Guest User

Untitled

a guest
Jan 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. // button onclick
  2. {
  3. Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
  4. intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
  5. startActivityForResult(intent, 1);
  6. }
  7.  
  8. // getting number from phonebook
  9.  
  10.  
  11. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  12.  
  13. // super.onActivityResult(requestCode, resultCode, data);
  14.  
  15. //Twitter Auth Callback
  16. // mTwitter.authorizeCallback(requestCode, resultCode, data);
  17. if (data != null) {
  18. Uri uri = data.getData();
  19.  
  20. if (uri != null) {
  21. Cursor c = null;
  22. try {
  23. c = getContentResolver()
  24. .query(uri,
  25. new String[] {
  26. ContactsContract.CommonDataKinds.Phone.NUMBER,
  27. /*ContactsContract.CommonDataKinds.Phone.TYPE*/ },
  28. null, null, null);
  29.  
  30. if (c != null && c.moveToFirst()) {
  31. String number = c.getString(0);
  32. //int type = c.getInt(1);
  33. showSelectedNumber(number);
  34. }
  35. } finally {
  36. if (c != null) {
  37. c.close();
  38. }
  39. }
  40. }
  41. }
  42.  
  43. }
  44.  
  45. public void showSelectedNumber(String number) {
  46.  
  47. final AlertDialog.Builder alert = new AlertDialog.Builder(this);
  48. LinearLayout lila1 = new LinearLayout(this);
  49. lila1.setOrientation(1); // 1 is for vertical orientation
  50. final EditText input = new EditText(this);
  51. final EditText input1 = new EditText(this);
  52. lila1.addView(input);
  53. input.setText(number);
  54. lila1.addView(input1);
  55. alert.setView(lila1);
  56. input1.setText(R.string.invite_SMS);
  57. input1.setTextSize(15);
  58. input1.setEllipsize(null);
  59. input1.setTextColor(Color.BLACK);
  60.  
  61.  
  62. alert.setTitle("MESSAGE");
  63.  
  64. alert.setPositiveButton("SEND", new DialogInterface.OnClickListener() {
  65.  
  66. public void onClick(DialogInterface dialog, int which) {
  67.  
  68. String phoneNo = input.getText().toString();
  69. String message = input1.getText().toString();
  70. if (phoneNo.length() > 0 && message.length() > 0)
  71. sendSMS(phoneNo, message);
  72.  
  73. else
  74. Toast.makeText(getBaseContext(),
  75. "Please enter both phone number and message.",
  76. Toast.LENGTH_SHORT).show();
  77.  
  78. }
  79. });
  80.  
  81. alert.setNegativeButton("Cancel",
  82. new DialogInterface.OnClickListener() {
  83. public void onClick(DialogInterface dialog, int whichButton) {
  84. dialog.cancel();
  85. }
  86. });
  87. alert.show();
  88.  
  89. }
  90.  
  91. private void sendSMS(String phoneNumber, String message) {
  92. PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this,
  93. InviteFriends.class), 0);
  94. SmsManager sms = SmsManager.getDefault();
  95. sms.sendTextMessage(phoneNumber, null, message, pi, null);
  96. Toast.makeText(getApplicationContext(), "MESSAGE SENT",
  97. Toast.LENGTH_SHORT).show();
  98.  
  99. }
Add Comment
Please, Sign In to add comment