打开图像形式BUILT_IN图库 [英] open image form built_in gallery

查看:90
本文介绍了打开图像形式BUILT_IN图库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读此链接:在打开图像的Andr​​oid内置的图库应用程序编程<一href=\"http://stackoverflow.com/questions/2169649/open-an-image-in-androids-built-in-gallery-app-programmatically\">Open在Android中内置的应用程序库的图像编程的,而code看起来很好。

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

我想打开类似于画廊: http://i.stack.imgur.com /ZoUvU.png
我想选择的图片形成的文件夹画廊。

你知道如何修改code?

我用:

 意向意图=新的Intent();
intent.setComponent(新单元名(com.android.gallery,com.android.camera.GalleryPicker));// intent.setType(图像/ *);
intent.setAction(Intent.ACTION_GET_CONTENT);Log.i(AA,adafdsfa);
startActivityForResult(意向,1);

通过我得到的文件夹,画廊,但我不能让图片的路径。


解决方案

 文件DIR =新的文件(Environment.getExternalStorageDirectory()的toString()+/ SD卡/ yourfolder);
        Log.d(文件路径,dir.getPath());
        串dirPath = dir.getAbsolutePath();
        如果(dir.exists()及&放大器; dir.isDirectory()){
            意向意图=新意图(Intent.ACTION_VIEW);
            //告诉你的意图,以获得内容
            //打开URI对你的SD卡图像目录
                            //其高达你想要的数据图像或视频。
            intent.setType(图像/ *);
        // intent.setType(视频/ *);
            intent.setData(Uri.fromFile(DIR));
        // intent.setType(媒体/ *);
        //意图。
            startActivityForResult(意向,1);
        }
        其他
        {
            showToast(无文件存在,以示);
        }
      保护无效的onActivityResult(INT申请code,INT结果code,意图数据){
    // TODO自动生成方法存根
    super.onActivityResult(要求code,结果code,数据);     如果(要求code == 1){
         如果(数据== NULL){
            showToast(无图像中选择);
            //完();
        }
         其他
         {
         乌里selectedImageUri = data.getData();      //串filemanagerstring = selectedImageUri.getPath();         //媒体库
       字符串selectedImagePath =的getPath(selectedImageUri);         如果(selectedImagePath!= NULL)
         {
             意向意图=新的Intent();
             intent.setAction(Intent.ACTION_VIEW);
             intent.setData(selectedImageUri);
             startActivity(意向);
         }         其他
         {
             showToast(映像路径不正确);
         }
     }
        }}

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

It results with following image: http://i.stack.imgur.com/vz3S8.png, but this is not the result I want.

I want to open the gallery similar to: http://i.stack.imgur.com/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.

解决方案

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


     }
        }

}

这篇关于打开图像形式BUILT_IN图库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