After the Android KitKat version, we can find out the default sms package name by "Telephony.sms.getDefaultSmsPackage(context);". But how does one get the package name before KitKat version?
Please refer this http://android-developers.blogspot.in/2013/10/getting-your-sms-apps-ready-for-kitkat.html
As per the doc "Android 4.4 (KitKat) makes the existing APIs public and adds the concept of a default SMS app, which the user can select in system settings."
In your code you should handle this as separate cases
Intent smsIntent;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(context); //Need to change the build to API 19
smsIntent = new Intent(Intent.ACTION_SEND);
smsIntent.setType("text/plain");
smsIntent.putExtra(Intent.EXTRA_TEXT,"content");
//if no default app is configured, then choose any app that support this intent.
if (defaultSmsPackageName != null) {
smsIntent.setPackage(defaultSmsPackageName);
}
} else {
smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("address", phoneNumber);
smsIntent.putExtra("sms_body","body");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With