确定如果活动存在,当前设备上?存在、设备

2023-09-12 04:15:33 作者:2018好听的女生最新版

有没有一种方法来检查,看看是否一个活动存在于您的设备上?如果我有一个YouTube视频链接我要打开指定它在YouTube上PlayerActivity。但是,我不想崩溃,如果由于某种原因,他们没有了。

有没有一种方法来检查,看看是否存在活动?我不认为我能赶上运行时异常,因为startActivity()不投。

解决方案   

我不认为我能赶上运行   除了

其实,这个作品:

 尝试{
    startActivity(新意图(..));
}赶上(ActivityNotFoundException E){
    Toast.makeText(这一点,不安装。,LENGTH_SHORT).show();
}
 

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't want to crash if for some reason they don't have it.

中国涂装设备行业存在不足,企业发展需持续优化产品

Is there a way to check and see if the activity exists? I don't think I can catch the runtime exception since startActivity() doesn't throw it.

解决方案

I don't think I can catch the runtime exception

Actually, this works:

try {
    startActivity(new Intent(..));
} catch (ActivityNotFoundException e) {
    Toast.makeText(this, "Not installed.", LENGTH_SHORT).show();
}