Send sms by opening default sms App it support both system and third party sms app programmatically in android.

try this:- 

public static void sendSMS(Context context, String mobileNo, 
       String msg) {
    Log.i("Send SMS", "");
    String defaultSmsPackage = Build.VERSION.SDK_INT >= 
      Build.VERSION_CODES.KITKAT
            ? Telephony.Sms.getDefaultSmsPackage(context)
            : 
      Settings.Secure.getString(context.getContentResolver(), 
              "sms_default_application");

    Log.i("Send SMS", defaultSmsPackage);
    Uri uri = Uri.parse(String.format("smsto:%s", mobileNo));

    Intent smsIntent = new Intent(Intent.ACTION_SENDTO, uri);
    smsIntent.putExtra("sms_body", msg);
    smsIntent.setPackage(defaultSmsPackage);

    try {
        context.startActivity(smsIntent);
        Log.i("Finished sending SMS...", "");
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(context,
                "SMS failed, There is no any default SMS App 
        Found.", Toast.LENGTH_SHORT).show();
    }
}

Comments

Popular posts from this blog

Android Studio 3.5 or above usb device not detected in Android Studio or Unable to detect adb version, exit value: 0xc0000135. ADB depends on the Windows Universal C Runtime, which is usually installed by default via Windows Update. You may need to manually fetch and install the runtime package here: https://support.microsoft.com/en-ca/help/2999226/update-for-universal-c-runtime-in-windows

Lint found fatal errors while assembling a release target.

ViewModelProviders.of(this) is deprecated what to use instead ViewModelProviders.of(this) OR if you don't want to use ViewmodelFactory OR ViewModelProviders error.