简体   繁体   English

允许用户从图库中选择图片以上传到活动中的imageview吗?

[英]Allow user to choose an image from their gallery to upload to imageview in an activity?

I am not sure what to search for, I have tried a few things but have not found what I need. 我不确定要搜索什么,我尝试了一些尝试,但没有找到我需要的东西。 Basically I have a default image for my app that is the logo displaying in an imageview. 基本上,我的应用程序有一个默认图像,即图像视图中显示的徽标。 I have and "admin" activity where the user will be able to customize the app further. 我有一个“管理员”活动,用户将可以进一步自定义应用程序。 How would I allow them to change from my default logo to one of their choice and display it in the same imageview on the mainactivity (separate from where they choose it, the admin activity)?? 我如何允许他们从默认徽标更改为他们选择的徽标,并在mainactivity的同一imageview中显示它(与他们选择的位置分开,即admin活动)?

Thanks much! 非常感谢!

On click of button we will trigger following code: 点击按钮,我们将触发以下代码:

   @Override
            public void onClick(View v) {
                Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                photoPickerIntent.setType("image/*");
                startActivityForResult(photoPickerIntent, 1);
            }

On ActivityResult : 在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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM