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:org.openintents.shopping.ui.ShoppingActivity.java

/**
 * Called when the activity is first created.
 *//*from   w  ww . j  av a  2s .  co  m*/
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    if (debug) {
        Log.d(TAG, "Shopping list onCreate()");
    }

    mSortOrder = PreferenceActivity.getShoppingListSortOrderFromPrefs(this);

    mDistribution.setFirst(MENU_DISTRIBUTION_START, DIALOG_DISTRIBUTION_START);

    // Check whether EULA has been accepted
    // or information about new version can be presented.
    if (false && mDistribution.showEulaOrNewVersion()) {
        return;
    }

    setContentView(R.layout.activity_shopping);

    // mEditItemPosition = -1;

    // Automatic requeries (once a second)
    mUpdateInterval = 2000;
    mUpdating = false;

    // General Uris:
    mListUri = ShoppingContract.Lists.CONTENT_URI;
    mItemUri = ShoppingContract.Items.CONTENT_URI;
    mListItemUri = ShoppingContract.Items.CONTENT_URI;

    int defaultShoppingList = getLastUsedListFromPrefs();

    // Handle the calling intent
    final Intent intent = getIntent();
    final String type = intent.resolveType(this);
    final String action = intent.getAction();

    if (action == null) {
        // Main action
        mState = STATE_MAIN;

        mListUri = Uri.withAppendedPath(ShoppingContract.Lists.CONTENT_URI, "" + defaultShoppingList);

        intent.setData(mListUri);
    } else if (Intent.ACTION_MAIN.equals(action)) {
        // Main action
        mState = STATE_MAIN;

        mListUri = Uri.withAppendedPath(ShoppingContract.Lists.CONTENT_URI, "" + defaultShoppingList);

        intent.setData(mListUri);

    } else if (Intent.ACTION_VIEW.equals(action)) {
        mState = STATE_VIEW_LIST;

        setListUriFromIntent(intent.getData(), type);
    } else if (Intent.ACTION_INSERT.equals(action)) {

        mState = STATE_VIEW_LIST;

        setListUriFromIntent(intent.getData(), type);

    } else if (Intent.ACTION_PICK.equals(action)) {
        mState = STATE_PICK_ITEM;

        mListUri = Uri.withAppendedPath(ShoppingContract.Lists.CONTENT_URI, "" + defaultShoppingList);
    } else if (Intent.ACTION_GET_CONTENT.equals(action)) {
        mState = STATE_GET_CONTENT_ITEM;

        mListUri = Uri.withAppendedPath(ShoppingContract.Lists.CONTENT_URI, "" + defaultShoppingList);
    } else if (GeneralIntents.ACTION_INSERT_FROM_EXTRAS.equals(action)) {
        if (ShoppingListIntents.TYPE_STRING_ARRAYLIST_SHOPPING.equals(type)) {
            /*
             * Need to insert new items from a string array in the intent
            * extras Use main action but add an item to the options menu
            * for adding extra items
            */
            getShoppingExtras(intent);
            mState = STATE_MAIN;
            mListUri = Uri.withAppendedPath(ShoppingContract.Lists.CONTENT_URI, "" + defaultShoppingList);
            intent.setData(mListUri);
        } else if (intent.getDataString().startsWith(ShoppingContract.Lists.CONTENT_URI.toString())) {
            // Somewhat quick fix to pass data from ShoppingListsActivity to
            // this activity.

            // We received a valid shopping list URI:
            mListUri = intent.getData();

            getShoppingExtras(intent);
            mState = STATE_MAIN;
            intent.setData(mListUri);
        }
    } else {
        // Unknown action.
        Log.e(TAG, "Shopping: Unknown action, exiting");
        finish();
        return;
    }

    // hook up all buttons, lists, edit text:
    createView();

    // populate the lists
    fillListFilter();

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    // Get last part of URI:
    int selectList;
    try {
        selectList = Integer.parseInt(mListUri.getLastPathSegment());
    } catch (NumberFormatException e) {
        selectList = defaultShoppingList;
    }

    // select the default shopping list at the beginning:
    setSelectedListId(selectList);

    if (icicle != null) {
        String prevText = icicle.getString(ORIGINAL_ITEM);
        if (prevText != null) {
            mEditText.setTextKeepState(prevText);
        }
        // mTextEntryMenu = icicle.getInt(BUNDLE_TEXT_ENTRY_MENU);
        // mEditItemPosition = icicle.getInt(BUNDLE_CURSOR_ITEMS_POSITION);
        mItemUri = Uri.parse(icicle.getString(BUNDLE_ITEM_URI));
        List<String> pathSegs = mItemUri.getPathSegments();
        int num = pathSegs.size();
        mListItemUri = Uri.withAppendedPath(mListUri, pathSegs.get(num - 1));
        if (icicle.containsKey(BUNDLE_RELATION_URI)) {
            mRelationUri = Uri.parse(icicle.getString(BUNDLE_RELATION_URI));
        }
        mItemsView.mMode = icicle.getInt(BUNDLE_MODE);
        mItemsView.mModeBeforeSearch = icicle.getInt(BUNDLE_MODE_BEFORE_SEARCH);
    }

    // set focus to the edit line:
    mEditText.requestFocus();

    // TODO remove initFromPreferences from onCreate
    // we need it in resume to update after settings have changed
    initFromPreferences();
    // now update title and fill all items
    onModeChanged();

    mItemsView.setActionBarListener(this);
    mItemsView.setUndoListener(this);

    if ("myo".equals(BuildConfig.FLAVOR)) {
        try {
            Class myoToggleBoughtInputMethod = Class
                    .forName("org.openintents.shopping.ui.MyoToggleBoughtInputMethod");
            Constructor constructor = myoToggleBoughtInputMethod
                    .getConstructor(new Class[] { ShoppingActivity.class, mItemsView.getClass() });
            toggleBoughtInputMethod = (ToggleBoughtInputMethod) constructor
                    .newInstance(new Object[] { this, mItemsView });
        } catch (ClassNotFoundException e) {
        } catch (NoSuchMethodException e) {
        } catch (InvocationTargetException e) {
        } catch (InstantiationException e) {
        } catch (IllegalAccessException e) {
        }
    }
}

