1

I am trying to share text through SMS. It looks fine on most of the phones, even Samsung phones, except on Galaxy S5.

Here is the code:

public static void shareWithSMS(@NonNull Context context, @Nullable String text) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", "", null));
    intent.setType("vnd.android-dir/mms-sms");
    intent.putExtra("sms_body", text);
    context.startActivity(intent);
}

It launch the app for SMS, without any text. Does anyone know why?

UPDATE

The aim is to launch the sms app of the device, not to send the SMS. That's why I am not using SmsManager.

Daniele Vitali
  • 3,848
  • 8
  • 48
  • 71

2 Answers2

0

You have Two method to do so.one of them is using smsManager()and other one is Using Intent So use this Code For Send Message:

    Intent smsIntent = new Intent(Intent.ACTION_VIEW);
            smsIntent.setType("vnd.android-dir/mms-sms");
            smsIntent.putExtra("sms_body", getString(R.string.social_invitation));
            startActivity(smsIntent);

Enjoy Your Code:)

John smith
  • 1,781
  • 17
  • 27
  • Hey Piyush Gupta. So, I removed the URI but still same problem :( And about the first solution, I don't want to send the sms from my app, but open the default sms app of the user. – Daniele Vitali Jul 17 '15 at 14:19
0

I faced with same trouble. I found solution here launch sms application with an intent

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);
      }
   }
Community
  • 1
  • 1