Android How can I call Camera or Gallery Intent Together

后端 未结 7 1780
被撕碎了的回忆
被撕碎了的回忆 2020-12-02 09:27

If I want to capture image from native camera, I can do:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTR         


        
7条回答
  •  庸人自扰
    2020-12-02 09:50

    I think I encountered your case before. An idea is that we will create a one item list alert dialog with selectable item, and each item will do a unique function defined by your own intention. If you want an icon for each element in items list, it should take a bit more work to do. Hope it will helpful.

        String title = "Open Photo";
        CharSequence[] itemlist ={"Take a Photo",
                      "Pick from Gallery",
                      "Open from File"};
    
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setIcon(R.drawable.icon_app);
        builder.setTitle(title);
        builder.setItems(itemlist, new DialogInterface.OnClickListener() {
    
            @Override
            public void onClick(DialogInterface dialog, int which) {
                switch (which) {
                case 0:// Take Photo
                    // Do Take Photo task here
                    break;
                case 1:// Choose Existing Photo
                    // Do Pick Photo task here
                    break;
                case 2:// Choose Existing File
                    // Do Pick file here
                    break;
                default:
                    break;
                }
            }
        });
        AlertDialog alert = builder.create();
        alert.setCancelable(true);
        alert.show();
    

提交回复
热议问题