【问题标题】:open image form built_in gallery打开图像形式 built_in 画廊
【发布时间】:2011-08-20 12:16:49
【问题描述】:

我已阅读此链接:以编程方式在 Android 的内置图库应用程序中打开图像Get/pick an image from Android's built-in Gallery app programmatically,代码看起来不错。

结果如下图:http://i.stack.imgur.com/vz3S8.png,但这不是我想要的结果。

我想打开类似于:http://i.stack.imgur.com/ZoUvU.png 的库。 我想从文件夹库中选择图片。

你知道如何修改代码吗?

我用过:

Intent intent = new Intent();
intent.setComponent(new ComponentName("com.android.gallery", "com.android.camera.GalleryPicker"));

//   intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);

Log.i("aa","adafdsfa");
startActivityForResult(intent, 1);

通过我获取文件夹库,但我无法获取图片路径。

【问题讨论】:

    标签: android gallery


    【解决方案1】:
     File dir = new File(Environment.getExternalStorageDirectory().toString() + "/sdcard/yourfolder");
            Log.d("File path ", dir.getPath());
            String dirPath=dir.getAbsolutePath();
            if(dir.exists() && dir.isDirectory()) {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                // tells your intent to get the contents
                // opens the URI for your image directory on your sdcard
                                //its upto you what data you want image or video.
                intent.setType("image/*");
            //  intent.setType("video/*");
                intent.setData(Uri.fromFile(dir));
            //  intent.setType("media/*");
            //  intent.
                startActivityForResult(intent, 1);
            }
            else
            {
                showToast("No file exist to show");
            }   
    
    
          protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
    
         if (requestCode == 1) {
             if (data==null) {
                showToast("No image selected");
                //finish();
            }
             else
             {
             Uri selectedImageUri = data.getData();
    
          //  String filemanagerstring = selectedImageUri.getPath();
    
             //MEDIA GALLERY
           String  selectedImagePath = getPath(selectedImageUri);
    
             if(selectedImagePath!=null)
             {
                 Intent intent = new Intent();
                 intent.setAction(Intent.ACTION_VIEW);
                 intent.setData(selectedImageUri);
                 startActivity(intent);
             }
    
             else
             {
                 showToast("Image path not correct");
             }
    
    
         }
            }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-16
      相关资源
      最近更新 更多