How to tell if a device is using TouchWiz programmatically
-
21-12-2019 - |
Question
I need to check from within my code whether the device I am using has TouchWiz enabled. I tried using
if(android.os.Build.MANUFACTURER.equals(MANUFACTURER_SAMSUNG))
But it turns out some devices are made by Samsung and don't use TouchWiz.
How can I figure this out?
Solution
check the default launcher.. i believe touchwiz is a launcher
final Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
final ResolveInfo res = getPackageManager().resolveActivity(intent, 0);
if (res.activityInfo == null) {
// should not happen. A home is always installed, isn't it?
} if ("android".equals(res.activityInfo.packageName)) {
// No default selected
} else {
// res.activityInfo.packageName and res.activityInfo.name gives you the default app
}
OTHER TIPS
You can get list of preferred activities from PackageManager. Use getPreferredActivities() method.
boolean isUsingTochwiz() {
final IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN);
filter.addCategory(Intent.CATEGORY_HOME);
List<IntentFilter> filters = new ArrayList<IntentFilter>();
filters.add(filter);
final String myPackageName = "INSERT TOUCHWIZ PACKAGE NAME HERE";
List<ComponentName> activities = new ArrayList<ComponentName>();
final PackageManager packageManager = (PackageManager) getPackageManager();
packageManager.getPreferredActivities(filters, activities, null);
for (ComponentName activity : activities) {
if (myPackageName.equals(activity.getPackageName())) {
return true;
}
}
return false;
}
Taken from: How to check if my application is the default launcher
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow