gpt4 book ai didi

android使用内置图库打开特定文件夹

转载 作者:太空狗 更新时间:2023-10-29 15:13:00 26 4
gpt4 key购买 nike

我正在尝试使用图库打开特定文件夹并引用了其他类似问题 open image form built_in gallery , 并执行了以下代码,仍然失败并报错(如下logcat所示):

选择特定文件夹:

private void selectSpecificFolder()
{
File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/MyFolder");
Log.d("File path ", dir.getPath());
String dirPath=dir.getAbsolutePath();
if(dir.exists() && dir.isDirectory()) {
Intent intent = new Intent(Intent.ACTION_VIEW, 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));
}
else
{
Toast.makeText(this, "No file exist to show", Toast.LENGTH_LONG).show();
}
}

onActivityResult:

protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 3)
{
Log.d("INSIDE_ONACTIVITY_REQUEST3", Integer.toString(3));
if (data==null)
{
Toast.makeText(this,"No image selected",Toast.LENGTH_LONG).show();
}
else
{
Uri selectedImageUri = data.getData();
String selectedImagePath = selectedImageUri.getPath();

if(selectedImagePath!=null)
{
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(selectedImageUri);
startActivity(intent);
}
}
}

日志:

03-02 23:56:09.910: D/b4performSpecificCrop_startActivityForResult::(18133): 3
03-02 23:56:09.940: D/Instrumentation(18133): checkStartActivityResult :Intent { act=android.intent.action.VIEW dat=file:xxxxx }
03-02 23:56:09.940: D/Instrumentation(18133): checkStartActivityResult inent is instance of inent:
03-02 23:56:09.950: D/AndroidRuntime(18133): Shutting down VM
03-02 23:56:09.950: W/dalvikvm(18133): threadid=1: thread exiting with uncaught exception (group=0x40c6e1f8)
03-02 23:56:09.965: E/AndroidRuntime(18133): FATAL EXCEPTION: main
03-02 23:56:09.965: E/AndroidRuntime(18133): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:xxxxx }
03-02 23:56:09.965: E/AndroidRuntime(18133): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1535)
03-02 23:56:09.965: E/AndroidRuntime(18133): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1387)
03-02 23:56:09.965: E/AndroidRuntime(18133): at android.app.Activity.startActivityForResult(Activity.java:3195)
03-02 23:56:09.965: E/AndroidRuntime(18133): at com.abc.drawing.Doodlz.performSpecificCrop(Doodlz.java:1712)
03-02 23:56:09.965: E/AndroidRuntime(18133): at com.abc.drawing.Doodlz.access$20(Doodlz.java:1701)
03-02 23:56:09.965: E/AndroidRuntime(18133): at com.abc.drawing.Doodlz$43.onClick(Doodlz.java:1184)
03-02 23:56:09.965: E/AndroidRuntime(18133): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:167)
03-02 23:56:09.965: E/AndroidRuntime(18133): at android.os.Handler.dispatchMessage(Handler.java:99)
03-02 23:56:09.965: E/AndroidRuntime(18133): at android.os.Looper.loop(Looper.java:137)
03-02 23:56:09.965: E/AndroidRuntime(18133): at android.app.ActivityThread.main(ActivityThread.java:4511)
03-02 23:56:09.965: E/AndroidRuntime(18133): at java.lang.reflect.Method.invokeNative(Native Method)
03-02 23:56:09.965: E/AndroidRuntime(18133): at java.lang.reflect.Method.invoke(Method.java:511)
03-02 23:56:09.965: E/AndroidRuntime(18133): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
03-02 23:56:09.965: E/AndroidRuntime(18133): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
03-02 23:56:09.965: E/AndroidRuntime(18133): at dalvik.system.NativeStart.main(Native Method)

问题:

在 Logcat 中它报告 android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:xxxxx } 这是什么意思,这怎么可能得到解决?谢谢!!

PS:对于该应用程序,它没有单独的布局来显示该特定文件夹中的所有图像。取而代之的是一个“打开文件夹”按钮,这样当用户按下按钮时。它会简单地使用内置图库直接显示特定文件夹中的图像。

最佳答案

我猜问题出在 AndroidManifest.xml 中

这是解决此问题的主要资源,请查看 Mark Murphy 的回复: https://groups.google.com/forum/?fromgroups#!topic/android-beginners/nYFBeAgmkMU

这是次要的,但基本相同的问题 Android: No Activity found to handle Intent error? How it will resolve

关于android使用内置图库打开特定文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15176863/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com