这个很简单的Android小程序,下面是MainActivity的代码,那个布局就不发了- package com.example.sendmsm;
- import java.util.ArrayList;
- import android.support.v4.widget.SimpleCursorAdapter.ViewBinder;
- import android.support.v7.app.ActionBarActivity;
- import android.telephony.gsm.SmsManager;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.Toast;
- public class MainActivity extends ActionBarActivity {
- private EditText numberText;
- private EditText contentText;
- private Button button;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- numberText=(EditText)findViewById(R.id.numebr);
- contentText=(EditText)findViewById(R.id.content);
- button=(Button)findViewById(R.id.button);
- button.setOnClickListener(new ButtonClickListener());
-
- }
- private final class ButtonClickListener implements View.OnClickListener{
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- String number=numberText.getText().toString();
- String content=contentText.getText().toString();
- SmsManager manager=SmsManager.getDefault();
- ArrayList<String> texts=manager.divideMessage(content);
- for(String text:texts){
- manager.sendTextMessage(number, null, text, null, null);
- }
- Toast.makeText(MainActivity.this, R.string.success, Toast.LENGTH_LONG).show();
-
- }
-
- }
-
- }
复制代码 |