3

我正在尝试使用 gallery 打开特定文件夹并参考了其他类似问题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();
    }  
}

活动结果:

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:对于应用程序,它没有单独的布局来显示该特定文件夹中的所有图像。相反,有一个“打开文件夹”按钮,当用户按下该按钮时。它只会使用内置图库直接显示特定文件夹中的图像。

4

1 回答 1

0

I guess the problem is inside the AndroidManifest.xml

This is a main resource for this problem, check the Mark Murphy response: https://groups.google.com/forum/?fromgroups#!topic/android-beginners/nYFBeAgmkMU

This is a secondary, but basic the same problem Android: No Activity found to handle Intent error? How it will resolve

于 2013-06-14T01:47:50.690 回答