How to programatically detect if an app supports Android Wear?

前端 未结 1 699
长情又很酷
长情又很酷 2021-01-06 06:10

Im trying to detect if an app supports Android Wear or is a watch face.

PackageManager pm = getActivity().getPackageManager();

        List

        
1条回答
  •  孤街浪徒
    2021-01-06 06:22

    To check if Android Wear package exists on system:

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

    0 讨论(0)
提交回复
热议问题