0

我正在关注本教程,我正在模拟器上对其进行测试,当我运行这个项目并单击它崩溃的按钮并给我以下错误时

07-27 06:33:30.324: E/AndroidRuntime(10972): FATAL EXCEPTION: main
07-27 06:33:30.324: E/AndroidRuntime(10972): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.GET_CONTENT typ=file/ * }
07-27 06:33:30.324: E/AndroidRuntime(10972):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at android.app.Activity.startActivityForResult(Activity.java:2817)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at com.exercise.AndroidPick_a_File.AndroidPick_a_File$1.onClick(AndroidPick_a_File.java:35)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at android.view.View.performClick(View.java:2408)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at android.view.View$PerformClick.run(View.java:8816)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at android.os.Handler.handleCallback(Handler.java:587)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at android.os.Handler.dispatchMessage(Handler.java:92)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at android.os.Looper.loop(Looper.java:123)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at android.app.ActivityThread.main(ActivityThread.java:4627)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at java.lang.reflect.Method.invokeNative(Native Method)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at java.lang.reflect.Method.invoke(Method.java:521)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at dalvik.system.NativeStart.main(Native Method)

我想处理这个错误,请帮助我处理这个错误。

4

2 回答 2

5

你有这个错误,因为你没有在模拟器上文件资源管理器应用程序。

如果要测试是否安装了文件资源管理器:

final PackageManager packageManager = getActivity().getPackageManager();
final Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
intent.setType("file/*");
List<ResolveInfo> list = packageManager.queryIntentActivities(intent,
                                PackageManager.GET_ACTIVITIES);

if (list.size() > 0) {
    //app installed
} else {
    //no app
}
于 2012-07-27T00:53:30.610 回答
0

如在类似问题中所见(https://stackoverflow.com/a/34181925/4098711)。假设您在一个活动中(否则用返回当前活动的方法替换它):

final PackageManager packageManager = this.getPackageManager();
final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
ComponentName testedActivity = intent.resolveActivity(getPackageManager());
if (testedActivity != null) {
    startActivityForResult(intent,IMPORT_FILE_REQ_CODE);
} else {
    Toast.makeText(this,"No file explorer available",Toast.LENGTH_LONG).show();
}
于 2017-01-14T00:16:34.657 回答