Posted By

YakupKalin on 05/23/11


Tagged


Versions (?)

Fake SMS


 / Published in: Java
 

  1. package be.yakupkalin.fakesms;
  2.  
  3. import android.app.Activity;
  4. import android.content.ContentValues;
  5. import android.net.Uri;
  6. import android.os.Bundle;
  7. import android.view.View;
  8. import android.view.View.OnClickListener;
  9. import android.widget.ArrayAdapter;
  10. import android.widget.Button;
  11. import android.widget.Spinner;
  12. import android.widget.TextView;
  13.  
  14. public class Main extends Activity {
  15.  
  16. private Button btnSave, btnStatus;
  17. private Spinner spFrom;
  18. private TextView txtBody;
  19. private String from = "Ghost";
  20.  
  21. @Override
  22. public void onCreate(Bundle savedInstanceState) {
  23. super.onCreate(savedInstanceState);
  24. setContentView(R.layout.main);
  25.  
  26. btnSave = (Button)findViewById(R.id.btnSave);
  27. btnStatus = (Button)findViewById(R.id.btnStatus);
  28. spFrom = (Spinner)findViewById(R.id.spFrom);
  29. txtBody = (TextView)findViewById(R.id.etBody);
  30.  
  31. String[] arFrom = getResources().getStringArray(R.array.fromStrings);
  32. java.util.Arrays.sort(arFrom);
  33.  
  34. ArrayAdapter adapter = new ArrayAdapter(this,
  35. android.R.layout.simple_spinner_item, arFrom);
  36.  
  37. spFrom.setAdapter(adapter);
  38. btnStatus.setOnClickListener(new OnClickListener() {
  39.  
  40. @Override
  41. public void onClick(View v) {
  42. btnStatus.setVisibility(View.INVISIBLE);
  43. }
  44. });
  45. btnSave.setOnClickListener(new OnClickListener() {
  46. @Override
  47. public void onClick(View v) {
  48. saveSMS(spFrom.getSelectedItem().toString(), txtBody.getText().toString());
  49. }
  50. });
  51. }
  52.  
  53. private void saveSMS(String from, String body) {
  54. ContentValues values = new ContentValues();
  55. values.put("address", from);
  56. values.put("body", body);
  57. getContentResolver().insert(Uri.parse("content://sms/inbox"), values);
  58. btnStatus.setText("Message Sent! (close)");
  59. btnStatus.setVisibility(View.VISIBLE);
  60. }
  61. }

Report this snippet  

You need to login to post a comment.