启动android图像选择器时仅从库中检索图像
我允许用户使用以下代码从设备中选择图像: (来自)启动android图像选择器时仅从库中检索图像,android,image,android-activity,android-intent,gallery,Android,Image,Android Activity,Android Intent,Gallery,我允许用户使用以下代码从设备中选择图像: (来自) 代码工作正常,但也显示选定区域内的应用程序资源。是否有任何方法可以从选择区域删除应用程序资源?否。这取决于用户选择的应用程序是否满足选择图片的要求 也就是说,可以通过向文件夹中添加标志文件或隐藏文件夹来阻止图像始终显示在库中,但这不是您所要求的。你不能用你的程序来做 public class BrowsePicture extends Activity { private static final int SELECT_PICTURE = 1
代码工作正常,但也显示选定区域内的应用程序资源。是否有任何方法可以从选择区域删除应用程序资源?否。这取决于用户选择的应用程序是否满足选择图片的要求 也就是说,可以通过向文件夹中添加标志文件或隐藏文件夹来阻止图像始终显示在库中,但这不是您所要求的。你不能用你的程序来做
public class BrowsePicture extends Activity {
private static final int SELECT_PICTURE = 1;
private String selectedImagePath;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
((Button) findViewById(R.id.Button01))
.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// in onCreate or any event where your want the user to
// select a file
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
"Select Picture"), SELECT_PICTURE);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
}
}
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}