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?
Asked
Active
Viewed 9,647 times
4
-
Please check http://stackoverflow.com/a/25969308 – Narendra Apr 06 '15 at 12:37
-
@Narendra what I want is package name – Malleswar Chinta Apr 06 '15 at 12:38
-
@MalleswarChinta what exactly you are trying to achieve by getting package name? – Fahim Apr 06 '15 at 12:53
-
@Fahim I am doing a custom chooser for my android app, [http://stackoverflow.com/questions/5734678/custom-filtering-of-intent-chooser-based-on-installed-android-package-name] – Malleswar Chinta Apr 06 '15 at 12:57
3 Answers
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