From source file:com.sbgapps.scoreit.ui.ScoreItActivity.java

private void showEditNameActionChoices() {
    new MaterialDialog.Builder(this).title(getString(R.string.edit_name)).titleColorRes(R.color.color_primary)
            .items(getResources().getStringArray(R.array.edit_name_action))
            .itemsCallback(new MaterialDialog.ListCallback() {
                @Override/* w w  w  .j av a  2  s . c o  m*/
                public void onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                    switch (which) {
                    default:
                    case 0:
                        Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
                        startActivityForResult(intent, REQ_PICK_CONTACT);
                        break;
                    case 1:
                        showEditNameDialog();
                        break;
                    }
                }
            }).show();
}

From source file:com.polyvi.xface.extension.contact.XContactsExt.java

/**
 * ?/*from w  w  w. ja v a 2  s  .com*/
 * @param callbackCtx
 */
private void startContactActivity() {
    Intent intent = new Intent(Intent.ACTION_PICK);
    intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
    mExtensionContext.getSystemContext().startActivityForResult(this, intent, PICK_CONTACT);
}

From source file:so.contacts.hub.basefunction.account.ui.YellowpagePersonalInfoActivity.java

/**
 * ? void/* w w  w  . j a  v  a 2 s.com*/
 */
protected void chooseImageFromGallery() {
    Intent intentFromGallery = new Intent();
    // 
    intentFromGallery.setType("image/*");
    intentFromGallery.setAction(Intent.ACTION_PICK);
    startActivityForResult(intentFromGallery, CODE_GALLERY_REQUEST);
}

From source file:com.sbgapps.scoreit.ScoreItActivity.java

private void pickContact() {
    Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
    startActivityForResult(intent, REQ_PICK_CONTACT);
}

From source file:spring16.cs442.com.obtchat_10.BluetoothChatFragment.java

private void selectImage() {
    final CharSequence[] items = { "Choose Color", "Take Photo", "Choose from Library", "Blue", "Colours",
            "Cancel" };
    AlertDialog.Builder builder = new AlertDialog.Builder(BluetoothChatFragment.this);
    builder.setTitle("Change Background!");
    builder.setItems(items, new DialogInterface.OnClickListener() {
        @Override//  w ww.j a  va2 s  .  co  m
        public void onClick(DialogInterface dialog, int item) {
            if (items[item].equals("Choose Color")) {
                cp.show();

                /* On Click listener for the dialog, when the user select the color */
                Button okColor = (Button) cp.findViewById(R.id.okColorButton);

                okColor.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        /* You can get single channel (value 0-255) */
                        //selectedColorR = cp.getRed();
                        //selectedColorG = cp.getGreen();
                        //selectedColorB = cp.getBlue();

                        /* Or the android RGB Color (see the android Color class reference) */
                        //selectedColorRGB = cp.getColor();
                        LinearLayout layout = (LinearLayout) findViewById(R.id.chatFragment);
                        layout.setBackgroundColor(cp.getColor());

                        cp.dismiss();
                    }
                });
            } else if (items[item].equals("Take Photo")) {
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(intent, 1888);
            } else if (items[item].equals("Choose from Library")) {
                Intent intent = new Intent(Intent.ACTION_PICK,
                        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                intent.setType("image/*");
                startActivityForResult(Intent.createChooser(intent, "Select File"), 79);
            } else if (items[item].equals("Blue")) {
                LinearLayout layout = (LinearLayout) findViewById(R.id.chatFragment);
                layout.setBackgroundDrawable(getResources().getDrawable(R.drawable.background));
            } else if (items[item].equals("Colours")) {
                LinearLayout layout = (LinearLayout) findViewById(R.id.chatFragment);
                layout.setBackgroundDrawable(getResources().getDrawable(R.drawable.background3));
            } else if (items[item].equals("Cancel")) {
                dialog.dismiss();
            }
        }
    });
    builder.show();
}

