Among the common Activity Action Intent constants, ACTION_PICK android.intent.action.PICK means "select data". Let's briefly share some usages of Intent.ACTION_PICK that I know:
(1) Call the gallery to get all local images:
Intent imageIntent = new Intent(Intent.ACTION_GET_CONTENT);
imageIntent.setType(“image/*”);
startActivityForResult(imageIntent, PICK_CODE); //PICK_CODE is a constant
(2), call local contact:
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
startActivityForResult(intent, PICK_CONTACT);
(3), call music, get all local music files :
Intent audioIntent = new Intent(Intent.ACTION_GET_CONTENT);
audioIntent.setType(“audio/*”);
startActivityForResult(audioIntent, PICK_AUDIO);
(4), call video, get all local video files:
Intent videoIntent = new Intent(Intent .ACTION_GET_CONTENT);
videoIntent.setType("video/*");
startActivityForResult(videoIntent, PICK_VIDEO);
E.g:
public static void jumpToChooser(Activity activity) {
if (activity == null) {
return;
}
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
PackageManager packageManager = activity.getPackageManager();
List<ResolveInfo> resInfo = packageManager.queryIntentActivities(intent, 0);
if (resInfo != null && (!resInfo.isEmpty())) {
List<Intent> targets = new ArrayList<>();
for (ResolveInfo info : resInfo) {
Intent targeted = new Intent(Intent.ACTION_PICK);
targeted.setType("image/*");
ActivityInfo activityInfo = info.activityInfo;
String packageName = activityInfo.packageName;
if (activityInfo != null && packageName != null) {
if (packageName.contains(FILE_MANAGER) || packageName.contains(GALLERY_APP)) {//FILE_MANAGER,GALLERY_APP自定义包名
targeted.setPackage(packageName);
targets.add(targeted);
}
}
}
// intent = Intent.createChooser(targets.remove(0), activity.getString(R.string.vrmake_setting_chooser_title));
intent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targets.toArray(new Parcelable[]{}));
}
activity.startActivityForResult(intent, PHOTO_REQUEST_GALLERY);
}