简体   繁体   中英

How to upload image from gallery to android?

I am working on an app which include uploading pictures, I am able to select pictures using following. By this it is directly taking me to gallery, how can I display an alert(like whatsapp profile pic change) before it taking me to gallery.

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_PICK);
startActivityForResult(intent, PICK_IMAGE_R);

You could pop up a dialog fragment when a user clicks your button or whatever to select a photo:

AlertDialog.Builder builder=new AlertDialog.Builder(MainActivity.this);
        builder.setTitle("Set a Profile Photo");


        final String[] Items={"Select a Profile Photo"}; // You can add more choices here
        builder.setItems(Items, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                if (i == 0){
                    // Your code to launch gallery here

                }
            }
        });
        builder.setCancelable(true);
        AlertDialog dialog=builder.create();
        dialog.show();

Check out more examples here: https://github.com/msandroid/AndroidUsefulExample_AlertDialog

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