From source file:com.supremainc.biostar2.user.UserModifyFragment.java

private void editUserImage() {
    if (Build.VERSION.SDK_INT >= 23) {
        if ((ActivityCompat.checkSelfPermission(mContext,
                Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)
                || (ActivityCompat.checkSelfPermission(mContext,
                        Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)) {
            ActivityCompat/*from  ww w.  j  a  v a2  s.co m*/
                    .requestPermissions(mContext,
                            new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE,
                                    Manifest.permission.READ_EXTERNAL_STORAGE },
                            Setting.REQUEST_EXTERNAL_STORAGE);
            return;
        }
    }

    SelectPopup<SelectCustomData> selectPopup = new SelectPopup<SelectCustomData>(mContext, mPopup);
    ArrayList<SelectCustomData> linkType = new ArrayList<SelectCustomData>();
    linkType.add(new SelectCustomData(getString(R.string.take_picture), TAKE_PICTURE, false));
    linkType.add(new SelectCustomData(getString(R.string.from_gallery), FROM_GALLERY, false));
    linkType.add(new SelectCustomData(getString(R.string.delete_picture), DELETE_PICTURE, false));
    selectPopup.show(SelectType.CUSTOM, new OnSelectResultListener<SelectCustomData>() {
        @Override
        public void OnResult(ArrayList<SelectCustomData> selectedItem) {
            if (isInValidCheck(null)) {
                return;
            }
            if (selectedItem == null) {
                return;
            }
            int type = selectedItem.get(0).getIntId();
            switch (type) {
            case TAKE_PICTURE: {
                Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, ImageUtil.getTempFileUri());
                startActivityForResult(intent, REQ_ACTIVITY_CAMERA);
                break;
            }
            case FROM_GALLERY: {
                Intent intent = ImageUtil.getImageActionIntent(Intent.ACTION_PICK, false,
                        Setting.USER_PROFILE_IMAGE_SIZE, Setting.USER_PROFILE_IMAGE_SIZE);
                startActivityForResult(intent, REQ_ACTIVITY_CAMERA_CROP);
                break;
            }
            case DELETE_PICTURE: {
                mUserInfo.photo = "";
                mPhotoStatus = PhotoStatus.DELETE;
                mLayout.setUserPhotoDefault();
                mLayout.setBlurBackGroudDefault();
                mBackupPhoto = null;
                break;
            }
            }
        }
    }, linkType, getString(R.string.edit_photo), false);
}

From source file:com.xxjwd.chat.ChatActivity.java

 /**
 * /*from w w w.  j a  v a 2 s  . c o  m*/
 */
private void selectFileFromLocal() {
   Intent intent = null;
   if (Build.VERSION.SDK_INT < 19) {
      intent = new Intent(Intent.ACTION_GET_CONTENT);
      intent.setType("*/*");
      intent.addCategory(Intent.CATEGORY_OPENABLE);

   } else {
      intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
   }
   startActivityForResult(intent, REQUEST_CODE_SELECT_FILE);
}

From source file:com.mobantica.DriverItRide.activities.ActivityProfile.java

private void selectImage() {
    final CharSequence[] options = { getResources().getString(R.string.take_photo),
            getResources().getString(R.string.select_from_gallery), getResources().getString(R.string.cancel) };
    android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(this);

    builder.setTitle(getResources().getString(R.string.add_photo));

    builder.setItems(options, new DialogInterface.OnClickListener() {
        @Override//from www  .j av  a2 s .  c o  m
        public void onClick(DialogInterface dialog, int item) {
            if (options[item].equals(getResources().getString(R.string.take_photo))) {
                Boolean isSDPresent = android.os.Environment.getExternalStorageState()
                        .equals(android.os.Environment.MEDIA_MOUNTED);
                if (isSDPresent) {
                    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
                    startActivityForResult(intent, 1);
                    //Log.d(TAG, "onClick: " + fileUri);
                    ChnagedUri = fileUri;
                } else {
                    myToast(ActivityProfile.this,
                            getResources().getString(R.string.insert_an_sd_card_before_using_the_camera));
                }
            } else if (options[item].equals(getResources().getString(R.string.select_from_gallery))) {
                Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(intent, 2);
            } else if (options[item].equals("Cancel")) {
                dialog.dismiss();
            }
        }

    });

    builder.show();
}

From source file:sharedcode.turboeditor.activity.MainActivity.java

/**
 * Parses the intent/*from  w ww .j  a  v  a 2s . c om*/
 */
private void parseIntent(Intent intent) {
    final String action = intent.getAction();
    final String type = intent.getType();

    if (Intent.ACTION_VIEW.equals(action) || Intent.ACTION_EDIT.equals(action)
            || Intent.ACTION_PICK.equals(action) && type != null) {
        // Post event
        onEvent(new EventBusEvents.NewFileToOpen(new File(intent.getData().getPath())));
    } else if (Intent.ACTION_SEND.equals(action) && type != null) {
        if ("text/plain".equals(type)) {
            onEvent(new EventBusEvents.NewFileToOpen(intent.getStringExtra(Intent.EXTRA_TEXT)));
        }
    }
}