Android 打开内置图库中的图像窗体
我已经读过这个链接:以编程方式在Android内置的Gallery应用程序中打开一个图像,代码看起来很好 结果如下图:,但这不是我想要的结果 我想打开类似以下内容的库:。 我想从文件夹库中选择图片 你知道如何修改代码吗 我用过:Android 打开内置图库中的图像窗体,android,gallery,Android,Gallery,我已经读过这个链接:以编程方式在Android内置的Gallery应用程序中打开一个图像,代码看起来很好 结果如下图:,但这不是我想要的结果 我想打开类似以下内容的库:。 我想从文件夹库中选择图片 你知道如何修改代码吗 我用过: Intent intent = new Intent(); intent.setComponent(new ComponentName("com.android.gallery", "com.android.camera.GalleryPicker")); //
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);
通过我得到的文件夹库,但我不能得到图片路径
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");
}
}
}
}