4

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?

Md. Sabbir Ahmed
  • 850
  • 8
  • 22

3 Answers3

6

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");
        }
Deniz
  • 12,332
  • 10
  • 44
  • 62
6

for below kiktat

public static final String getDefaultSmsPackage(Context context){
    String defApp = Settings.Secure.getString(context.getContentResolver(), "sms_default_application");
    PackageManager pm = context.getApplicationContext().getPackageManager();
    Intent iIntent = pm.getLaunchIntentForPackage(defApp);
    ResolveInfo mInfo = pm.resolveActivity(iIntent,0);
    return mInfo.activityInfo.packageName;
}

above or equal to kitkat

Telephony.Sms.getDefaultSmsPackage(this)
Siddarth Kanted
  • 5,738
  • 1
  • 29
  • 20
1

There is no "default SMS app" concept in Android prior to Android 4.4. Hence, there is no way to get this information.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491