Example usage for android.content Intent ACTION_PICK

List of usage examples for android.content Intent ACTION_PICK

Introduction

In this page you can find the example usage for android.content Intent ACTION_PICK.

Prototype

String ACTION_PICK

To view the source code for android.content Intent ACTION_PICK.

Click Source Link

Document

Activity Action: Pick an item from the data, returning what was selected.

Usage

From source file:chinanurse.cn.nurse.Fragment_Nurse_job.IdentityFragment_ACTIVITY.java

protected void ShowPickDialog() {
    new AlertDialog.Builder(activity, AlertDialog.THEME_HOLO_LIGHT)
            .setNegativeButton("", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();/*w w w . j a  v a 2  s  .  c o m*/
                    Intent intentFromGallery = new Intent();
                    intentFromGallery.setType("image/*"); // 
                    intentFromGallery.setAction(Intent.ACTION_PICK);
                    startActivityForResult(intentFromGallery, PHOTO_REQUEST_ALBUM);

                }
            }).setPositiveButton("?", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.dismiss();
                    Intent intentFromCapture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    // ????
                    String state = Environment.getExternalStorageState();
                    if (state.equals(Environment.MEDIA_MOUNTED)) {
                        File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
                        File file = new File(path, "newpic.jpg");
                        intentFromCapture.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
                    }

                    startActivityForResult(intentFromCapture, PHOTO_REQUEST_CAMERA);
                }
            }).show();
}

From source file:net.bither.fragment.hot.OptionHotFragment.java

@Override
public void avatarFromGallery() {
    Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(intent, BitherSetting.REQUEST_CODE_IMAGE);
}

From source file:com.github.colorchief.colorchief.MainActivity.java

public void openImageFile(View view) {

    Intent imagePickerIntent = new Intent(Intent.ACTION_PICK);
    imagePickerIntent.setType("image/*");
    startActivityForResult(imagePickerIntent, SELECT_IMAGE);

}

From source file:org.tigase.mobile.chat.ChatHistoryFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.showChatsButton) {
        Intent chatListActivity = new Intent(getActivity(), ChatListActivity.class);
        this.getActivity().startActivityForResult(chatListActivity, TigaseMobileMessengerActivity.REQUEST_CHAT);
    } else if (item.getItemId() == R.id.closeChatButton) {
        layout.cancelEdit();/*from w w w .j  a  v a  2 s  .  com*/
        final Jaxmpp jaxmpp = ((MessengerApplication) getActivity().getApplicationContext()).getMultiJaxmpp()
                .get(chat.getSessionObject());
        final ViewPager viewPager = ((TigaseMobileMessengerActivity) this.getActivity()).viewPager;
        final AbstractChatManager cm = jaxmpp.getModule(MessageModule.class).getChatManager();
        try {
            viewPager.setCurrentItem(1);
            cm.close(chat);
            // this will be done by TigaseMessengerActiviy after receiving
            // ChatOpened event
            // viewPager.getAdapter().notifyDataSetChanged();
            viewPager.setCurrentItem(1);
            if (DEBUG)
                Log.i(TAG, "Chat with " + chat.getJid() + " (" + chat.getId() + ") closed");
        } catch (JaxmppException e) {
            Log.w(TAG, "Chat close problem!", e);
        }
    } else if (item.getItemId() == R.id.shareImageButton) {
        Log.v(TAG, "share selected for = " + chat.getJid().toString());
        Intent pickerIntent = new Intent(Intent.ACTION_PICK);
        pickerIntent.setType("image/*");
        pickerIntent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        startActivityForResult(pickerIntent, TigaseMobileMessengerActivity.SELECT_FOR_SHARE);
    } else if (item.getItemId() == R.id.shareVideoButton) {
        Log.v(TAG, "share selected for = " + chat.getJid().toString());
        Intent pickerIntent = new Intent(Intent.ACTION_PICK);
        pickerIntent.setType("video/*");
        pickerIntent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        startActivityForResult(pickerIntent, TigaseMobileMessengerActivity.SELECT_FOR_SHARE);
    }
    return true;
}

From source file:foam.littlej.android.app.ui.phone.AddCheckinActivity.java

/**
 * Create various dialog/*www.  j  a v a2s  . c  o m*/
 */
