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

时间:2013-03-02 16:41:24

标签: android image android-intent gallery directory

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

selectSpecificFolder:

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);
            }
        }   
    }

logcat的:

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

1 个答案:

答案 0 :(得分:0)

我猜问题出在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