我正在尝试使用Intent启动一个Activity。以下是使用intent的代码:
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("rtmp:example"))
startActivity(i);
我希望在此意图无法找到第三方应用程序时显示对话框。
我该怎么做?
下面是我的try和catch块代码:
try {
startActivity(i2);
} catch () {
AlertDialog.Builder b = new AlertDialog.Builder(getApplicationContext());
b.setMessage("You need MX player or VLC player to play the video.");
b.create().show();
}
答案 0 :(得分:2)
Android startActivity()
会抛出ActivityNotFoundException
。你应该抓住它并显示对话框:
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("rtmp:example"))
try{
startActivity(i);
} catch(android.content.ActivityNotFoundException e) {
//show you message here
}