简体   繁体   English

android.content.ActivityNotFoundException:未找到任何处理Intent的活动{act = android.intent.action.GET_CONTENT

[英]android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.GET_CONTENT

I'm trying to open the screenshots photos folder. 我正在尝试打开screenshots照片文件夹。

        private void Try3()
        {
            File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pictures/Screenshots");
            Log.d("File path ", dir.getPath());
            String dirPath=dir.getAbsolutePath();
            if(dir.exists() && dir.isDirectory()) {
                Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
                intent.setType("image/*");
                intent.setData(Uri.fromFile(dir));

                Log.d("b4performSpecificCrop_startActivityForResult::", Integer.toString(3));
                startActivityForResult(intent, 3);
                Log.d("afterperformSpecificCrop_startActivityForResult::", Integer.toString(3));
            }             

I have this permission in the Manifest: 我在清单中有此许可:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

and get this from logCat: 并从logCat获取此信息:

10-05 22:17:26.790: E/AndroidRuntime(28347): FATAL EXCEPTION: main
10-05 22:17:26.790: E/AndroidRuntime(28347): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.GET_CONTENT dat=file:///storage/sdcard0/Pictures/Screenshots }
10-05 22:17:26.790: E/AndroidRuntime(28347):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1580)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1431)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at android.app.Activity.startActivityForResult(Activity.java:3446)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at android.app.Activity.startActivityForResult(Activity.java:3407)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at de.vogella.android.todos.TodoDetailActivity$1.Try3(TodoDetailActivity.java:149)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at de.vogella.android.todos.TodoDetailActivity$1.onClick(TodoDetailActivity.java:132)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at android.view.View.performClick(View.java:4223)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at android.view.View$PerformClick.run(View.java:17275)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at android.os.Handler.handleCallback(Handler.java:615)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at android.os.Handler.dispatchMessage(Handler.java:92)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at android.os.Looper.loop(Looper.java:137)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at android.app.ActivityThread.main(ActivityThread.java:4898)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at java.lang.reflect.Method.invokeNative(Native Method)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at java.lang.reflect.Method.invoke(Method.java:511)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at dalvik.system.NativeStart.main(Native Method)
10-05 22:17:26.815: E/android.os.Debug(2282): !@Dumpstate > dumpstate -k -t -z -d -o /data/log/dumpstate_app_error
10-05 22:17:29.950: E/Watchdog(2282): !@Sync 36
10-05 22:17:31.460: E/WifiP2pStateTracker(2282): getNetworkInfo : NetworkInfo: type: WIFI_P2P[], state: UNKNOWN/IDLE, reason: (unspecified), extra: (none), roaming: false, failover: false, isAvailable: true
10-05 22:17:32.890: E/Sensors(2282): Gyro old sensor_state 75, new sensor_state : 73 en : 0
10-05 22:17:32.895: E/Sensors(2282): Pressure old sensor_state 73, new sensor_state : 65 en : 0
10-05 22:17:38.545: E/MtpService(2826): In MTPAPP onReceive:android.intent.action.BATTERY_CHANGED
10-05 22:17:38.550: E/MtpService(2826): battPlugged Type : 2

Update: 更新:

ACTION_VIEW doesn't work ACTION_VIEW不起作用

ACTION_GET_CONTENT doesn't work ACTION_GET_CONTENT不起作用

ACTION_PICK works, but I prefer the default photos Gallery view ACTION_PICK有效,但我希望使用默认照片库视图

I have read about these in the documentation, but didn't fully understand the difference between them. 我已经在文档中阅读了这些内容,但是并没有完全理解它们之间的区别。 Can someone clear this out? 有人可以清除吗?

First, setData() wipes out your setType() IIRC. 首先, setData()清除了您的setType() IIRC。 When you actually need both (hint: not here), set them both together with setDataAndType() . 当您实际上需要两者时(提示:不在此处),请将两者与setDataAndType()一起设置。

Second, ACTION_GET_CONTENT is for choosing by type, not location. 其次, ACTION_GET_CONTENT用于按类型而非位置进行选择。 Quoting the documentation for ACTION_GET_CONTENT : 引用ACTION_GET_CONTENT的文档

Note that no URI is supplied in the intent, as there are no constraints on where the returned data originally comes from 请注意,意图中未提供URI,因为对于返回的数据最初来自何处没有限制

Hence, you will need to remove your setData() call and just use setType() . 因此,您将需要删除setData()调用,而只需使用setType() However, that will not pick from that folder. 但是,不会从该文件夹中进行选择。

ACTION_PICK is where you specify a collection to pick from, rather than a type. ACTION_PICK中,您指定要选择的集合而不是类型。 However, there is no guarantee that there will be an app on the device that supports ACTION_PICK for a file:// Uri . 但是,不能保证设备上将有一个支持ACTION_PICK for file:// Uri的应用程序。

I would recommend that you implement the UI in your application directly. 我建议您直接在应用程序中实现UI。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android.content.ActivityNotFoundException:没有找到处理意图的活动{act=android.intent.action.VIEW dat=PendingIntent{} - android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=PendingIntent{ } Android错误:“ android.content.ActivityNotFoundException:未找到用于处理Intent的活动” - Android error : “android.content.ActivityNotFoundException: No Activity found to handle Intent” android.content.ActivityNotFoundException: 没有找到处理意图的活动 { act=activity2.application1 (有额外的) } - android.content.ActivityNotFoundException: No Activity found to handle Intent { act=activity2.application1 (has extras) } android.content.ActivityNotFoundException:未找到用于处理Intent的活动 - android.content.ActivityNotFoundException: No Activity found to handle Intent 致命异常:android.content.ActivityNotFoundException:未找到处理 Intent 的活动 - Fatal Exception: android.content.ActivityNotFoundException: No Activity found to handle Intent android.content.ActivityNotFoundException:未找到任何处理Intent的活动{act = login_filter(有其他功能)} - android.content.ActivityNotFoundException: No Activity found to handle Intent { act=login_filter (has extras) } android.content.ActivityNotFoundException:将url传递给intent - android.content.ActivityNotFoundException: passing url to the intent 找不到用于处理意图的活动{act = android.intent.action.View} - No activity found to handle intent { act=android.intent.action.View } 没有找到处理意图的活动{act=android,intent.action.VIEW} - No activity found to handle intent{act=android,intent.action.VIEW} android.content.ActivityNotFoundException,无法开始活动 - android.content.ActivityNotFoundException ,unable to start activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM