如何以编程方式检测应用是否支持Android Wear?

时间:2014-09-23 03:40:28

标签: android wear-os

我试图检测某个应用是否支持Android Wear或是表情。

PackageManager pm = getActivity().getPackageManager();

        List<PackageInfo> packs = pm.getInstalledPackages(0);
        for (int i = 0; i < packs.size(); i++)
        {}

代码是否正在使用。任何反馈或建议都会很棒!

1 个答案:

答案 0 :(得分:0)

检查系统上是否存在Android Wear软件包:

public void foobar() {
    boolean doesExist = isPackageInstalled("com.google.android.wearable.app");
}

private boolean isPackageInstalled(String packagename) {
    PackageManager pm = getApplicationContext().getPackageManager();
    try {
        pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (NameNotFoundException e) {
        //swallow exception
        return false;
    }
}