简体   繁体   中英

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)??

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 :

    @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);
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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