Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // button onclick
- {
- Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
- intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
- startActivityForResult(intent, 1);
- }
- // getting number from phonebook
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- // super.onActivityResult(requestCode, resultCode, data);
- //Twitter Auth Callback
- // mTwitter.authorizeCallback(requestCode, resultCode, data);
- if (data != null) {
- Uri uri = data.getData();
- if (uri != null) {
- Cursor c = null;
- try {
- c = getContentResolver()
- .query(uri,
- new String[] {
- ContactsContract.CommonDataKinds.Phone.NUMBER,
- /*ContactsContract.CommonDataKinds.Phone.TYPE*/ },
- null, null, null);
- if (c != null && c.moveToFirst()) {
- String number = c.getString(0);
- //int type = c.getInt(1);
- showSelectedNumber(number);
- }
- } finally {
- if (c != null) {
- c.close();
- }
- }
- }
- }
- }
- public void showSelectedNumber(String number) {
- final AlertDialog.Builder alert = new AlertDialog.Builder(this);
- LinearLayout lila1 = new LinearLayout(this);
- lila1.setOrientation(1); // 1 is for vertical orientation
- final EditText input = new EditText(this);
- final EditText input1 = new EditText(this);
- lila1.addView(input);
- input.setText(number);
- lila1.addView(input1);
- alert.setView(lila1);
- input1.setText(R.string.invite_SMS);
- input1.setTextSize(15);
- input1.setEllipsize(null);
- input1.setTextColor(Color.BLACK);
- alert.setTitle("MESSAGE");
- alert.setPositiveButton("SEND", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- String phoneNo = input.getText().toString();
- String message = input1.getText().toString();
- if (phoneNo.length() > 0 && message.length() > 0)
- sendSMS(phoneNo, message);
- else
- Toast.makeText(getBaseContext(),
- "Please enter both phone number and message.",
- Toast.LENGTH_SHORT).show();
- }
- });
- alert.setNegativeButton("Cancel",
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- dialog.cancel();
- }
- });
- alert.show();
- }
- private void sendSMS(String phoneNumber, String message) {
- PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this,
- InviteFriends.class), 0);
- SmsManager sms = SmsManager.getDefault();
- sms.sendTextMessage(phoneNumber, null, message, pi, null);
- Toast.makeText(getApplicationContext(), "MESSAGE SENT",
- Toast.LENGTH_SHORT).show();
- }
Add Comment
Please, Sign In to add comment