@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_ERROR_NETWORK: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.network_error));
        dialog.setMessage(getString(R.string.network_error_msg));
        dialog.setButton2(getString(R.string.ok), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setCancelable(false);
        return dialog;
    }
    case DIALOG_ERROR_SAVING: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.network_error));
        dialog.setMessage(getString(R.string.file_system_error_msg));
        dialog.setButton2(getString(R.string.ok), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setCancelable(false);
        return dialog;
    }

    case DIALOG_CHOOSE_IMAGE_METHOD: {

        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.choose_method));
        dialog.setMessage(getString(R.string.how_to_select_pic));
        dialog.setButton(getString(R.string.gallery_option), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                deleteExistingPhoto();
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_PICK);
                intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(intent, REQUEST_CODE_IMAGE);
                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.cancel), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setButton3(getString(R.string.camera_option), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                deleteExistingPhoto();
                Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                intent.putExtra(MediaStore.EXTRA_OUTPUT,
                        PhotoUtils.getPhotoUri(photoName, AddCheckinActivity.this));
                startActivityForResult(intent, REQUEST_CODE_CAMERA);
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    case DIALOG_SHOW_MESSAGE:
        AlertDialog.Builder messageBuilder = new AlertDialog.Builder(this);
        messageBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });

        AlertDialog showDialog = messageBuilder.create();
        showDialog.show();
        break;

    case DIALOG_SHOW_REQUIRED:
        AlertDialog.Builder requiredBuilder = new AlertDialog.Builder(this);
        requiredBuilder.setTitle(R.string.required_fields);
        requiredBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });

        AlertDialog showRequiredDialog = requiredBuilder.create();
        showRequiredDialog.show();
        break;

    // prompt for unsaved changes
    case DIALOG_SHOW_PROMPT: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.unsaved_changes));
        dialog.setMessage(getString(R.string.want_to_cancel));
        dialog.setButton(getString(R.string.no), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.yes), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // delete any existing photo in the pending folder
                new DiscardTask(AddCheckinActivity.this).execute((String) null);
                finish();
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    // prompt for report deletion
    case DIALOG_SHOW_DELETE_PROMPT: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.delete_report));
        dialog.setMessage(getString(R.string.want_to_delete));
        dialog.setButton(getString(R.string.no), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.yes), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // delete checkin
                deleteCheckins();
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    }
    return null;
}

From source file:com.mobicage.rogerthat.SendMessageButtonActivity.java

private void addButton() {
    final View dialog = getLayoutInflater().inflate(R.layout.new_button_dialog, null);
    final TextInputLayout captionViewLayout = (TextInputLayout) dialog.findViewById(R.id.button_caption);
    mCaptionView = captionViewLayout.getEditText();
    mActionView = (EditText) dialog.findViewById(R.id.button_action);
    final ImageButton actionHelpButton = (ImageButton) dialog.findViewById(R.id.action_help_button);
    final RadioButton noneRadio = (RadioButton) dialog.findViewById(R.id.action_none);
    final RadioButton telRadio = (RadioButton) dialog.findViewById(R.id.action_tel);
    final RadioButton geoRadio = (RadioButton) dialog.findViewById(R.id.action_geo);
    final RadioButton wwwRadio = (RadioButton) dialog.findViewById(R.id.action_www);
    final int iconColor = LookAndFeelConstants.getPrimaryIconColor(SendMessageButtonActivity.this);
    noneRadio.setChecked(true);/*from www . j a v a2s .c  om*/
    mActionView.setVisibility(View.GONE);
    actionHelpButton.setVisibility(View.GONE);
    noneRadio.setOnClickListener(new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            mActionView.setVisibility(View.GONE);
            actionHelpButton.setVisibility(View.GONE);
        }
    });
    telRadio.setOnClickListener(new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            mActionView.setText("");
            mActionView.setVisibility(View.VISIBLE);
            mActionView.setInputType(InputType.TYPE_CLASS_PHONE);
            actionHelpButton.setVisibility(View.VISIBLE);
            actionHelpButton.setImageDrawable(new IconicsDrawable(mService, FontAwesome.Icon.faw_address_book_o)
                    .color(iconColor).sizeDp(24));
        }
    });
    geoRadio.setOnClickListener(new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            mActionView.setText("");
            mActionView.setVisibility(View.VISIBLE);
            mActionView.setInputType(InputType.TYPE_CLASS_TEXT);
            actionHelpButton.setVisibility(View.VISIBLE);
            actionHelpButton.setImageDrawable(
                    new IconicsDrawable(mService, FontAwesome.Icon.faw_map_marker).color(iconColor).sizeDp(24));
        }
    });
    wwwRadio.setOnClickListener(new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            mActionView.setText("http://");
            mActionView.setVisibility(View.VISIBLE);
            mActionView.setInputType(InputType.TYPE_CLASS_TEXT);
            actionHelpButton.setVisibility(View.GONE);
        }
    });
    actionHelpButton.setOnClickListener(new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            if (telRadio.isChecked()) {
                Intent intent = new Intent(Intent.ACTION_PICK,
                        ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
                startActivityForResult(intent, PICK_CONTACT);
            } else if (geoRadio.isChecked()) {
                Intent intent = new Intent(SendMessageButtonActivity.this, GetLocationActivity.class);
                startActivityForResult(intent, GET_LOCATION);
            }
        }
    });
    String message = getString(R.string.create_button_title);
    String positiveCaption = getString(R.string.ok);
    String negativeCaption = getString(R.string.cancel);
    SafeDialogClick positiveClick = new SafeDialogClick() {
        @Override
        public void safeOnClick(DialogInterface di, int id) {
            String caption = mCaptionView.getText().toString();
            if ("".equals(caption.trim())) {
                UIUtils.showLongToast(SendMessageButtonActivity.this, getString(R.string.caption_required));
                return;
            }

            CannedButton cannedButton;
            if (!noneRadio.isChecked()) {
                String actionText = mActionView.getText().toString();
                if ("".equals(caption.trim())) {
                    UIUtils.showLongToast(SendMessageButtonActivity.this, getString(R.string.action_not_valid));
                    return;
                }
                if (telRadio.isChecked()) {
                    actionText = "tel://" + actionText;
                } else if (geoRadio.isChecked()) {
                    actionText = "geo://" + actionText;
                }

                Matcher action = actionPattern.matcher(actionText);
                if (!action.matches()) {
                    UIUtils.showLongToast(SendMessageButtonActivity.this, getString(R.string.action_not_valid));
                    return;
                }
                cannedButton = new CannedButton(caption, "".equals(action.group(2)) ? null : action.group());

            } else {
                cannedButton = new CannedButton(caption, null);
            }

            mCannedButtons.add(cannedButton);
            cannedButton.setSelected(true);
            mCannedButtonAdapter.notifyDataSetChanged();
            mButtons.add(cannedButton.getId());
            di.dismiss();
        }
    };
    AlertDialog alertDialog = UIUtils.showDialog(SendMessageButtonActivity.this, null, message, positiveCaption,
            positiveClick, negativeCaption, null, dialog);
    alertDialog.setCanceledOnTouchOutside(true);
}

