List of usage examples for android.content Intent ACTION_PICK
String ACTION_PICK
To view the source code for android.content Intent ACTION_PICK.
Click Source Link
From source file:com.android.music.PlaylistBrowserFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view = inflater.inflate(R.layout.media_picker_activity, null); final Intent intent = getActivity().getIntent(); final String action = intent.getAction(); if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) { mCreateShortcut = true;/*w ww .j ava 2 s . c om*/ } getActivity().setVolumeControlStream(AudioManager.STREAM_MUSIC); mToken = MusicUtils.bindToService(getActivity(), new ServiceConnection() { public void onServiceConnected(ComponentName classname, IBinder obj) { if (Intent.ACTION_VIEW.equals(action)) { Bundle b = intent.getExtras(); if (b == null) { Log.w(TAG, "Unexpected:getExtras() returns null."); } else { try { long id = Long.parseLong(b.getString("playlist")); if (id == RECENTLY_ADDED_PLAYLIST) { playRecentlyAdded(); } else if (id == PODCASTS_PLAYLIST) { playPodcasts(); } else if (id == ALL_SONGS_PLAYLIST) { long[] list = MusicUtils.getAllSongs(getActivity()); if (list != null) { MusicUtils.playAll(getActivity(), list, 0); } } else { MusicUtils.playPlaylist(getActivity(), id); } } catch (NumberFormatException e) { Log.w(TAG, "Playlist id missing or broken"); } } getActivity().finish(); return; } MusicUtils.updateNowPlaying(getActivity()); } public void onServiceDisconnected(ComponentName classname) { } }); IntentFilter f = new IntentFilter(); f.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED); f.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED); f.addAction(Intent.ACTION_MEDIA_UNMOUNTED); f.addDataScheme("file"); getActivity().registerReceiver(mScanListener, f); lv = (ListView) view.findViewById(android.R.id.list); lv.setOnCreateContextMenuListener(this); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub if (mCreateShortcut) { final Intent shortcut = new Intent(); shortcut.setAction(Intent.ACTION_VIEW); shortcut.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/playlist"); shortcut.putExtra("playlist", String.valueOf(id)); final Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcut); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, ((TextView) view.findViewById(R.id.line1)).getText()); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(getActivity(), R.drawable.ic_launcher_shortcut_music_playlist)); getActivity().setResult(getActivity().RESULT_OK, intent); getActivity().finish(); return; } if (id == RECENTLY_ADDED_PLAYLIST) { Intent intent = new Intent(Intent.ACTION_PICK); intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track"); intent.putExtra("playlist", "recentlyadded"); startActivity(intent); } else if (id == PODCASTS_PLAYLIST) { Intent intent = new Intent(Intent.ACTION_PICK); intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track"); intent.putExtra("playlist", "podcasts"); startActivity(intent); } else { Intent intent = new Intent(Intent.ACTION_EDIT); intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track"); intent.putExtra("playlist", Long.valueOf(id).toString()); startActivity(intent); } } }); mAdapter = (PlaylistListAdapter) getActivity().getLastNonConfigurationInstance(); if (mAdapter == null) { //Log.i("@@@", "starting query"); mAdapter = new PlaylistListAdapter(getActivity().getApplication(), this, R.layout.track_list_item, mPlaylistCursor, new String[] { MediaStore.Audio.Playlists.NAME }, new int[] { android.R.id.text1 }); lv.setAdapter(mAdapter); //setTitle(R.string.working_playlists); getPlaylistCursor(mAdapter.getQueryHandler(), null); } else { mAdapter.setActivity(this); lv.setAdapter(mAdapter); mPlaylistCursor = mAdapter.getCursor(); // If mPlaylistCursor is null, this can be because it doesn't have // a cursor yet (because the initial query that sets its cursor // is still in progress), or because the query failed. // In order to not flash the error dialog at the user for the // first case, simply retry the query when the cursor is null. // Worst case, we end up doing the same query twice. if (mPlaylistCursor != null) { init(mPlaylistCursor); } else { //setTitle(R.string.working_playlists); getPlaylistCursor(mAdapter.getQueryHandler(), null); } } return view; }
From source file:com.akalizakeza.apps.ishusho.activity.NewPostActivity.java
@AfterPermissionGranted(RC_CAMERA_PERMISSIONS) private void showImagePicker() { // Check for camera permissions if (!EasyPermissions.hasPermissions(this, cameraPerms)) { EasyPermissions.requestPermissions(this, "This sample will upload a picture from your Camera", RC_CAMERA_PERMISSIONS, cameraPerms); return;/*from www .j a v a 2 s .c o m*/ } // Choose file storage location File file = new File(getExternalCacheDir(), UUID.randomUUID().toString()); mFileUri = Uri.fromFile(file); // Camera final List<Intent> cameraIntents = new ArrayList<Intent>(); final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); final PackageManager packageManager = getPackageManager(); final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0); for (ResolveInfo res : listCam) { final String packageName = res.activityInfo.packageName; final Intent intent = new Intent(captureIntent); intent.setComponent(new ComponentName(packageName, res.activityInfo.name)); intent.setPackage(packageName); intent.putExtra(MediaStore.EXTRA_OUTPUT, mFileUri); cameraIntents.add(intent); } // Image Picker Intent pickerIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); Intent chooserIntent = Intent.createChooser(pickerIntent, getString(R.string.picture_chooser_title)); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[cameraIntents.size()])); startActivityForResult(chooserIntent, TC_PICK_IMAGE); }
From source file:com.nonstop.android.SoC.Facebook.Hackbook.java
@Override public void onItemClick(AdapterView<?> arg0, View v, int position, long arg3) { switch (position) { /*//from w w w .ja va2 s . c om * Source Tag: upload_photo You can upload a photo from the media * gallery or from a remote server How to upload photo: * https://developers.facebook.com/blog/post/498/ */ case 0: { if (!Utility.mFacebook.isSessionValid()) { Util.showAlert(this, "Warning", "You must first log in."); } else { dialog = ProgressDialog.show(Hackbook.this, "", getString(R.string.please_wait), true, true); new AlertDialog.Builder(this).setTitle(R.string.gallery_remote_title) .setMessage(R.string.gallery_remote_msg) .setPositiveButton(R.string.gallery_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Intent.ACTION_PICK, (MediaStore.Images.Media.EXTERNAL_CONTENT_URI)); startActivityForResult(intent, PICK_EXISTING_PHOTO_RESULT_CODE); } }).setNegativeButton(R.string.remote_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { /* * Source tag: upload_photo_tag */ Bundle params = new Bundle(); params.putString("url", "http://www.facebook.com/images/devsite/iphone_connect_btn.jpg"); params.putString("caption", "FbAPIs Sample App photo upload"); Utility.mAsyncRunner.request("me/photos", params, "POST", new PhotoUploadListener(), null); } }).setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface d) { dialog.dismiss(); } }).show(); } break; } case 7: { if (!Utility.mFacebook.isSessionValid()) { Util.showAlert(this, "Warning", "You must first log in."); } else { new TokenRefreshDialog(Hackbook.this).show(); } } } }
From source file:com.suan.weclient.fragment.MassFragment.java
private void setIndex(int index) { nowIndex = index;/* w w w . j a va2 s .c om*/ for (int i = 0; i < 5; i++) { indexLayout[i].setSelected(false); } indexLayout[index].setSelected(true); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); switch (index) { case 0: fragmentTransaction.replace(R.id.mass_layout_content, massTextFragment); break; case 1: fragmentTransaction.replace(R.id.mass_layout_content, massImgFragment); massImgFragment.setSelectPhotoListener(new SelectPhotoListener() { @Override public void onSelectFromAlbum() { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, REQUEST_CODE_SELECT_PHOTO); } @Override public void onTakePhoto() { Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); String uploadImgPath = Util.getFilePath(UPLOAD_IMG_NAME); File out = new File(uploadImgPath); capturedImageName = out.getAbsolutePath(); i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(out)); startActivityForResult(i, REQUEST_CODE_TAKE_PHOTO); } }); break; case 2: fragmentTransaction.replace(R.id.mass_layout_content, massVoiceFragment); break; case 3: fragmentTransaction.replace(R.id.mass_layout_content, massAPPFragment); break; case 4: fragmentTransaction.replace(R.id.mass_layout_content, massVideoFragment); break; } fragmentTransaction.commit(); }
From source file:com.remobile.contacts.ContactManager.java
/** * Launches the Contact Picker to select a single contact. *//*from www. ja va 2s .co m*/ private void pickContactAsync() { final CordovaPlugin plugin = (CordovaPlugin) this; Runnable worker = new Runnable() { public void run() { Intent contactPickerIntent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI); plugin.cordova.startActivityForResult(plugin, contactPickerIntent, plugin.cordova.CONTACT_PICKER_RESULT); } }; this.cordova.getThreadPool().execute(worker); }
From source file:org.projectbuendia.client.ui.OdkActivityLauncher.java
/** * Shows the form with the given id in ODK collect. * @param callingActivity the {@link Activity} requesting the xform; when ODK closes, the user * will be returned to this activity * @param requestCode if >= 0, this code will be returned in onActivityResult() when the * activity exits * @param formId the id of the form to fetch * @param patient the {@link org.odk.collect.android.model.Patient} that this form entry will * correspond to//from w w w. j ava 2 s.c o m * @param fields a {@link Preset} object with any form fields that should be * pre-populated */ public static void showOdkCollect(Activity callingActivity, int requestCode, long formId, @Nullable org.odk.collect.android.model.Patient patient, @Nullable Preset fields) { Intent intent = new Intent(callingActivity, FormEntryActivity.class); Uri formUri = ContentUris.withAppendedId(FormsProviderAPI.FormsColumns.CONTENT_URI, formId); intent.setData(formUri); intent.setAction(Intent.ACTION_PICK); if (patient != null) { intent.putExtra("patient", patient); } if (fields != null) { intent.putExtra("fields", fields); } callingActivity.startActivityForResult(intent, requestCode); }
From source file:org.cm.podd.report.activity.SettingActivity.java
private void cropImage() { Intent photoPickerIntent;//ww w .ja v a 2 s . com if (mCurrentPhotoUri == null) { // no photo to edit, then first select what to edit photoPickerIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); photoPickerIntent.setType("image/*"); } else { // Edit photo after taken photoPickerIntent = new Intent("com.android.camera.action.CROP"); // indicate taken image type and Uri photoPickerIntent.setDataAndType(mCurrentPhotoUri, "image/*"); photoPickerIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } photoPickerIntent.putExtra("crop", "true"); photoPickerIntent.putExtra("aspectX", 1); photoPickerIntent.putExtra("aspectY", 1); photoPickerIntent.putExtra("outputX", 400); photoPickerIntent.putExtra("outputY", 400); photoPickerIntent.putExtra("return-data", true); photoPickerIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString()); startActivityForResult(photoPickerIntent, REQ_CODE_PICK_IMAGE); }
From source file:com.repay.android.frienddetails.FriendActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_settings: Intent intent = new Intent(); intent.setClass(this, SettingsActivity.class); startActivity(intent);/*from www. j a v a 2s . c o m*/ return true; case R.id.action_delete: AlertDialog.Builder dialog = new AlertDialog.Builder(this); dialog.setTitle(R.string.delete); dialog.setMessage(R.string.confirm_remove_person); dialog.setPositiveButton(R.string.delete, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { if (mDB != null) { mDB.removeFriend(mFriend.getRepayID()); finish(); } } catch (Exception e) { e.printStackTrace(); } } }); dialog.setNegativeButton(R.string.cancel, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.show(); return true; case R.id.action_info: new AlertDialog.Builder(this).setTitle(R.string.info).setMessage(R.string.info_dialog_text) .setPositiveButton(R.string.okay, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).show(); return true; case R.id.action_addDebt: Intent i = new Intent(this, AddDebtActivity.class); i.putExtra(DebtActivity.FRIEND, mFriend); startActivity(i); return true; case R.id.action_reLinkContact: Intent getContact = new Intent(Intent.ACTION_PICK); getContact.setType(ContactsContract.Contacts.CONTENT_TYPE); startActivityForResult(getContact, PICK_CONTACT_REQUEST); return true; case R.id.action_unLinkContact: mFriend = new Friend(mFriend.getRepayID(), null, mFriend.getName(), mFriend.getDebt()); mDB.updateFriendRecord(mFriend); return true; } return false; }
From source file:ucr.cs180.rlifts.DriverRegistration.java
private void selectImage() { final CharSequence[] items = { "Take Photo", "Choose from Library", "Cancel" }; AlertDialog.Builder builder = new AlertDialog.Builder(DriverRegistration.this); builder.setTitle("Add Photo!"); builder.setItems(items, new DialogInterface.OnClickListener() { @Override//w ww. j ava 2 s. co m public void onClick(DialogInterface dialog, int item) { if (items[item].equals("Take Photo")) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, REQUEST_CAMERA); } 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"), SELECT_FILE); } else if (items[item].equals("Cancel")) { dialog.dismiss(); } } }); builder.show(); }