【问题标题】:How to tell if a device is using TouchWiz programmatically如何判断设备是否以编程方式使用 TouchWiz
【发布时间】:2014-07-29 16:48:47
【问题描述】:

我需要在我的代码中检查我正在使用的设备是否启用了 TouchWiz。我尝试使用

if(android.os.Build.MANUFACTURER.equals(MANUFACTURER_SAMSUNG))

但事实证明,有些设备是三星制造的,不使用 TouchWiz。

我该如何解决这个问题?

【问题讨论】:

  • 可能只是带有自定义 rom 的那个,

标签: android android-widget samsung-touchwiz


【解决方案1】:

检查默认启动器.. 我相信 touchwiz 是一个启动器

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
} 

【讨论】:

  • 是的,这很好用。 touchwiz 的包名是“com.sec.android.app.launcher”吧?
【解决方案2】:

您可以从 PackageManager 获取首选活动列表。使用 getPreferredActivities() 方法。

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;
}

取自:How to check if my application is the default launcher

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-04
    • 1970-01-01
    • 1970-01-01
    • 2015-10-18
    • 1970-01-01
    • 1970-01-01
    • 2011-10-31
    • 2017-02-03
    相关资源
    最近更新 更多