我试图检测一个应用是否支持Android Wear或者是一个手表表盘。
PackageManager pm = getActivity().getPackageManager();
List<PackageInfo> packs = pm.getInstalledPackages(0);
for (int i = 0; i < packs.size(); i++)
{}
我正在使用的代码。如果有任何反馈或建议,那就太棒了!
检查系统中是否存在 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;
}
}