Determining if an Activity exists on the current device?

前端 未结 5 1739
攒了一身酷
攒了一身酷 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 06:58

    Here's how I check if an Activity is available on the device:

            Intent intent = new Intent(Intent.ACTION_CALL);
            intent.setData(Uri.parse("tell//:" + phoneNumber));
    
            PackageManager manager = context.getPackageManager();
            List activities = manager.queryIntentActivities(
                    intent, 0);
            if (!manager.hasSystemFeature(
                    PackageManager.FEATURE_TELEPHONY) || activities == null || activities
                    .size() < 1) {
                Toast.makeText(
                        context,
                        "Sorry, there were no apps that worked with that request.",
                        Toast.LENGTH_SHORT).show();
            } else {
                context.startActivity(intent);
            }
    

提交回复
热议问题