List of usage examples for android.content Intent FLAG_GRANT_READ_URI_PERMISSION
int FLAG_GRANT_READ_URI_PERMISSION
To view the source code for android.content Intent FLAG_GRANT_READ_URI_PERMISSION.
Click Source Link
From source file:kr.wdream.ui.MediaActivity.java
private void onItemClick(int index, View view, MessageObject message, int a) { if (message == null) { return;//from w w w . ja v a 2 s.c om } if (actionBar.isActionModeShowed()) { int loadIndex = message.getDialogId() == dialog_id ? 0 : 1; if (selectedFiles[loadIndex].containsKey(message.getId())) { selectedFiles[loadIndex].remove(message.getId()); if (!message.canDeleteMessage(null)) { cantDeleteMessagesCount--; } } else { selectedFiles[loadIndex].put(message.getId(), message); if (!message.canDeleteMessage(null)) { cantDeleteMessagesCount++; } } if (selectedFiles[0].isEmpty() && selectedFiles[1].isEmpty()) { actionBar.hideActionMode(); } else { selectedMessagesCountTextView.setNumber(selectedFiles[0].size() + selectedFiles[1].size(), true); } actionBar.createActionMode().getItem(delete) .setVisibility(cantDeleteMessagesCount == 0 ? View.VISIBLE : View.GONE); scrolling = false; if (view instanceof SharedDocumentCell) { ((SharedDocumentCell) view).setChecked(selectedFiles[loadIndex].containsKey(message.getId()), true); } else if (view instanceof SharedPhotoVideoCell) { ((SharedPhotoVideoCell) view).setChecked(a, selectedFiles[loadIndex].containsKey(message.getId()), true); } else if (view instanceof SharedLinkCell) { ((SharedLinkCell) view).setChecked(selectedFiles[loadIndex].containsKey(message.getId()), true); } } else { if (selectedMode == 0) { PhotoViewer.getInstance().setParentActivity(getParentActivity()); PhotoViewer.getInstance().openPhoto(sharedMediaData[selectedMode].messages, index, dialog_id, mergeDialogId, this); } else if (selectedMode == 1 || selectedMode == 4) { if (view instanceof SharedDocumentCell) { SharedDocumentCell cell = (SharedDocumentCell) view; if (cell.isLoaded()) { if (message.isMusic()) { if (MediaController.getInstance().setPlaylist(sharedMediaData[selectedMode].messages, message)) { return; } } File f = null; String fileName = message.messageOwner.media != null ? FileLoader.getAttachFileName(message.getDocument()) : ""; if (message.messageOwner.attachPath != null && message.messageOwner.attachPath.length() != 0) { f = new File(message.messageOwner.attachPath); } if (f == null || f != null && !f.exists()) { f = FileLoader.getPathToMessage(message.messageOwner); } if (f != null && f.exists()) { String realMimeType = null; try { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); MimeTypeMap myMime = MimeTypeMap.getSingleton(); int idx = fileName.lastIndexOf('.'); if (idx != -1) { String ext = fileName.substring(idx + 1); realMimeType = myMime.getMimeTypeFromExtension(ext.toLowerCase()); if (realMimeType == null) { realMimeType = message.getDocument().mime_type; if (realMimeType == null || realMimeType.length() == 0) { realMimeType = null; } } } if (Build.VERSION.SDK_INT >= 24) { intent.setDataAndType( FileProvider.getUriForFile(getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", f), realMimeType != null ? realMimeType : "text/plain"); } else { intent.setDataAndType(Uri.fromFile(f), realMimeType != null ? realMimeType : "text/plain"); } if (realMimeType != null) { try { getParentActivity().startActivityForResult(intent, 500); } catch (Exception e) { if (Build.VERSION.SDK_INT >= 24) { intent.setDataAndType( FileProvider.getUriForFile(getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", f), "text/plain"); } else { intent.setDataAndType(Uri.fromFile(f), "text/plain"); } getParentActivity().startActivityForResult(intent, 500); } } else { getParentActivity().startActivityForResult(intent, 500); } } catch (Exception e) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName)); builder.setPositiveButton( LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK), null); builder.setMessage(LocaleController.formatString("NoHandleAppInstalled", kr.wdream.storyshop.R.string.NoHandleAppInstalled, message.getDocument().mime_type)); showDialog(builder.create()); } } } else if (!cell.isLoading()) { FileLoader.getInstance().loadFile(cell.getMessage().getDocument(), false, false); cell.updateFileExistIcon(); } else { FileLoader.getInstance().cancelLoadFile(cell.getMessage().getDocument()); cell.updateFileExistIcon(); } } } else if (selectedMode == 3) { try { TLRPC.WebPage webPage = message.messageOwner.media.webpage; String link = null; if (webPage != null && !(webPage instanceof TLRPC.TL_webPageEmpty)) { if (Build.VERSION.SDK_INT >= 16 && webPage.embed_url != null && webPage.embed_url.length() != 0) { openWebView(webPage); return; } else { link = webPage.url; } } if (link == null) { link = ((SharedLinkCell) view).getLink(0); } if (link != null) { Browser.openUrl(getParentActivity(), link); } } catch (Exception e) { FileLog.e("tmessages", e); } } } }
From source file:org.getlantern.firetweet.util.Utils.java
public static Intent createStatusShareIntent(final Context context, final ParcelableStatus status) { final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, getStatusShareSubject(context, status)); intent.putExtra(Intent.EXTRA_TEXT, getStatusShareText(context, status)); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); return intent; }
From source file:com.ferdi2005.secondgram.AndroidUtilities.java
public static void openForView(MessageObject message, Activity activity) throws Exception { File f = null;// w w w . ja v a 2 s. com String fileName = message.getFileName(); if (message.messageOwner.attachPath != null && message.messageOwner.attachPath.length() != 0) { f = new File(message.messageOwner.attachPath); } if (f == null || !f.exists()) { f = FileLoader.getPathToMessage(message.messageOwner); } if (f != null && f.exists()) { String realMimeType = null; Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); MimeTypeMap myMime = MimeTypeMap.getSingleton(); int idx = fileName.lastIndexOf('.'); if (idx != -1) { String ext = fileName.substring(idx + 1); realMimeType = myMime.getMimeTypeFromExtension(ext.toLowerCase()); if (realMimeType == null) { if (message.type == 9 || message.type == 0) { realMimeType = message.getDocument().mime_type; } if (realMimeType == null || realMimeType.length() == 0) { realMimeType = null; } } } if (Build.VERSION.SDK_INT >= 24) { intent.setDataAndType( FileProvider.getUriForFile(activity, BuildConfig.APPLICATION_ID + ".provider", f), realMimeType != null ? realMimeType : "text/plain"); } else { intent.setDataAndType(Uri.fromFile(f), realMimeType != null ? realMimeType : "text/plain"); } if (realMimeType != null) { try { activity.startActivityForResult(intent, 500); } catch (Exception e) { if (Build.VERSION.SDK_INT >= 24) { intent.setDataAndType( FileProvider.getUriForFile(activity, BuildConfig.APPLICATION_ID + ".provider", f), "text/plain"); } else { intent.setDataAndType(Uri.fromFile(f), "text/plain"); } activity.startActivityForResult(intent, 500); } } else { activity.startActivityForResult(intent, 500); } } }
From source file:com.ferdi2005.secondgram.AndroidUtilities.java
public static void openForView(TLObject media, Activity activity) throws Exception { if (media == null || activity == null) { return;//from w w w. j a va 2 s . co m } String fileName = FileLoader.getAttachFileName(media); File f = FileLoader.getPathToAttach(media, true); if (f != null && f.exists()) { String realMimeType = null; Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); MimeTypeMap myMime = MimeTypeMap.getSingleton(); int idx = fileName.lastIndexOf('.'); if (idx != -1) { String ext = fileName.substring(idx + 1); realMimeType = myMime.getMimeTypeFromExtension(ext.toLowerCase()); if (realMimeType == null) { if (media instanceof TLRPC.TL_document) { realMimeType = ((TLRPC.TL_document) media).mime_type; } if (realMimeType == null || realMimeType.length() == 0) { realMimeType = null; } } } if (Build.VERSION.SDK_INT >= 24) { intent.setDataAndType( FileProvider.getUriForFile(activity, BuildConfig.APPLICATION_ID + ".provider", f), realMimeType != null ? realMimeType : "text/plain"); } else { intent.setDataAndType(Uri.fromFile(f), realMimeType != null ? realMimeType : "text/plain"); } if (realMimeType != null) { try { activity.startActivityForResult(intent, 500); } catch (Exception e) { if (Build.VERSION.SDK_INT >= 24) { intent.setDataAndType( FileProvider.getUriForFile(activity, BuildConfig.APPLICATION_ID + ".provider", f), "text/plain"); } else { intent.setDataAndType(Uri.fromFile(f), "text/plain"); } activity.startActivityForResult(intent, 500); } } else { activity.startActivityForResult(intent, 500); } } }
From source file:com.amaze.filemanager.activities.MainActivity.java
protected void onActivityResult(int requestCode, int responseCode, Intent intent) { if (requestCode == RC_SIGN_IN && !mGoogleApiKey && mGoogleApiClient != null) { new Thread(new Runnable() { @Override/*from w w w. j a v a 2s . c o m*/ public void run() { mIntentInProgress = false; mGoogleApiKey = true; // !mGoogleApiClient.isConnecting if (mGoogleApiClient.isConnecting()) { mGoogleApiClient.connect(); } else mGoogleApiClient.disconnect(); } }).run(); } else if (requestCode == image_selector_request_code) { if (Sp != null && intent != null && intent.getData() != null) { if (Build.VERSION.SDK_INT >= 19) getContentResolver().takePersistableUriPermission(intent.getData(), Intent.FLAG_GRANT_READ_URI_PERMISSION); Sp.edit().putString("drawer_header_path", intent.getData().toString()).commit(); setDrawerHeaderBackground(); } } else if (requestCode == 3) { String p = Sp.getString("URI", null); Uri oldUri = null; if (p != null) oldUri = Uri.parse(p); Uri treeUri = null; if (responseCode == Activity.RESULT_OK) { // Get Uri from Storage Access Framework. treeUri = intent.getData(); // Persist URI - this is required for verification of writability. if (treeUri != null) Sp.edit().putString("URI", treeUri.toString()).commit(); } // If not confirmed SAF, or if still not writable, then revert settings. if (responseCode != Activity.RESULT_OK) { /* DialogUtil.displayError(getActivity(), R.string.message_dialog_cannot_write_to_folder_saf, false, currentFolder);||!FileUtil.isWritableNormalOrSaf(currentFolder) */ if (treeUri != null) Sp.edit().putString("URI", oldUri.toString()).commit(); return; } // After confirmation, update stored value of folder. // Persist access permissions. final int takeFlags = intent.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); getContentResolver().takePersistableUriPermission(treeUri, takeFlags); switch (operation) { case DataUtils.DELETE://deletion new DeleteTask(null, mainActivity).execute((oparrayList)); break; case DataUtils.COPY://copying Intent intent1 = new Intent(con, CopyService.class); intent1.putExtra("FILE_PATHS", (oparrayList)); intent1.putExtra("COPY_DIRECTORY", oppathe); startService(intent1); break; case DataUtils.MOVE://moving new MoveFiles((oparrayList), ((Main) getFragment().getTab()), ((Main) getFragment().getTab()).getActivity(), 0) .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, path); break; case DataUtils.NEW_FOLDER://mkdir Main ma1 = ((Main) getFragment().getTab()); mainActivityHelper.mkDir(RootHelper.generateBaseFile(new File(oppathe), true), ma1); break; case DataUtils.RENAME: mainActivityHelper.rename(HFile.LOCAL_MODE, (oppathe), (oppathe1), mainActivity, rootmode); Main ma2 = ((Main) getFragment().getTab()); ma2.updateList(); break; case DataUtils.NEW_FILE: Main ma3 = ((Main) getFragment().getTab()); mainActivityHelper.mkFile(new HFile(HFile.LOCAL_MODE, oppathe), ma3); break; case DataUtils.EXTRACT: mainActivityHelper.extractFile(new File(oppathe)); break; case DataUtils.COMPRESS: mainActivityHelper.compressFiles(new File(oppathe), oparrayList); } operation = -1; } }
From source file:com.filemanager.free.activities.MainActivity.java
protected void onActivityResult(int requestCode, int responseCode, Intent intent) { if (requestCode == RC_SIGN_IN && !mGoogleApiKey && mGoogleApiClient != null) { new Thread(new Runnable() { @Override//from ww w. ja v a2s . c o m public void run() { mIntentInProgress = false; mGoogleApiKey = true; // !mGoogleApiClient.isConnecting if (mGoogleApiClient.isConnecting()) { mGoogleApiClient.connect(); } else mGoogleApiClient.disconnect(); } }).run(); } else if (requestCode == image_selector_request_code) { if (Sp != null && intent != null && intent.getData() != null) { if (Build.VERSION.SDK_INT >= 19) { getContentResolver().takePersistableUriPermission(intent.getData(), Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { con.getApplicationContext().grantUriPermission(BuildConfig.APPLICATION_ID, intent.getData(), Intent.FLAG_GRANT_READ_URI_PERMISSION); } Sp.edit().putString("drawer_header_path", intent.getData().toString()).commit(); setDrawerHeaderBackground(); } } else if (requestCode == 3) { String p = Sp.getString("URI", null); Uri oldUri = null; if (p != null) oldUri = Uri.parse(p); Uri treeUri = null; if (responseCode == Activity.RESULT_OK) { // Get Uri from Storage Access Framework. treeUri = intent.getData(); // Persist URI - this is required for verification of writability. if (treeUri != null) { Sp.edit().putString("URI", treeUri.toString()).commit(); } } // If not confirmed SAF, or if still not writable, then revert settings. if (responseCode != Activity.RESULT_OK) { /* DialogUtil.displayError(getActivity(), R.string.message_dialog_cannot_write_to_folder_saf, false, currentFolder);||!FileUtil.isWritableNormalOrSaf(currentFolder) */ if (treeUri != null) { Sp.edit().putString("URI", oldUri.toString()).commit(); } return; } // After confirmation, update stored value of folder. // Persist access permissions. int takeFlags = intent.getFlags(); takeFlags &= (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (treeUri != null) { getContentResolver().takePersistableUriPermission(treeUri, takeFlags); } } else { if (treeUri != null) { con.getApplicationContext().grantUriPermission(BuildConfig.APPLICATION_ID, treeUri, takeFlags); } } switch (operation) { case DataUtils.DELETE://deletion new DeleteTask(null, mainActivity).execute((oparrayList)); break; case DataUtils.COPY://copying Intent intent1 = new Intent(con, CopyService.class); intent1.putExtra("FILE_PATHS", (oparrayList)); intent1.putExtra("COPY_DIRECTORY", oppathe); startService(intent1); break; case DataUtils.MOVE://moving new MoveFiles((oparrayList), ((Main) getFragment().getTab()), ((Main) getFragment().getTab()).getActivity(), 0) .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, path); break; case DataUtils.NEW_FOLDER://mkdir Main ma1 = ((Main) getFragment().getTab()); mainActivityHelper.mkDir(RootHelper.generateBaseFile(new File(oppathe), true), ma1); break; case DataUtils.RENAME: mainActivityHelper.rename(HFile.LOCAL_MODE, (oppathe), (oppathe1), mainActivity, rootmode); Main ma2 = ((Main) getFragment().getTab()); ma2.updateList(); break; case DataUtils.NEW_FILE: Main ma3 = ((Main) getFragment().getTab()); mainActivityHelper.mkFile(new HFile(HFile.LOCAL_MODE, oppathe), ma3); break; case DataUtils.EXTRACT: mainActivityHelper.extractFile(new File(oppathe)); break; case DataUtils.COMPRESS: mainActivityHelper.compressFiles(new File(oppathe), oparrayList); } operation = -1; } }
From source file:com.android.email.activity.MessageView.java
/** * Back in the UI thread, handle the final steps of downloading an attachment (view or save). * * @param attachmentId the attachment that was just downloaded *///from w ww . j av a 2s.co m private void doFinishLoadAttachment(long attachmentId) { // If the result does't line up, just skip it - we handle one at a time. if (attachmentId != mLoadAttachmentId) { return; } Attachment attachment = Attachment.restoreAttachmentWithId(MessageView.this, attachmentId); Uri attachmentUri = AttachmentProvider.getAttachmentUri(mAccountId, attachment.mId); Uri contentUri = AttachmentProvider.resolveAttachmentIdToContentUri(getContentResolver(), attachmentUri); if (mLoadAttachmentSave) { try { File file = createUniqueFile(Environment.getExternalStorageDirectory(), attachment.mFileName); InputStream in = getContentResolver().openInputStream(contentUri); OutputStream out = new FileOutputStream(file); IOUtils.copy(in, out); out.flush(); out.close(); in.close(); Toast.makeText(MessageView.this, String.format(getString(R.string.message_view_status_attachment_saved), file.getName()), Toast.LENGTH_LONG).show(); new MediaScannerNotifier(this, file, mHandler); } catch (IOException ioe) { Toast.makeText(MessageView.this, getString(R.string.message_view_status_attachment_not_saved), Toast.LENGTH_LONG).show(); } } else { try { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(contentUri); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); startActivity(intent); } catch (ActivityNotFoundException e) { mHandler.attachmentViewError(); // TODO: Add a proper warning message (and lots of upstream cleanup to prevent // it from happening) in the next release. } } }
From source file:com.android.gallery3d.app.PhotoPage.java
@Override protected boolean onItemSelected(MenuItem item) { if (mModel == null) return true; refreshHidingMessage();/*from w w w .ja v a2 s . c o m*/ MediaItem current = mModel.getMediaItem(0); // This is a shield for monkey when it clicks the action bar // menu when transitioning from filmstrip to camera if (current instanceof SnailItem) return true; // TODO: We should check the current photo against the MediaItem // that the menu was initially created for. We need to fix this // after PhotoPage being refactored. if (current == null) { // item is not ready, ignore return true; } int currentIndex = mModel.getCurrentIndex(); Path path = current.getPath(); DataManager manager = mActivity.getDataManager(); int action = item.getItemId(); /// M: [BUG.ADD] show toast before PhotoDataAdapter finishing loading to avoid JE @{ if (action != android.R.id.home && !mLoadingFinished && mSetPathString != null) { Toast.makeText(mActivity, mActivity.getString(R.string.please_wait), Toast.LENGTH_SHORT).show(); return true; } /// @} String confirmMsg = null; switch (action) { case android.R.id.home: { onUpPressed(); return true; } case R.id.action_slideshow: { Bundle data = new Bundle(); /// M: [BUG.MODIFY] fix bug: slideshow doesn't play again // when finish playing the last picture @{ String mediaSetPath = mMediaSet.getPath().toString(); if (mSnailSetPath != null) { mediaSetPath = mediaSetPath.replace(mSnailSetPath + ",", ""); Log.i(TAG, "<onItemSelected> action_slideshow | mediaSetPath: " + mediaSetPath); } /*data.putString(SlideshowPage.KEY_SET_PATH, mMediaSet.getPath().toString());*/ data.putString(SlideshowPage.KEY_SET_PATH, mediaSetPath); /// @} data.putString(SlideshowPage.KEY_ITEM_PATH, path.toString()); /// M: [BUG.ADD] currentIndex-- if it is in camera folder @{ if (mHasCameraScreennailOrPlaceholder) { currentIndex--; } /// @} data.putInt(SlideshowPage.KEY_PHOTO_INDEX, currentIndex); data.putBoolean(SlideshowPage.KEY_REPEAT, true); mActivity.getStateManager().startStateForResult(SlideshowPage.class, REQUEST_SLIDESHOW, data); return true; } case R.id.action_crop: { /// M: [BUG.ADD] disable cropping photo when file not exists or sdcard is full. @{ File srcFile = new File(current.getFilePath()); if (!srcFile.exists()) { Log.i(TAG, "<onItemSelected> abort cropping photo when not exists!"); return true; } if (!isSpaceEnough(srcFile)) { Log.i(TAG, "<onItemSelected> abort cropping photo when no enough space!"); Toast.makeText(mActivity, mActivity.getString(R.string.storage_not_enough), Toast.LENGTH_SHORT) .show(); return true; } /// @} Activity activity = mActivity; Intent intent = new Intent(CropActivity.CROP_ACTION); intent.setClass(activity, CropActivity.class); intent.setDataAndType(manager.getContentUri(path), current.getMimeType()) .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); activity.startActivityForResult(intent, PicasaSource.isPicasaImage(current) ? REQUEST_CROP_PICASA : REQUEST_CROP); return true; } case R.id.action_trim: { Intent intent = new Intent(mActivity, TrimVideo.class); intent.setData(manager.getContentUri(path)); // We need the file path to wrap this into a RandomAccessFile. intent.putExtra(KEY_MEDIA_ITEM_PATH, current.getFilePath()); /// M: [FEATURE.ADD] SlideVideo@{ if (FeatureConfig.SUPPORT_SLIDE_VIDEO_PLAY) { intent.putExtra(TrimVideo.KEY_COME_FROM_GALLERY, true); } /// @} mActivity.startActivityForResult(intent, REQUEST_TRIM); return true; } case R.id.action_mute: { /// M: [BUG.ADD] disable muting video when file not exists or sdcard is full. @{ File srcFile = new File(current.getFilePath()); if (!srcFile.exists()) { Log.i(TAG, "<onItemSelected> abort muting video when not exists!"); return true; } if (!isSpaceEnough(srcFile)) { Log.i(TAG, "<onItemSelected> abort muting video when no enough space!"); Toast.makeText(mActivity, mActivity.getString(R.string.storage_not_enough), Toast.LENGTH_SHORT) .show(); return true; } /// @} mMuteVideo = new MuteVideo(current.getFilePath(), manager.getContentUri(path), mActivity); mMuteVideo.muteInBackground(); /// M: [FEATURE.ADD] SlideVideo@{ mMuteVideo.setMuteDoneListener(new MuteDoneListener() { public void onMuteDone(Uri uri) { redirectCurrentMedia(uri, false); } }); /// @} return true; } case R.id.action_edit: { /// M: [BUG.ADD] disable editing photo when file not exists or sdcard is full. @{ File srcFile = new File(current.getFilePath()); if (!srcFile.exists()) { Log.i(TAG, "<onItemSelected> abort editing photo when not exists!"); return true; } if (!isSpaceEnough(srcFile)) { Log.i(TAG, "<onItemSelected> abort editing photo when no enough space!"); Toast.makeText(mActivity, mActivity.getString(R.string.storage_not_enough), Toast.LENGTH_SHORT) .show(); return true; } /// @} launchPhotoEditor(); return true; } /// M: [FEATURE.ADD] @{ case R.id.m_action_picture_quality: { Activity activity = (Activity) mActivity; Intent intent = new Intent(PictureQualityActivity.ACTION_PQ); intent.setClass(activity, PictureQualityActivity.class); intent.setData(manager.getContentUri(path)); Bundle pqBundle = new Bundle(); pqBundle.putString("PQUri", manager.getContentUri(path).toString()); pqBundle.putString("PQMineType", current.getMimeType()); pqBundle.putInt("PQViewWidth", mPhotoView.getWidth()); pqBundle.putInt("PQViewHeight", mPhotoView.getHeight()); intent.putExtras(pqBundle); Log.i(TAG, "<onItemSelected>startActivity PQ"); activity.startActivityForResult(intent, REQUEST_PQ); return true; } case R.id.m_action_image_dc: { ImageDC.resetStatus((Context) mActivity); ImageDC.setMenuItemTile(item); path.clearObject(); mActivity.getDataManager().forceRefreshAll(); Log.d(TAG, "< onStateResult > forceRefreshAll~~"); return true; } /// @} case R.id.action_simple_edit: { launchSimpleEditor(); return true; } case R.id.action_details: { if (mShowDetails) { hideDetails(); } else { showDetails(); } return true; } case R.id.print: { mActivity.printSelectedImage(manager.getContentUri(path)); return true; } case R.id.action_delete: confirmMsg = mActivity.getResources().getQuantityString(R.plurals.delete_selection, 1); case R.id.action_setas: case R.id.action_rotate_ccw: case R.id.action_rotate_cw: case R.id.action_show_on_map: mSelectionManager.deSelectAll(); mSelectionManager.toggle(path); mMenuExecutor.onMenuClicked(item, confirmMsg, mConfirmDialogListener); return true; /// M: [FEATURE.ADD] DRM & HotKnot @{ case R.id.m_action_protect_info: Log.d(TAG, "<onItemSelected> ProtectionInfo: do action_protection_info"); DrmHelper.showProtectionInfoDialog((Activity) mActivity, manager.getContentUri(path)); return true; case R.id.action_hotknot: Log.d(TAG, "<onItemSelected> HotKnot: do action_hotknot"); // for continuous shot, may share a group image, so getContentUris() Uri[] uris = null; ExtItem extItem = mCurrentPhoto.getExtItem(); if (extItem != null) { uris = extItem.getContentUris(); } if (uris != null) { mActivity.getHotKnot().sendZip(uris); } else { extHotKnot(); } return true; /// @} /// M: [FEATURE.ADD] entry to export as video @{ case R.id.action_export: mAnimatedContentSharer.exportCurrentPhoto(); return true; /// @} /// M: [FEATURE.ADD] Support BlueTooth print feature.@{ case R.id.action_print: mSelectionManager.deSelectAll(); mSelectionManager.toggle(path); mMenuExecutor.onMenuClicked(item, confirmMsg, mConfirmDialogListener); return true; /// @} default: /// M: [FEATURE.ADD] menu extension @{ // return false; return mPhotoView.onOptionsItemSelected(item); /// @} } }
From source file:com.igniva.filemanager.activities.MainActivity.java
protected void onActivityResult(int requestCode, int responseCode, Intent intent) { if (requestCode == RC_SIGN_IN && !mGoogleApiKey && mGoogleApiClient != null) { new Thread(new Runnable() { @Override/* ww w .j a va 2 s . com*/ public void run() { mIntentInProgress = false; mGoogleApiKey = true; // !mGoogleApiClient.isConnecting if (mGoogleApiClient.isConnecting()) { mGoogleApiClient.connect(); } else mGoogleApiClient.disconnect(); } }).run(); } else if (requestCode == image_selector_request_code) { if (Sp != null && intent != null && intent.getData() != null) { if (Build.VERSION.SDK_INT >= 19) getContentResolver().takePersistableUriPermission(intent.getData(), Intent.FLAG_GRANT_READ_URI_PERMISSION); Sp.edit().putString("drawer_header_path", intent.getData().toString()).commit(); setDrawerHeaderBackground(); } } else if (requestCode == 3) { String p = Sp.getString("URI", null); Uri oldUri = p != null ? Uri.parse(p) : null; Uri treeUri = null; if (responseCode == Activity.RESULT_OK) { // Get Uri from Storage Access Framework. treeUri = intent.getData(); // Persist URI - this is required for verification of writability. if (treeUri != null) Sp.edit().putString("URI", treeUri.toString()).commit(); } // If not confirmed SAF, or if still not writable, then revert settings. if (responseCode != Activity.RESULT_OK) { /* DialogUtil.displayError(getActivity(), R.string.message_dialog_cannot_write_to_folder_saf, false, currentFolder);||!FileUtil.isWritableNormalOrSaf(currentFolder) */ if (treeUri != null) Sp.edit().putString("URI", oldUri.toString()).commit(); return; } // After confirmation, update stored value of folder. // Persist access permissions. final int takeFlags = intent.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); getContentResolver().takePersistableUriPermission(treeUri, takeFlags); switch (operation) { case DataUtils.DELETE://deletion new DeleteTask(null, mainActivity).execute((oparrayList)); break; case DataUtils.COPY://copying Intent intent1 = new Intent(con, CopyService.class); intent1.putExtra("FILE_PATHS", (oparrayList)); intent1.putExtra("COPY_DIRECTORY", oppathe); startService(intent1); break; case DataUtils.MOVE://moving new MoveFiles((oparrayList), ((Main) getFragment().getTab()), ((Main) getFragment().getTab()).getActivity(), 0) .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, path); break; case DataUtils.NEW_FOLDER://mkdir Main ma1 = ((Main) getFragment().getTab()); mainActivityHelper.mkDir(RootHelper.generateBaseFile(new File(oppathe), true), ma1); break; case DataUtils.RENAME: mainActivityHelper.rename(HFile.LOCAL_MODE, (oppathe), (oppathe1), mainActivity, BaseActivity.rootMode); Main ma2 = ((Main) getFragment().getTab()); ma2.updateList(); break; case DataUtils.NEW_FILE: Main ma3 = ((Main) getFragment().getTab()); mainActivityHelper.mkFile(new HFile(HFile.LOCAL_MODE, oppathe), ma3); break; case DataUtils.EXTRACT: mainActivityHelper.extractFile(new File(oppathe)); break; case DataUtils.COMPRESS: mainActivityHelper.compressFiles(new File(oppathe), oparrayList); } operation = -1; } }