thieumao

SMS demo - GUI

Nov 7th, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.51 KB | None | 0 0
  1. package thieu.mao;
  2.  
  3. import thieu.mao.R.string;
  4. import android.net.Uri;
  5. import android.os.Bundle;
  6. import android.app.Activity;
  7. import android.content.Intent;
  8. import android.telephony.SmsManager;
  9. import android.view.Menu;
  10. import android.view.View;
  11. import android.widget.Button;
  12. import android.widget.EditText;
  13.  
  14. public class MainActivity extends Activity {
  15.  
  16.     private EditText etNumber;
  17.     private EditText etContent;
  18.     private Button btSend;
  19.  
  20.     @Override
  21.     protected void onCreate(Bundle savedInstanceState) {
  22.         super.onCreate(savedInstanceState);
  23.         setContentView(R.layout.giaodien);
  24.  
  25.         etNumber = (EditText) findViewById(R.id.etNumber);
  26.         etContent = (EditText) findViewById(R.id.etContent);
  27.         btSend = (Button) findViewById(R.id.btSend);
  28.  
  29.         btSend.setOnClickListener(new View.OnClickListener() {
  30.  
  31.             @Override
  32.             public void onClick(View v) {
  33.                 // TODO Auto-generated method stub
  34.                 String strNumber = etNumber.getText().toString();
  35.                 if ((strNumber.length() != 10) && (strNumber.length() != 11)) {
  36.                     strNumber = "0917735107";
  37.                 }
  38.                 Uri uri = Uri.parse("smsto:" + strNumber);
  39.                 Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
  40.                 String strContent = etContent.getText().toString();
  41.                 intent.putExtra("sms_body", strContent);
  42.                 startActivity(intent);
  43.             }
  44.         });
  45.     }
  46.  
  47.     @Override
  48.     public boolean onCreateOptionsMenu(Menu menu) {
  49.         // Inflate the menu; this adds items to the action bar if it is present.
  50.         getMenuInflater().inflate(R.menu.main, menu);
  51.         return true;
  52.     }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment