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:com.crust87.ffmpegexecutorsample.MainActivity.java

public void onButtonLoadClick(View v) {
    Intent lIntent = new Intent(Intent.ACTION_PICK);
    lIntent.setType("video/*");
    lIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivityForResult(lIntent, 1000);
}

From source file:zuo.biao.library.ui.SelectPictureActivity.java

/**
 * ?/*  www . ja v  a 2s.  com*/
 */
public void selectPicFromLocal() {
    Intent intent;
    if (Build.VERSION.SDK_INT < 19) {
        intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("image/*");
    } else {
        intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    }
    toActivity(intent, REQUEST_CODE_LOCAL);
}

From source file:com.crust87.videotrackviewsample.MainActivity.java

public void onButtonLoadClick(View v) {
    if (ContextCompat.checkSelfPermission(mActivity,
            Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(mActivity, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
    } else {//from  www . java2 s .  c o m
        Intent lIntent = new Intent(Intent.ACTION_PICK);
        lIntent.setType("video/*");
        lIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivityForResult(lIntent, ACTIVITY_REQUEST_VIDEO);
    }
}

From source file:com.ichi2.anki.multimediacard.fields.BasicImageFieldController.java

@Override
public void createUI(Context context, LinearLayout layout) {
    mImagePreview = new ImageView(mActivity);

    DisplayMetrics metrics = getDisplayMetrics();

    int height = metrics.heightPixels;
    int width = metrics.widthPixels;

    LinearLayout.LayoutParams p = new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    setPreviewImage(mField.getImagePath(), getMaxImageSize());
    mImagePreview.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    mImagePreview.setAdjustViewBounds(true);

    mImagePreview.setMaxHeight((int) Math.round(height * 0.4));
    mImagePreview.setMaxWidth((int) Math.round(width * 0.6));

    mBtnGallery = new Button(mActivity);
    mBtnGallery.setText(gtxt(R.string.multimedia_editor_image_field_editing_galery));
    mBtnGallery.setOnClickListener(new View.OnClickListener() {
        @Override//from w  w w .  j  a  va  2s .  c  o m
        public void onClick(View v) {
            Intent i = new Intent(Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            mActivity.startActivityForResult(i, ACTIVITY_SELECT_IMAGE);
        }
    });

    mBtnCamera = new Button(mActivity);
    mBtnCamera.setText(gtxt(R.string.multimedia_editor_image_field_editing_photo));
    mBtnCamera.setOnClickListener(new View.OnClickListener() {
        @SuppressLint("NewApi")
        @Override
        public void onClick(View v) {
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            File image;
            File storageDir;
            String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US).format(new Date());
            try {
                storageDir = mActivity.getCacheDir();
                image = File.createTempFile("img_" + timeStamp, ".jpg", storageDir);
                mTempCameraImagePath = image.getPath();
                Uri uriSavedImage = FileProvider.getUriForFile(mActivity,
                        mActivity.getApplicationContext().getPackageName() + ".apkgfileprovider", image);

                cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
                mActivity.startActivityForResult(cameraIntent, ACTIVITY_TAKE_PICTURE);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
    // Chromebooks do not support camera capture yet.
    if (CompatHelper.isChromebook()) {
        mBtnCamera.setVisibility(View.INVISIBLE);
    }

    layout.addView(mImagePreview, android.view.ViewGroup.LayoutParams.FILL_PARENT, p);
    layout.addView(mBtnGallery, android.view.ViewGroup.LayoutParams.FILL_PARENT);
    layout.addView(mBtnCamera, android.view.ViewGroup.LayoutParams.FILL_PARENT);
}

From source file:de.skubware.opentraining.activity.create_exercise.ImageFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.create_exercise_image_fragment_menu, menu);

    // configure menu_item_take_photo
    MenuItem menu_item_take_photo = (MenuItem) menu.findItem(R.id.menu_item_take_photo);
    menu_item_take_photo.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            dispatchTakePictureIntent();
            return true;
        }//w  ww. j  a  v  a 2 s  .  c  o  m
    });

    // configure menu_item_chose_photo
    MenuItem menu_item_chose_photo = (MenuItem) menu.findItem(R.id.menu_item_chose_photo);
    menu_item_chose_photo.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
            photoPickerIntent.setType("image/*");
            startActivityForResult(photoPickerIntent, CreateExerciseActivity.CHOSE_PICTURE);
            return true;
        }
    });
}

From source file:ca.marcmeszaros.papyrus.browser.BooksBrowser.java

/**
 * Handles a click event from the LongClickDialog.
 *///from  ww  w .j av a  2 s .  c  o m
@Override
public void onClick(DialogInterface dialog, int position) {
    switch (position) {
    // delete
    case 0:
        // delete the entry in the database
        Uri bookDelete = ContentUris.withAppendedId(PapyrusContentProvider.Books.CONTENT_URI, selectedBookID);
        resolver.delete(bookDelete, null, null);

        Toast.makeText(getApplicationContext(), getString(R.string.BooksBrowser_toast_bookDeleted),
                Toast.LENGTH_SHORT).show();
        break;
    // lend book to someone
    case 1:
        Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
        startActivityForResult(intent, 1001);
        break;
    }
}

From source file:org.yammp.app.QueryFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {

    // Dialog doesn't allow us to wait for a result, so we need to store
    // the info we need for when the dialog posts its result
    mQueryCursor.moveToPosition(position);
    if (mQueryCursor.isBeforeFirst() || mQueryCursor.isAfterLast())
        return;//from   www .  j  a v a2  s  .c  om
    String selectedType = mQueryCursor.getString(mQueryCursor.getColumnIndexOrThrow(Audio.Media.MIME_TYPE));

    if ("artist".equals(selectedType)) {
        Intent intent = new Intent(Intent.ACTION_PICK);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/album");
        intent.putExtra("artist", Long.valueOf(id).toString());
        startActivity(intent);
    } else if ("album".equals(selectedType)) {
        Intent intent = new Intent(Intent.ACTION_PICK);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
        intent.putExtra("album", Long.valueOf(id).toString());
        startActivity(intent);
    } else if (position >= 0 && id >= 0) {
        long[] list = new long[] { id };
        MusicUtils.playAll(getActivity(), list, 0);
    } else {
        Log.e("QueryBrowser", "invalid position/id: " + position + "/" + id);
    }
}

From source file:com.wordpress.jftreading.FragmentMain.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.update_contact:
        startActivityForResult(new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI),
                PICK_CONTACT_REQUEST);//from  ww  w  . ja  v  a 2 s .com
        break;
    case R.id.call_btn:
        // Dial mobile number
        if (contactUri != null) {
            Intent callIntent = new Intent(Intent.ACTION_CALL);
            callIntent.setData(Uri.parse("tel:" + getMobileNumber(contactUri)));
            startActivity(callIntent);
        }
        break;
    case R.id.send_btn:
        String stextMessage = textMessage.getText().toString();
        if (stextMessage.matches("")) {

        } else if (contactUri != null) {

            dialog = ProgressDialog.show(getActivity(), "Sending", "Sending text message");
            Thread th = new Thread(new Runnable() {

                @Override
                public void run() {
                    // Send text message
                    try {
                        String SENT = "sent";
                        String DELIVERED = "delivered";

                        Intent sentIntent = new Intent(SENT);
                        //Create Pending Intents
                        PendingIntent sentPI = PendingIntent.getBroadcast(getActivity().getApplicationContext(),
                                0, sentIntent, PendingIntent.FLAG_UPDATE_CURRENT);

                        Intent deliveryIntent = new Intent(DELIVERED);

                        PendingIntent deliverPI = PendingIntent.getBroadcast(
                                getActivity().getApplicationContext(), 0, deliveryIntent,
                                PendingIntent.FLAG_UPDATE_CURRENT);
                        //Register for SMS send action
                        getActivity().registerReceiver(new BroadcastReceiver() {
                            String result = "";

                            @Override
                            public void onReceive(Context context, Intent intent) {

                                switch (getResultCode()) {

                                case Activity.RESULT_OK:
                                    result = "Message sent";
                                    break;
                                case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                                    result = "Sending failed";
                                    break;
                                case SmsManager.RESULT_ERROR_RADIO_OFF:
                                    result = "Radio off";
                                    break;
                                case SmsManager.RESULT_ERROR_NULL_PDU:
                                    result = "No PDU defined";
                                    break;
                                case SmsManager.RESULT_ERROR_NO_SERVICE:
                                    result = "No service";
                                    break;
                                }

                                handler.post(new Runnable() {

                                    @Override
                                    public void run() {
                                        if (result != "") {
                                            Toast toast = Toast.makeText(getActivity().getApplicationContext(),
                                                    result, Toast.LENGTH_LONG);
                                            toast.setGravity(Gravity.CENTER, 0, 0);
                                            toast.show();
                                            result = "";
                                        }
                                        dialog.dismiss();
                                    }
                                });
                            }

                        }, new IntentFilter(SENT));
                        //Register for Delivery event
                        getActivity().registerReceiver(new BroadcastReceiver() {

                            @Override
                            public void onReceive(Context context, Intent intent) {
                                handler.post(new Runnable() {

                                    @Override
                                    public void run() {
                                        Toast.makeText(getActivity().getApplicationContext(), "Delivered",
                                                Toast.LENGTH_LONG).show();
                                    }
                                });
                            }

                        }, new IntentFilter(DELIVERED));

                        //Send SMS
                        SmsManager smsManager = SmsManager.getDefault();
                        smsManager.sendTextMessage(getMobileNumber(contactUri), null,
                                textMessage.getText().toString(), sentPI, deliverPI);
                    } catch (Exception ex) {
                        final String exception = ex.getMessage().toString();
                        handler.post(new Runnable() {

                            @Override
                            public void run() {
                                Toast.makeText(getActivity().getApplicationContext(), exception,
                                        Toast.LENGTH_LONG).show();
                            }
                        });
                        ex.printStackTrace();
                        dialog.dismiss();
                    }

                }
            });
            th.start();
        }
        break;
    default:
        break;
    }
}

