List of usage examples for android.content Intent ACTION_GET_CONTENT
String ACTION_GET_CONTENT
To view the source code for android.content Intent ACTION_GET_CONTENT.
Click Source Link
From source file:kr.wdream.ui.ChatActivity.java
private void processSelectedAttach(int which) { if (which == attach_photo || which == attach_gallery || which == attach_document || which == attach_video) { String action;//from ww w. j a va 2 s . com if (currentChat != null) { if (currentChat.participants_count > MessagesController.getInstance().groupBigSize) { if (which == attach_photo || which == attach_gallery) { action = "bigchat_upload_photo"; } else { action = "bigchat_upload_document"; } } else { if (which == attach_photo || which == attach_gallery) { action = "chat_upload_photo"; } else { action = "chat_upload_document"; } } } else { if (which == attach_photo || which == attach_gallery) { action = "pm_upload_photo"; } else { action = "pm_upload_document"; } } if (!MessagesController.isFeatureEnabled(action, ChatActivity.this)) { return; } } if (which == attach_photo) { if (Build.VERSION.SDK_INT >= 23 && getParentActivity() .checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { getParentActivity().requestPermissions(new String[] { Manifest.permission.CAMERA }, 19); return; } try { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File image = AndroidUtilities.generatePicturePath(); if (image != null) { if (Build.VERSION.SDK_INT >= 24) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile( getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", image)); takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image)); } currentPicturePath = image.getAbsolutePath(); } startActivityForResult(takePictureIntent, 0); } catch (Exception e) { FileLog.e("tmessages", e); } } else if (which == attach_gallery) { if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission( Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { getParentActivity().requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, 4); return; } PhotoAlbumPickerActivity fragment = new PhotoAlbumPickerActivity(false, currentEncryptedChat == null || AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 46, true, ChatActivity.this); fragment.setDelegate(new PhotoAlbumPickerActivity.PhotoAlbumPickerActivityDelegate() { @Override public void didSelectPhotos(ArrayList<String> photos, ArrayList<String> captions, ArrayList<ArrayList<TLRPC.InputDocument>> masks, ArrayList<MediaController.SearchImage> webPhotos) { SendMessagesHelper.prepareSendingPhotos(photos, null, dialog_id, replyingMessageObject, captions, masks); SendMessagesHelper.prepareSendingPhotosSearch(webPhotos, dialog_id, replyingMessageObject); showReplyPanel(false, null, null, null, false, true); DraftQuery.cleanDraft(dialog_id, true); } @Override public void startPhotoSelectActivity() { try { Intent videoPickerIntent = new Intent(); videoPickerIntent.setType("video/*"); videoPickerIntent.setAction(Intent.ACTION_GET_CONTENT); videoPickerIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long) (1024 * 1024 * 1536)); Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); Intent chooserIntent = Intent.createChooser(photoPickerIntent, null); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { videoPickerIntent }); startActivityForResult(chooserIntent, 1); } catch (Exception e) { FileLog.e("tmessages", e); } } @Override public boolean didSelectVideo(String path) { if (Build.VERSION.SDK_INT >= 16) { return !openVideoEditor(path, true, true); } else { SendMessagesHelper.prepareSendingVideo(path, 0, 0, 0, 0, null, dialog_id, replyingMessageObject, null); showReplyPanel(false, null, null, null, false, true); DraftQuery.cleanDraft(dialog_id, true); return true; } } }); presentFragment(fragment); } else if (which == attach_video) { if (Build.VERSION.SDK_INT >= 23 && getParentActivity() .checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { getParentActivity().requestPermissions(new String[] { Manifest.permission.CAMERA }, 20); return; } try { Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); File video = AndroidUtilities.generateVideoPath(); if (video != null) { if (Build.VERSION.SDK_INT >= 24) { takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile( getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", video)); takeVideoIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); takeVideoIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else if (Build.VERSION.SDK_INT >= 18) { takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(video)); } takeVideoIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long) (1024 * 1024 * 1536)); currentPicturePath = video.getAbsolutePath(); } startActivityForResult(takeVideoIntent, 2); } catch (Exception e) { FileLog.e("tmessages", e); } } else if (which == attach_location) { if (!AndroidUtilities.isGoogleMapsInstalled(ChatActivity.this)) { return; } LocationActivity fragment = new LocationActivity(); fragment.setDelegate(new LocationActivity.LocationActivityDelegate() { @Override public void didSelectLocation(TLRPC.MessageMedia location) { SendMessagesHelper.getInstance().sendMessage(location, dialog_id, replyingMessageObject, null, null); moveScrollToLastMessage(); showReplyPanel(false, null, null, null, false, true); DraftQuery.cleanDraft(dialog_id, true); if (paused) { scrollToTopOnResume = true; } } }); presentFragment(fragment); } else if (which == attach_document) { if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission( Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { getParentActivity().requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, 4); return; } DocumentSelectActivity fragment = new DocumentSelectActivity(); fragment.setDelegate(new DocumentSelectActivity.DocumentSelectActivityDelegate() { @Override public void didSelectFiles(DocumentSelectActivity activity, ArrayList<String> files) { activity.finishFragment(); SendMessagesHelper.prepareSendingDocuments(files, files, null, null, dialog_id, replyingMessageObject); showReplyPanel(false, null, null, null, false, true); DraftQuery.cleanDraft(dialog_id, true); } @Override public void startDocumentSelectActivity() { try { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("*/*"); startActivityForResult(photoPickerIntent, 21); } catch (Exception e) { FileLog.e("tmessages", e); } } }); presentFragment(fragment); } else if (which == attach_audio) { if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission( Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { getParentActivity().requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, 4); return; } AudioSelectActivity fragment = new AudioSelectActivity(); fragment.setDelegate(new AudioSelectActivity.AudioSelectActivityDelegate() { @Override public void didSelectAudio(ArrayList<MessageObject> audios) { SendMessagesHelper.prepareSendingAudioDocuments(audios, dialog_id, replyingMessageObject); showReplyPanel(false, null, null, null, false, true); DraftQuery.cleanDraft(dialog_id, true); } }); presentFragment(fragment); } else if (which == attach_contact) { if (Build.VERSION.SDK_INT >= 23) { if (getParentActivity().checkSelfPermission( Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) { getParentActivity().requestPermissions(new String[] { Manifest.permission.READ_CONTACTS }, 5); return; } } try { Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE); startActivityForResult(intent, 31); } catch (Exception e) { FileLog.e("tmessages", e); } } }
From source file:com.bernard.beaconportal.activities.activity.MessageList.java
void onImport() { Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("*/*"); PackageManager packageManager = getPackageManager(); List<ResolveInfo> infos = packageManager.queryIntentActivities(i, 0); if (infos.size() > 0) { startActivityForResult(Intent.createChooser(i, null), ACTIVITY_REQUEST_PICK_SETTINGS_FILE); } else {//from w w w . j a v a 2 s . co m showDialog(DIALOG_NO_FILE_MANAGER); } }
From source file:com.tct.mail.compose.ComposeActivity.java
@SuppressLint("NewApi") private void doAttach(String type) { mAddingAttachment = true;//TS: yang.mei 2015-1-19 EMAIL BUGFIX_1441004 MOD //TS: zheng.zou 2015-11-30 EMAIL TASK_869664 ADD_S if (PermissionUtil.checkAndRequestPermissionForResult(this, Manifest.permission.READ_EXTERNAL_STORAGE, PermissionUtil.REQ_CODE_PERMISSION_ADD_ATTACHMENT)) { //TS: jin.dong 2015-12-17 EMAIL BUGFIX_1170083 MOD Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); i.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); i.setType(type);//w w w . j av a2s . c o m startActivityForResult(Intent.createChooser(i, getText(R.string.select_attachment_type)), RESULT_PICK_ATTACHMENT); } //TS: zheng.zou 2015-11-30 EMAIL TASK_869664 ADD_E }
From source file:com.codename1.impl.android.AndroidImplementation.java
public void openGallery(final ActionListener response, int type) { if (!isGalleryTypeSupported(type)) { throw new IllegalArgumentException("Gallery type " + type + " not supported on this platform."); }//w ww . j a v a 2s. c o m if (getActivity() == null) { throw new RuntimeException("Cannot open galery in background mode"); } if (!checkForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, "This is required to browse the photos")) { return; } if (editInProgress()) { stopEditing(true); } final boolean multi; switch (type) { case Display.GALLERY_ALL_MULTI: multi = true; type = Display.GALLERY_ALL; break; case Display.GALLERY_VIDEO_MULTI: multi = true; type = Display.GALLERY_VIDEO; break; case Display.GALLERY_IMAGE_MULTI: multi = true; type = Display.GALLERY_IMAGE; break; case -9998: multi = true; type = -9999; break; default: multi = false; } callback = new EventDispatcher(); callback.addListener(response); Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI); if (multi) { galleryIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); } if (type == Display.GALLERY_VIDEO) { galleryIntent.setType("video/*"); } else if (type == Display.GALLERY_IMAGE) { galleryIntent.setType("image/*"); } else if (type == Display.GALLERY_ALL) { galleryIntent.setType("image/* video/*"); } else if (type == -9999) { galleryIntent = new Intent(); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { galleryIntent.setAction(Intent.ACTION_OPEN_DOCUMENT); } else { galleryIntent.setAction(Intent.ACTION_GET_CONTENT); } galleryIntent.addCategory(Intent.CATEGORY_OPENABLE); // set MIME type for image galleryIntent.setType("*/*"); galleryIntent.putExtra(Intent.EXTRA_MIME_TYPES, Display.getInstance().getProperty("android.openGallery.accept", "*/*").split(",")); } else { galleryIntent.setType("*/*"); } this.getActivity().startActivityForResult(galleryIntent, multi ? OPEN_GALLERY_MULTI : OPEN_GALLERY); }
From source file:org.telegram.ui.PassportActivity.java
private void processSelectedAttach(int which) { if (which == attach_photo) { if (Build.VERSION.SDK_INT >= 23 && getParentActivity() .checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { getParentActivity().requestPermissions(new String[] { Manifest.permission.CAMERA }, 19); return; }/*from www . j av a2s. c o m*/ try { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File image = AndroidUtilities.generatePicturePath(); if (image != null) { if (Build.VERSION.SDK_INT >= 24) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile( getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", image)); takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image)); } currentPicturePath = image.getAbsolutePath(); } startActivityForResult(takePictureIntent, 0); } catch (Exception e) { FileLog.e(e); } } else if (which == attach_gallery) { if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission( Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { getParentActivity().requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, 4); return; } PhotoAlbumPickerActivity fragment = new PhotoAlbumPickerActivity(0, false, false, null); fragment.setCurrentAccount(currentAccount); fragment.setMaxSelectedPhotos(getMaxSelectedDocuments()); fragment.setAllowSearchImages(false); fragment.setDelegate(new PhotoAlbumPickerActivity.PhotoAlbumPickerActivityDelegate() { @Override public void didSelectPhotos(ArrayList<SendMessagesHelper.SendingMediaInfo> photos) { processSelectedFiles(photos); } @Override public void startPhotoSelectActivity() { try { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, 1); } catch (Exception e) { FileLog.e(e); } } }); presentFragment(fragment); } else if (which == attach_document) { if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission( Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { getParentActivity().requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, 4); return; } DocumentSelectActivity fragment = new DocumentSelectActivity(false); fragment.setCurrentAccount(currentAccount); fragment.setCanSelectOnlyImageFiles(true); fragment.setMaxSelectedFiles(getMaxSelectedDocuments()); fragment.setDelegate(new DocumentSelectActivity.DocumentSelectActivityDelegate() { @Override public void didSelectFiles(DocumentSelectActivity activity, ArrayList<String> files) { activity.finishFragment(); ArrayList<SendMessagesHelper.SendingMediaInfo> arrayList = new ArrayList<>(); for (int a = 0, count = files.size(); a < count; a++) { SendMessagesHelper.SendingMediaInfo info = new SendMessagesHelper.SendingMediaInfo(); info.path = files.get(a); arrayList.add(info); } processSelectedFiles(arrayList); } @Override public void startDocumentSelectActivity() { try { Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT); if (Build.VERSION.SDK_INT >= 18) { photoPickerIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); } photoPickerIntent.setType("*/*"); startActivityForResult(photoPickerIntent, 21); } catch (Exception e) { FileLog.e(e); } } }); presentFragment(fragment); } }