在我的Android应用程序中,我将一个字符串值附加到我的图像选择器事件。然后我想要恢复它,但它一直得到一个空值。
有谁知道什么是错的?
由于
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
Intent image_chooser = Intent.createChooser(intent, getString(R.string.select_picture));
image_chooser.putExtra("type", "6");
startActivityForResult(image_chooser, SELECT_PICTURE);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
String type = data.getExtras().getString("type"); // -- > null
if (type.equals("5")) {
Bitmap bitmap = MyImage.GetBitmapFromPath(this, data.getData(), 240, 180);
new Async_up_image(bitmap, NavigationScreen.CategoryWhosOptionsClicked);
} else {
analyze(data);
}
}
}
答案 0 :(得分:1)
请尝试这种方式,希望这有助于您解决问题。
HashMap<Integer,String> map = new HashMap<Integer, String>();
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
Intent image_chooser = Intent.createChooser(intent, getString(R.string.select_picture));
map.put(SELECT_PICTURE,"6");
startActivityForResult(image_chooser, SELECT_PICTURE);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if(requestCode==SELECT_PICTURE) {
String type = map.get(requestCode);
if (type.equals("5")) {
Bitmap bitmap = MyImage.GetBitmapFromPath(this, data.getData(), 240, 180);
new Async_up_image(bitmap, NavigationScreen.CategoryWhosOptionsClicked);
} else {
analyze(data);
}
}
}
}