thecr0w thecr0w - 24 days ago 8
Android Question

how could I get default sms app's package name?

As default sms app is added in 4.4, I cannot open default sms app like this:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setType("vnd.android-dir/mms-sms");
startActivity(intent);


So how could I get default sms app's package name, so I can open it from my app directly?

Answer

//http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.4.4_r1/android/provider/Settings.java#Settings.Secure.0SMS_DEFAULT_APPLICATION

public static final String SMS_DEFAULT_APPLICATION = "sms_default_application";

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.4.4_r1/com/android/internal/telephony/SmsApplication.java#267

if(Utils.hasKikKat()) {
    String defaultApplication = Settings.Secure.getString(getContentResolver(),  SMS_DEFAULT_APPLICATION);
    PackageManager pm = context.getPackageManager();
    Intent intent = pm.getLaunchIntentForPackage(defaultApplication );
      if (intent != null) {
        context.startActivity(intent);
      }
} else {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setType("vnd.android-dir/mms-sms");
    startActivity(intent);
}
Comments