[英]Allow user to choose an image from their gallery to upload to imageview in an activity?
我不确定要搜索什么,我尝试了一些尝试,但没有找到我需要的东西。 基本上,我的应用程序有一个默认图像,即图像视图中显示的徽标。 我有一个“管理员”活动,用户将可以进一步自定义应用程序。 我如何允许他们从默认徽标更改为他们选择的徽标,并在mainactivity的同一imageview中显示它(与他们选择的位置分开,即admin活动)?
非常感谢!
点击按钮,我们将触发以下代码:
@Override
public void onClick(View v) {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, 1);
}
在ActivityResult上:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
try {
String path = "";
if (requestCode == 1) {
if (resultCode == RESULT_OK) {
Uri imageUri = data.getData();
Log.d("image selected path", imageUri.getPath());
System.out.println("image selected path"
+ imageUri.getPath());
path = getRealPathFromURI(EditProfileMemberActivity.this,
imageUri);
}
//DO other stuff
}
} catch (Exception e) {
System.out.println(e);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.