如何从画廊的Android上传图片 [英] How to upload image from gallery in android
问题描述
我想从我的手机图库上传图片到我的应用程序。在我的应用程序有按钮命名上传。当我点击按钮,就应该移动到画廊和画廊,如果我选择所选影像将显示为缩略图application.I要上传10张图片,从库中我的应用程序的形象。
I want to upload image from my phone gallery into my application .In my application there is button named upload. when i click button,it should move to gallery and in gallery if i select image that selected image should display as thumbnail in application.I want to upload 10 images, from gallery in my application.
推荐答案
在点击图库按钮,开始startActivityForResult如下:
On click of the gallery button, start startActivityForResult as follows:
startActivityForResult(new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), GET_FROM_GALLERY);
因此,检测GET_FROM_GALLERY(这是一个静态的INT,您所选择的任何请求数量,例如,公共静态最终诠释GET_FROM_GALLERY = 3;
)。里面onActivityResult
Consequently, detect GET_FROM_GALLERY (which is a static int, any request number of your choice e.g., public static final int GET_FROM_GALLERY = 3;
) inside onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//Detects request codes
if(requestCode==GET_FROM_GALLERY && resultCode == Activity.RESULT_OK) {
Uri selectedImage = data.getData();
Bitmap bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImage);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
这篇关于如何从画廊的Android上传图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!