Determining if an Activity exists on the current device?

前端 未结 5 1737
攒了一身酷
攒了一身酷 2020-11-29 06:28

Is there a way to check and see if an Activity exists on your device? If I have a youtube video link I want to specify it open in the YouTube PlayerActivity. However, I don\

5条回答
  •  醉梦人生
    2020-11-29 07:15

    You could create an Intent object with necessary component info and then check if the intent is callable or not.I stumbled upon this snippet here on SO, don't have the link to the actual thread.

    private boolean isCallable(Intent intent) {
            List list = getPackageManager().queryIntentActivities(intent, 
                PackageManager.MATCH_DEFAULT_ONLY);
            return list.size() > 0;
    }
    

提交回复
热议问题