How to find default sms messaging app


From api level 19 onwards, its just a one line call to get the packageName of default sms application.
Telephony.Sms.getDefaultSmsPackage(context)
Before API level 19, there is no concept of Default Sms, so what we can do is get the list of messaging apps.
private Object[] getMessagingAppPackageNames(Context context) {
   List messagingAppPackgeNameList = new ArrayList<>();
   final PackageManager pm = context.getPackageManager();
   //get metaData for installed apps
   List packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);

   for (ApplicationInfo appInfo : packages) {
      String packageName = appInfo.packageName;
      if (packageName != null && (packageName.contains("sms")
             || packageName.contains("mms") || packageName.contains("message")
             || packageName.contains("SMS") || packageName.contains("MMS")
             || packageName.contains("Message") || packageName.contains("media")
             || packageName.contains("Media"))) {
                messagingAppPackgeNameList.add(packageName);
      }
   }
   return messagingAppPackgeNameList.toArray();
}
This list may have all messaging apps plus some other apps also. But at least we can make sure the list will have all messaging app package names.

Comments

Popular posts from this blog

AlarmManager and Notification in Android

Swipe Action and ViewFlipper in Android