如何处理好ActivityNotFoundException?如何处理、ActivityNotFoundException

2023-09-12 23:45:54 作者:第十九个梦

在我的应用程序,我需要使用startActivity看到文件的内容,或者使用默认的应用程序打开某些文件,但有时Android系统可能无法安装所需要的应用程序。

In my app , I need to use startActivity to see the content of the file , or use the default application to open the certain file , but sometimes the android system may not install the application which is needed .

我的问题是如何处理这个异常。我想敬酒,而不是FC ..

My question is how to handle this exception . I want a toast , not FC..

什么建议? THX

推荐答案

只需简单的添加在你的清单文件的活动。

喜欢,

<activity android:name=".ActivityName"
                  android:label="@string/app_name">
        </activity>

编辑:

现在赶上 ActivityNOtFoundException 把你的code中,

Now to catch the ActivityNOtFoundException put your code in,

try {

  // Your startActivity code wich throws exception  
} catch (ActivityNotFoundException activityNotFound) {

    // Now, You can catch the exception here and do what you want
}

请注意:要小心,当你抓住这个 ActivityNotFound 例外,但你不能修改清单文件运行时,意味着一旦你遇到的异常,如果你想补充一点,在运行时该活动标签那么你就不能。

Note: Be careful when you catch this ActivityNotFound Exception but you can't modified manifest file to run time, means once you encountered the exception and if you want to add that this activity tag at runtime then you can't.