From source file:net.micode.fileexplorer.FileViewActivity.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mActivity = getActivity();//from   ww w. j av a  2s  . co  m
    // getWindow().setFormat(android.graphics.PixelFormat.RGBA_8888);
    mRootView = inflater.inflate(R.layout.file_explorer_list, container, false);
    ActivitiesManager.getInstance().registerActivity(ActivitiesManager.ACTIVITY_FILE_VIEW, mActivity);

    mFileCagetoryHelper = new FileCategoryHelper(mActivity);
    mFileViewInteractionHub = new FileViewInteractionHub(this);
    Intent intent = mActivity.getIntent();
    String action = intent.getAction();
    if (!TextUtils.isEmpty(action)
            && (action.equals(Intent.ACTION_PICK) || action.equals(Intent.ACTION_GET_CONTENT))) {
        mFileViewInteractionHub.setMode(Mode.Pick);

        boolean pickFolder = intent.getBooleanExtra(PICK_FOLDER, false);
        if (!pickFolder) {
            String[] exts = intent.getStringArrayExtra(EXT_FILTER_KEY);
            if (exts != null) {
                mFileCagetoryHelper.setCustomCategory(exts);
            }
        } else {
            mFileCagetoryHelper.setCustomCategory(new String[] {} /*folder only*/);
            mRootView.findViewById(R.id.pick_operation_bar).setVisibility(View.VISIBLE);

            mRootView.findViewById(R.id.button_pick_confirm).setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    try {
                        Intent intent = Intent.parseUri(mFileViewInteractionHub.getCurrentPath(), 0);
                        mActivity.setResult(Activity.RESULT_OK, intent);
                        mActivity.finish();
                    } catch (URISyntaxException e) {
                        e.printStackTrace();
                    }
                }
            });

            mRootView.findViewById(R.id.button_pick_cancel).setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    mActivity.finish();
                }
            });
        }
    } else {
        mFileViewInteractionHub.setMode(Mode.View);
    }

    mFileListView = (ListView) mRootView.findViewById(R.id.file_path_list);
    mFileIconHelper = new FileIconHelper(mActivity);
    mAdapter = new FileListAdapter(mActivity, R.layout.file_browser_item, mFileNameList,
            mFileViewInteractionHub, mFileIconHelper);

    boolean baseSd = intent.getBooleanExtra(GlobalConsts.KEY_BASE_SD,
            !FileExplorerPreferenceActivity.isReadRoot(mActivity));
    Log.i(LOG_TAG, "baseSd = " + baseSd);

    String rootDir = intent.getStringExtra(ROOT_DIRECTORY);
    if (!TextUtils.isEmpty(rootDir)) {
        if (baseSd && this.sdDir.startsWith(rootDir)) {
            rootDir = this.sdDir;
        }
    } else {
        rootDir = baseSd ? this.sdDir : GlobalConsts.ROOT_PATH;
    }
    mFileViewInteractionHub.setRootPath(rootDir);

    String currentDir = FileExplorerPreferenceActivity.getPrimaryFolder(mActivity);
    Uri uri = intent.getData();
    if (uri != null) {
        if (baseSd && this.sdDir.startsWith(uri.getPath())) {
            currentDir = this.sdDir;
        } else {
            currentDir = uri.getPath();
        }
    }
    mFileViewInteractionHub.setCurrentPath(currentDir);
    Log.i(LOG_TAG, "CurrentDir = " + currentDir);

    mBackspaceExit = (uri != null) && (TextUtils.isEmpty(action)
            || (!action.equals(Intent.ACTION_PICK) && !action.equals(Intent.ACTION_GET_CONTENT)));

    mFileListView.setAdapter(mAdapter);
    mFileViewInteractionHub.refreshFileList();

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
    intentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    intentFilter.addDataScheme("file");
    mActivity.registerReceiver(mReceiver, intentFilter);

    updateUI();
    setHasOptionsMenu(true);
    return mRootView;
}

From source file:com.google.android.apps.paco.FindMyExperimentsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mainLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.find_experiments, null);
    setContentView(mainLayout);/*w  ww .  j a  v a  2s .  c  o m*/
    Intent intent = getIntent();
    if (intent.getData() == null) {
        intent.setData(ExperimentColumns.CONTENT_URI);
    }

    userPrefs = new UserPreferences(this);
    list = (ListView) findViewById(R.id.find_experiments_list);
    createListHeader();
    createRefreshHeader();

    experimentProviderUtil = new ExperimentProviderUtil(this);

    refreshButton = (Button) findViewById(R.id.RefreshExperimentsButton2);
    refreshButton.setVisibility(View.VISIBLE);

    refreshButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (!isConnected()) {
                showDialogById(DownloadHelper.NO_NETWORK_CONNECTION);
            } else {
                refreshList();
            }
        }
    });

    progressBar = (ProgressBar) findViewById(R.id.findExperimentsProgressBar);

    reloadAdapter();
    list.setItemsCanFocus(true);
    list.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> listview, View textview, int position, long id) {
            Experiment experiment = experiments.get(position);
            Uri uri = ContentUris.withAppendedId(getIntent().getData(), experiment.getServerId());

            String action = getIntent().getAction();
            if (Intent.ACTION_PICK.equals(action) || Intent.ACTION_GET_CONTENT.equals(action)) {
                // The caller is waiting for us to return an experiment selected by
                // the user. The have clicked on one, so return it now.
                setResult(RESULT_OK, new Intent().setData(uri));
            } else {
                Intent experimentIntent = new Intent(FindMyExperimentsActivity.this,
                        ExperimentDetailActivity.class);
                experimentIntent.setData(uri);
                experimentIntent.putExtra(ExperimentDetailActivity.ID_FROM_MY_EXPERIMENTS_FILE, true);
                startActivityForResult(experimentIntent, JOIN_REQUEST_CODE);
            }
        }
    });
    registerForContextMenu(list);
}