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:us.shandian.blacklight.ui.statuses.NewPostActivity.java
private void showPicturePicker() { new AlertDialog.Builder(this).setItems(getResources().getStringArray(R.array.picture_picker_array), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int id) { switch (id) { case 0: Intent i = new Intent(); i.setAction(Intent.ACTION_PICK); i.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(i, REQUEST_PICK_IMG); break; case 1: Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(captureIntent, REQUEST_CAPTURE_PHOTO); break; }//w w w. j av a2 s.c o m } }).show(); }
From source file:com.soma.daemin.main.UserDetailActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_user_detail); imgDetail = false;/*from w w w. j a va 2 s.com*/ final String uId = getIntent().getStringExtra("uId"); mGlideRequestManager = Glide.with(UserDetailActivity.this); currentUserId = fUtil.getCurrentUserId(); fUtil.databaseReference.child(currentUserId).child(uId) .addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { try { if (dataSnapshot.getValue() != null) { btAddFriend.setVisibility(View.INVISIBLE);//null? } } catch (NullPointerException e) { } } @Override public void onCancelled(DatabaseError databaseError) { } }); final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); final CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById( R.id.collapsing_toolbar); ivProfile = (CircleImageView) findViewById(R.id.ivProfile); btAddProfile = (Button) findViewById(R.id.btAddProfile); btAddFriend = (Button) findViewById(R.id.btAddFriend); tvStudy = (TextView) findViewById(R.id.tvStudy); tvCareer = (TextView) findViewById(R.id.tvCareer); tvStartTime = (TextView) findViewById(R.id.tvStartTime); tvEndTime = (TextView) findViewById(R.id.tvEndTime); bar = (ProgressBar) findViewById(R.id.progressBar); if (uId.equals(currentUserId)) btAddFriend.setVisibility(View.INVISIBLE); try { fUtil.databaseReference.child("users").child(uId).addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (dataSnapshot.exists()) { User user = dataSnapshot.getValue(User.class); String study = user.getStudy(); String career = user.getCareer(); String startTime = user.getStartTime(); String endTime = user.getEndTime(); if (user.getThumbPhotoURL() == null) { imgDetail = false; collapsingToolbar.setTitle(""); ivProfile.setBackgroundResource(R.drawable.ic_account_circle_black_36dp); } else { mGlideRequestManager.load(user.getThumbPhotoURL()) .placeholder(R.drawable.ic_account_circle_black_36dp).dontAnimate().fitCenter() .into(ivProfile); imgDetail = true; } collapsingToolbar.setTitle(user.getuName()); if (study != null) tvStudy.setText(study); if (career != null) tvCareer.setText(career); SimpleDateFormat dayTime = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); if (startTime != null) { String sTime = dayTime.format(new Date(Long.parseLong(startTime))); tvStartTime.setText(sTime); } if (endTime != null) { String eTime = dayTime.format(new Date(Long.parseLong(endTime))); tvEndTime.setText(eTime); } } else { collapsingToolbar.setTitle(fUtil.getCurrentUserName()); ivProfile.setBackgroundResource(R.drawable.ic_account_circle_black_36dp); imgDetail = false; } } @Override public void onCancelled(DatabaseError databaseError) { imgDetail = false; } }); } catch (Exception e) { imgDetail = false; } btAddFriend.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { fUtil.databaseReference.child(currentUserId).child(uId).setValue(uId) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { btAddFriend.setVisibility(View.INVISIBLE); } }); // fUtil.databaseReference.child("users").child(uId).child("fcmToken") .addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { String token = (String) dataSnapshot.getValue(); FcmPush(token); } @Override public void onCancelled(DatabaseError databaseError) { } }); } }); FragmentManager fm = getSupportFragmentManager(); mTaskFragment = (NewPicUploadTaskFragment) fm.findFragmentByTag(TAG_TASK_FRAGMENT); // create the fragment and data the first time if (mTaskFragment == null) { // add the fragment mTaskFragment = new NewPicUploadTaskFragment(); fm.beginTransaction().add(mTaskFragment, TAG_TASK_FRAGMENT).commit(); } Bitmap selectedBitmap = mTaskFragment.getSelectedBitmap(); Bitmap thumbnail = mTaskFragment.getThumbnail(); if (selectedBitmap != null) { ivProfile.setImageBitmap(selectedBitmap); mResizedBitmap = selectedBitmap; } if (thumbnail != null) { mThumbnail = thumbnail; } ivProfile.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (imgDetail) { Intent i = new Intent(UserDetailActivity.this, DetailActivity.class); i.putExtra("uId", uId); startActivity(i); } } }); if (fUtil.getCurrentUserId().equals(uId)) { btAddProfile.setVisibility(View.VISIBLE); btAddProfile.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !EasyPermissions.hasPermissions(UserDetailActivity.this, cameraPerms)) { EasyPermissions.requestPermissions(this, " ? ", RC_CAMERA_PERMISSIONS, cameraPerms); return; } if (currentUserId != null) { Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(intent, REQUEST_IMAGE_PIC); } else { Toast.makeText(UserDetailActivity.this, getString(R.string.error_user_not_signed_in), Toast.LENGTH_SHORT).show(); } } }); } }
From source file:de.wikilab.android.friendica01.activity.HomeActivity.java
void navigate(String arg1) { currentMMItem = arg1;/*from w w w . j ava 2s.c o m*/ if (arg1.equals(getResources().getString(R.string.mm_timeline))) { navigatePostList(getResources().getString(R.string.mm_timeline)); } if (arg1.equals(getResources().getString(R.string.mm_notifications))) { navigatePostList(getResources().getString(R.string.mm_notifications)); } if (arg1.equals(getResources().getString(R.string.mm_mywall))) { navigatePostList(getResources().getString(R.string.mm_mywall)); } if (arg1.equals(getResources().getString(R.string.mm_updatemystatus))) { navigateStatusUpdate(); } if (arg1.equals(getResources().getString(R.string.mm_friends))) { navigateFriendList(); } if (arg1.equals(getResources().getString(R.string.mm_myphotoalbums))) { navigatePhotoGallery(getResources().getString(R.string.mm_myphotoalbums)); } if (arg1.equals(getResources().getString(R.string.mm_takephoto))) { Intent in = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); takePhotoTarget = Max.getTempFile(); in.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(takePhotoTarget)); startActivityForResult(in, RQ_TAKE_PHOTO); } if (arg1.equals(getResources().getString(R.string.mm_selectphoto))) { Intent in = new Intent(Intent.ACTION_PICK); in.setType("image/*"); startActivityForResult(in, RQ_SELECT_PHOTO); } if (arg1.equals(getResources().getString(R.string.mm_directmessages))) { //Intent in = new Intent(HomeActivity.this, MessagesActivity.class); //startActivity(in); navigateMessages("msg:all"); } if (arg1.equals(getResources().getString(R.string.mm_preferences))) { navigatePreferences(); } if (arg1.equals(getResources().getString(R.string.mm_logout))) { SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(HomeActivity.this) .edit(); //prefs.putString("login_server", null); //keep server and user ... prefs.putString("login_user", null); prefs.putString("login_password", null); //...only remove password prefs.commit(); finish(); } }
From source file:com.money.manager.ex.fragment.PayeeListFragment.java
@Override protected void setResult() { if (Intent.ACTION_PICK.equals(mAction)) { // Cursor that is already in the desired position, because positioned in the event onListItemClick Cursor cursor = ((SimpleCursorAdapter) getListAdapter()).getCursor(); int payeeId = cursor.getInt(cursor.getColumnIndex(Payee.PAYEEID)); String payeeName = cursor.getString(cursor.getColumnIndex(Payee.PAYEENAME)); sendResultToActivity(payeeId, payeeName); return;// w w w . j av a2s . c om } getActivity().setResult(PayeeActivity.RESULT_CANCELED); }
From source file:com.nuvolect.securesuite.main.SharedMenu.java
/** * Process a menu command and return a post command to be executed in the * calling activity// w w w . j a va 2 s. co m * @return post command. */ private static POST_CMD process() { switch (m_item_id) { case R.id.menu_shared_search: { SearchDialog.manageSearch(m_act, new SearchDialog.SearchCallbacks() { @Override public void onContactSelected(long contact_id) { if (invalidContact(contact_id)) { Toast.makeText(m_act, "Invalid contact", Toast.LENGTH_SHORT).show(); return; } LogUtil.log("SharedMenu.shared_search id selected: " + contact_id); Persist.setCurrentContactId(m_act, contact_id); if (m_post_cmd_callbacks == null) { LogUtil.log("ERROR SharedMenu.shared_search callbacks null "); } else { m_post_cmd_callbacks.postCommand(POST_CMD.START_CONTACT_DETAIL); } } }); break; } case R.id.menu_add_contact: { m_contact_id = SqlCipher.createEmptyContact(m_act, Cryp.getCurrentGroup()); Persist.setCurrentContactId(m_act, m_contact_id); // In case the user discards contact, it will be deleted Persist.setEmptyContactId(m_act, m_contact_id); return POST_CMD.START_CONTACT_EDIT; } case R.id.menu_delete_contact: { if (invalidContact(m_contact_id)) { Toast.makeText(m_act, "Select a contact to delete", Toast.LENGTH_SHORT).show(); return POST_CMD.DONE; } else { long nextId = 0; if (m_cursor != null) nextId = SqlCipher.getNextContactId(m_cursor); boolean success; if (MyGroups.isInTrash(m_contact_id)) { success = 1 == SqlCipher.deleteContact(m_act, m_contact_id, true);//sync==true if (success) Toast.makeText(m_act, "Contact deleted", Toast.LENGTH_SHORT).show(); } else { success = MyGroups.trashContact(m_act, Cryp.getCurrentAccount(), m_contact_id); if (success) Toast.makeText(m_act, "Item moved to trash", Toast.LENGTH_SHORT).show(); } if (!success) LogUtil.log("SharedMenu.delete_contact delete failure: " + m_contact_id); MyContacts.setValidId(m_act, nextId); MyGroups.loadGroupMemory(); return POST_CMD.REFRESH_LEFT_DEFAULT_RIGHT; } } case R.id.menu_edit_contact: { if (invalidContact(m_contact_id)) { Toast.makeText(m_act, "Invalid contact", Toast.LENGTH_SHORT).show(); return POST_CMD.NIL; } else return POST_CMD.START_CONTACT_EDIT; } case R.id.menu_edit_save: case R.id.menu_edit_discard: { return POST_CMD.START_CONTACT_DETAIL; } case R.id.menu_share_contact: { if (invalidContact(m_contact_id)) { Toast.makeText(m_act, "Invalid contact", Toast.LENGTH_SHORT).show(); return POST_CMD.NIL; } ExportVcf.emailVcf(m_act, Persist.getCurrentContactId(m_act)); return POST_CMD.NIL; } case R.id.menu_set_profile: Persist.setProfileId(m_act, m_contact_id); Toast.makeText(m_act, "Profile set", Toast.LENGTH_SHORT).show(); return POST_CMD.REFRESH_LEFT_DEFAULT_RIGHT; case R.id.menu_delete_group: { // Test for All other contacts group, it can't be deleted if (MyGroups.isBaseGroup(m_group_id)) { Toast.makeText(m_act, "This group cannot be removed", Toast.LENGTH_LONG).show(); } else { // Delete the group but not the contacts in the group. // Remove memory based and DB group title and data records matching group ID. // Sync transaction to companion device. MyGroups.deleteGroup(m_act, m_group_id, true);// Sync transaction is true // Group is now gone, select a default group int g_id = MyGroups.getDefaultGroup(Cryp.getCurrentAccount()); Cryp.setCurrentGroup(g_id); return POST_CMD.REFRESH_LEFT_DEFAULT_RIGHT; } break; } case R.id.menu_add_group: { Intent intent = new Intent(m_act, EditGroupActivity.class); m_act.startActivity(intent); break; } case R.id.menu_edit_group: { if (MyGroups.isPseudoGroup(m_group_id)) Toast.makeText(m_act, "Can't edit this group directly", Toast.LENGTH_SHORT).show(); else { Intent intent = new Intent(m_act, EditGroupActivity.class); intent.putExtra(CConst.GROUP_ID_KEY, Cryp.getCurrentGroup()); m_act.startActivity(intent); } break; } case R.id.menu_merge_group: MergeGroup.mergeGroup(m_act); break; //FUTURE integrate OpenPGP https://github.com/open-keychain/openpgp-api case R.id.menu_email_group: GroupSendEmail.emailGroup(m_act); break; case R.id.menu_text_group: { GroupSendSms.startGroupSms(m_act); break; } case R.id.menu_import_vcard: { if (hasPermission(READ_EXTERNAL_STORAGE)) { // Kickoff a browser activity here. // When user selects file, onActivityResult called with the result. Intent intent = new Intent(); intent.setClass(m_act, FileBrowserImportVcf.class); m_act.startActivityForResult(intent, CConst.IMPORT_VCARD_BROWSE_ACTION); } else PermissionUtil.requestReadExternalStorage(m_act, CConst.IMPORT_VCARD_REQUEST_EXTERNAL_STORAGE); break; } case R.id.menu_import_single_contact: { if (hasPermission(READ_CONTACTS)) { /** * Launch the contact picker intent. * Results returned in onActivityResult() */ Intent contactPickerIntent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); m_act.startActivityForResult(contactPickerIntent, CConst.IMPORT_SINGLE_CONTACT_PICKER); } else PermissionUtil.requestReadExternalStorage(m_act, CConst.IMPORT_SINGLE_CONTACT_REQUEST_READ); break; } case R.id.menu_import_account_contacts: { if (hasPermission(READ_CONTACTS) && hasPermission(GET_ACCOUNTS)) { CloudImportDialog.openDialog(m_act); } else { if (!hasPermission(READ_CONTACTS)) { PermissionUtil.requestReadContacts(m_act, CConst.IMPORT_ACCOUNT_CONTACTS_REQUEST_READ_CONTACTS); break; } if (!hasPermission(GET_ACCOUNTS)) { PermissionUtil.requestGetAccounts(m_act, CConst.IMPORT_ACCOUNT_CONTACTS_REQUEST_GET_ACCOUNTS); break; } } break; } case R.id.menu_export_group: { if (hasPermission(WRITE_EXTERNAL_STORAGE)) { ExportVcf.exportGroupVcardAsync(m_act, m_group_id); Toast.makeText(m_act, "Exporting...", Toast.LENGTH_LONG).show(); } else { PermissionUtil.requestWriteExternalStorage(m_act, 0); } break; } case R.id.menu_export_account: { if (hasPermission(WRITE_EXTERNAL_STORAGE)) { ExportVcf.exportAccountVcardAsync(m_act, Cryp.getCurrentAccount()); Toast.makeText(m_act, "Exporting...", Toast.LENGTH_LONG).show(); } else { PermissionUtil.requestWriteExternalStorage(m_act, 0); } break; } case R.id.menu_export_all: { if (hasPermission(WRITE_EXTERNAL_STORAGE)) { ExportVcf.exportAllVcardAsync(m_act); Toast.makeText(m_act, "Exporting...", Toast.LENGTH_LONG).show(); } else { PermissionUtil.requestWriteExternalStorage(m_act, 0); } break; } case R.id.menu_cleanup: { CleanupFragment f = CleanupFragment.newInstance(m_act); f.startFragment(); break; } case R.id.menu_backup_to_email: { if (hasPermission(WRITE_EXTERNAL_STORAGE)) { BackupRestore.backupToEmail(m_act); } else { PermissionUtil.requestWriteExternalStorage(m_act, 0); } break; } case R.id.menu_backup_to_storage: { if (hasPermission(WRITE_EXTERNAL_STORAGE)) BackupRestore.backupToStorage(m_act); else PermissionUtil.requestWriteExternalStorage(m_act, REQUEST_ID_BACKUP_TO_STORAGE); break; } case R.id.menu_backup_to_lan: { SqlFullSyncSource.getInstance().backupDiag(m_act); break; } case R.id.menu_accounts: { // import android.provider.Settings; m_act.startActivity(new Intent(Settings.ACTION_SYNC_SETTINGS)); break; } case R.id.menu_password_generator: { PasswordFragment f = PasswordFragment.newInstance(m_act); f.start(); break; } case R.id.menu_empty_trash: { DialogUtil.emptyTrash(m_act, m_post_cmd_callbacks); break; } case R.id.menu_settings: { Intent intent = new Intent(m_act, SettingsActivity.class); m_act.startActivity(intent); break; } case R.id.menu_help: { String url = AppSpecific.APP_WIKI_URL; Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); m_act.startActivity(i); break; } case R.id.menu_developer: { DeveloperDialog.start(m_act); break; } default: if (DEBUG && m_item != null) LogUtil.log("SharedMenu.default: " + m_item.getTitle()); } return POST_CMD.NIL; }
From source file:io.ingame.squarecamera.CameraLauncher.java
/** * Get image from photo library.// w w w .j av a2 s. c om * * @param srcType The album to get image from. * @param returnType Set the type of image to return. * @param encodingType */ // TODO: Images selected from SDCARD don't display correctly, but from CAMERA ALBUM do! // TODO: Images from kitkat filechooser not going into crop function public void getImage(int srcType, int returnType, int encodingType) { Intent intent = new Intent(); String title = GET_PICTURE; croppedUri = null; if (this.mediaType == PICTURE) { intent.setType("image/*"); if (this.allowEdit) { intent.setAction(Intent.ACTION_PICK); intent.putExtra("crop", "true"); if (targetWidth > 0) { intent.putExtra("outputX", targetWidth); } if (targetHeight > 0) { intent.putExtra("outputY", targetHeight); } if (targetHeight > 0 && targetWidth > 0 && targetWidth == targetHeight) { intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); } File photo = createCaptureFile(encodingType); croppedUri = Uri.fromFile(photo); setOutputUri(intent, croppedUri); } else { intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); } } else if (this.mediaType == VIDEO) { intent.setType("video/*"); title = GET_VIDEO; intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); } else if (this.mediaType == ALLMEDIA) { // I wanted to make the type 'image/*, video/*' but this does not work on all versions // of android so I had to go with the wildcard search. intent.setType("*/*"); title = GET_All; intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); } if (this.cordova != null) { this.cordova.startActivityForResult((CordovaPlugin) this, Intent.createChooser(intent, new String(title)), (srcType + 1) * 16 + returnType + 1); } }
From source file:com.bwash.bwashcar.activities.CompanyActivity.java
private void pickFromGallery() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { requestPermission(Manifest.permission.READ_EXTERNAL_STORAGE, getString(R.string.permission_read_storage_rationale), REQUEST_STORAGE_READ_ACCESS_PERMISSION); } else {//from www. j a va 2s .c om // Intent intent = new Intent(); // intent.setType("image/*"); // intent.setAction(Intent.ACTION_GET_CONTENT); // intent.addCategory(Intent.CATEGORY_OPENABLE); // startActivityForResult(Intent.createChooser(intent, getString(R.string.label_select_picture)), REQUEST_SELECT_PICTURE); mSelectPicturePopupWindow.dismissPopupWindow(); Intent pickIntent = new Intent(Intent.ACTION_PICK, null); // ???"image/jpeg ? image/png" pickIntent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*"); startActivityForResult(pickIntent, GALLERY_REQUEST_CODE); } }
From source file:com.awrtechnologies.carbudgetsales.MainActivity.java
public void imageOpen(Fragment f, final int REQUEST_CAMERA, final int SELECT_FILE) { GeneralHelper.getInstance(MainActivity.this).setTempFragment(f); final CharSequence[] items = { "Take Photo", "Choose from Library", "Cancel" }; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Add Photo!"); builder.setItems(items, new DialogInterface.OnClickListener() { @Override/* w ww. j av a 2 s . co m*/ public void onClick(DialogInterface dialog, int item) { if (items[item].equals("Take Photo")) { java.io.File imageFile = new File( (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + "/." + Constants.APPNAME + "/" + System.currentTimeMillis() + ".jpeg")); PreferencesManager.setPreferenceByKey(MainActivity.this, "IMAGEWWC", imageFile.getAbsolutePath()); // imageFilePath = imageFile; imageFileUri = Uri.fromFile(imageFile); Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri); startActivityForResult(i, REQUEST_CAMERA); } else if (items[item].equals("Choose from Library")) { if (Build.VERSION.SDK_INT < 19) { 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 { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("image/*"); startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE); } } else if (items[item].equals("Cancel")) { dialog.dismiss(); } } }); builder.show(); }
From source file:org.catrobat.catroid.ui.dialogs.NewSpriteDialog.java
private void setupGalleryButton(View parentView) { View galleryButton = parentView.findViewById(R.id.dialog_new_object_gallery); galleryButton.setOnClickListener(new View.OnClickListener() { @Override//from w w w .j a v a 2 s. c o m public void onClick(View view) { Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI); intent.putExtra(MediaStore.EXTRA_OUTPUT, lookUri); startActivityForResult(intent, REQUEST_SELECT_IMAGE); } }); }
From source file:com.twinone.locker.ui.SettingsFragment.java
private void backgroundFromGallery() { Log.d("", "background"); Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_PICK); List<ResolveInfo> ris = getActivity().getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (ris.size() > 0) { startActivityForResult(Intent.createChooser(intent, null), IMG_REQ_CODE); } else {/*from ww w . ja va 2 s.co m*/ Toast.makeText(getActivity(), "Error - No gallery app(?)", Toast.LENGTH_SHORT).show(); } }