From source file:org.y20k.transistor.PlayerActivityFragment.java

private void selectFromImagePicker() {
    // permission to read external storage granted
    if (ActivityCompat.checkSelfPermission(mActivity,
            Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {

        // get system picker for images
        Intent pickImageIntent = new Intent(Intent.ACTION_PICK,
                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        startActivityForResult(pickImageIntent, REQUEST_LOAD_IMAGE);
    }//from  ww w  . jav a2s.  co  m
    // permission to read external storage granted
    else {
        if (ActivityCompat.shouldShowRequestPermissionRationale(mActivity,
                Manifest.permission.READ_EXTERNAL_STORAGE)) {
            // ask for permission and explain why
            Snackbar snackbar = Snackbar.make(mRootView, R.string.snackbar_request_storage_access,
                    Snackbar.LENGTH_INDEFINITE);
            snackbar.setAction(R.string.dialog_generic_button_okay, new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                            PERMISSION_REQUEST_READ_EXTERNAL_STORAGE);
                }
            });
            snackbar.show();

        } else {
            // ask for permission without explanation
            requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                    PERMISSION_REQUEST_READ_EXTERNAL_STORAGE);
        }
    }
}

From source file:net.jongrakko.zipsuri.activity.PostReviseActivity.java

private void pickVideo() {
    Intent intent = new Intent(Intent.ACTION_PICK);
    intent.setType(MediaStore.Video.Media.CONTENT_TYPE);
    intent.setData(MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(intent, PICK_VIDEO_FOR_AVATAR);

}

From source file:com.yojiokisoft.yumekanow.activity.MakeCardActivity.java

/**
 * ???// w ww .  j  ava  2  s .com
 */
@Click(R.id.addBackImgButton)
/*package*/void addBackImgButtonClicked() {
    Intent intent = new Intent(Intent.ACTION_PICK);
    intent.setType("image/*");
    startActivityForResult(intent, INTENT_REQUEST_PICTURE);
}

From source file:com.brandroidtools.filemanager.activities.PickerActivity.java

private boolean isFilePickIntent(Intent intent) {
    final String action = intent.getAction();

    if (Intent.ACTION_GET_CONTENT.equals(action)) {
        return true;
    }/* w  w w  .ja v  a  2s.co m*/
    if (Intent.ACTION_PICK.equals(action)) {
        final Uri data = intent.getData();
        if (data != null && FILE_URI_SCHEME.equals(data.getScheme())) {
            return true;
        }
    }

    return false;
}