打开图像形式内置图库

发布于 2024-11-30 16:51:36 字数 845 浏览 1 评论 0原文

我已阅读此链接:以编程方式在 Android 的内置图库应用程序中打开图像 以编程方式从 Android 的内置图库应用程序获取/选取图像,代码看起来不错。

结果如下: https://i.sstatic.net/vz3S8.png,但这不是我想要的结果。

我想打开类似于以下内容的图库: https://i.sstatic.net/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);

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

I have read this link :Open an image in Android's built-in Gallery app programmatically Get/pick an image from Android's built-in Gallery app programmatically, and the code looks well.

It results with following image: https://i.sstatic.net/vz3S8.png, but this is not the result I want.

I want to open the gallery similar to: https://i.sstatic.net/ZoUvU.png.
I want to choose the pic form the folder gallery.

Do you know how to modify the code?

I used:

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

Through I get the folder gallery, but I cannot get the pic path.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇俏 2024-12-07 16:51:36
 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");
         }


     }
        }

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


     }
        }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文