Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the package name of sms app(default) in Android before KitKat version?

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?

like image 773
Malleswar Chinta Avatar asked Dec 12 '22 00:12

Malleswar Chinta


1 Answers

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");
        }
like image 50
Dennis MP Avatar answered Dec 28 '22 10:12

Dennis MP