ActivityNotFoundException: No Activity found to handle Intent
程序员文章站
2024-02-10 16:09:16
...
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.tencent.squeezencnn, PID: 607
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.PICK typ=image/* }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1798)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1512)
at android.app.Activity.startActivityForResult(Activity.java:3930)
at android.app.Activity.startActivityForResult(Activity.java:3890)
at com.tencent.squeezencnn.MainActivity$1.onClick(MainActivity.java:75)
at android.view.View.performClick(View.java:5204)
at android.view.View$PerformClick.run(View.java:21155)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5422)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
做从手机上取出图片时用Intent.ACTION_PICK,在使用过程中发现,有的手机正常,有的手机报错 ,
后来发现,原因在于对于Intent.ACTION_PICK认识不足。ACTION_PICK 是允许用户从已安装的应用程序注册为这种行动的任何图像中选择,报错的手机没有安装暴露有ACTION_PICK意图的软件,所以无法打开,出错!
知道了错误原因,问题就好解决了!
把如下的 Intent.ACTION_PICK改成Intent.ACTION_GET_CONTENT就ok了
@Override
public void onClick(View v) {
Intent getAlbum = new Intent(Intent.ACTION_GET_CONTENT);
getAlbum.setType("image/*");
startActivityForResult(getAlbum, 0);
}