打开图像形式BUILT_IN图库图像、形式、图库、BUILT_IN

2023-09-07 11:55:34 作者:騎著母豬ヅ去蹭樹

我已阅读此链接:在打开图像的Andr​​oid内置的图库应用程序编程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(映像路径不正确);         }     }        }} 

word怎么打开origin图像并修改图像呢

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


     }
        }

}