[英]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.