Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

launch sms application with an intent

People also ask

What is the intent action to launch phone application with number?

Intent callIntent = new Intent(Intent. ACTION_DIAL, number); When your app invokes this intent by calling startActivity() , the Phone app initiates a call to the given phone number.

How do I send a message using intent?

Intent sendIntent = new Intent(Intent. ACTION_VIEW); sendIntent. putExtra("sms_body", "default content"); sendIntent.

How do I open SMS app?

From the Home screen, tap the Apps icon (in the QuickTap bar) > the Apps tab (if necessary) > Tools folder > Messaging .


To start launch the sms activity all you need is this:

Intent sendIntent = new Intent(Intent.ACTION_VIEW);         
sendIntent.setData(Uri.parse("sms:"));

You can add extras to populate your own message and such like this

sendIntent.putExtra("sms_body", x); 

then just startActivity with the intent.

startActivity(sendIntent);

Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("address", "12125551212");
smsIntent.putExtra("sms_body","Body of Message");
startActivity(smsIntent);

If android version is Kitkat or above, users can change default sms application. This method will get default sms app and start default sms app.

private void sendSMS() {    
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) // At least KitKat
      {
         String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(this); // Need to change the build to API 19

         Intent sendIntent = new Intent(Intent.ACTION_SEND);
         sendIntent.setType("text/plain");
         sendIntent.putExtra(Intent.EXTRA_TEXT, "text");

         if (defaultSmsPackageName != null)// Can be null in case that there is no default, then the user would be able to choose
         // any app that support this intent.
         {
            sendIntent.setPackage(defaultSmsPackageName);
         }
         startActivity(sendIntent);

      }
      else // For early versions, do what worked for you before.
      {
         Intent smsIntent = new Intent(android.content.Intent.ACTION_VIEW);
         smsIntent.setType("vnd.android-dir/mms-sms");
         smsIntent.putExtra("address","phoneNumber");         
         smsIntent.putExtra("sms_body","message");
         startActivity(smsIntent);
      }
   }

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setType("vnd.android-dir/mms-sms");
startActivity(intent);

That's all you need.


If you want to launch SMS Composing activity from some of your other activity and you also have to pass a phone number and SMS text, then use this code:

Uri sms_uri = Uri.parse("smsto:+92xxxxxxxx"); 
Intent sms_intent = new Intent(Intent.ACTION_SENDTO, sms_uri); 
sms_intent.putExtra("sms_body", "Good Morning ! how r U ?"); 
startActivity(sms_intent); 

Note: here the sms_body and smsto: is keys for recognizing the text and phone no at SMS compose activity, so be careful here.


Here is the code that will open the SMS activity pre-populated with the phone number to which the SMS has to be sent. This works fine on emulator as well as the device.

Intent smsIntent = new Intent(Intent.ACTION_SENDTO);
smsIntent.addCategory(Intent.CATEGORY_DEFAULT);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.setData(Uri.parse("sms:" + phoneNumber));
startActivity(smsIntent);