[英]How to upload image from gallery to android?
我正在開發一個包含上傳圖片的應用程序,我可以使用以下方法選擇圖片。 通過這種方式,它直接帶我進入畫廊,在帶我進入畫廊之前,如何顯示警報(如whatsapp個人資料圖片更改)。
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_PICK);
startActivityForResult(intent, PICK_IMAGE_R);
當用戶單擊您的按鈕或選擇照片時,您可以彈出一個對話框片段:
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();
在此處查看更多示例: https : //github.com/msandroid/AndroidUsefulExample_AlertDialog
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.