【问题标题】:android open specific folder using built-in galleryandroid使用内置图库打开特定文件夹
【发布时间】:2013-02-17 02:00:09
【问题描述】:

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

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

【问题讨论】:

    标签: android image android-intent gallery directory


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-21
      • 2017-03-12
      • 1970-01-01
      • 2018-01-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多