确定如果活动存在,当前设备上? [英] Determining if an Activity exists on the current device?

查看:119
本文介绍了确定如果活动存在,当前设备上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来检查,看看是否一个活动存在于您的设备上?如果我有一个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();
}

这篇关于确定如果活动存在,当前设备上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