List of usage examples for android.content Intent setDataAndType
public @NonNull Intent setDataAndType(@Nullable Uri data, @Nullable String type)
From source file:com.remobile.camera.CameraLauncher.java
/** * Brings up the UI to perform crop on passed image URI * * @param picUri//from w ww . j a va 2s . co m */ private void performCrop(Uri picUri, int destType, Intent cameraIntent) { try { Intent cropIntent = new Intent("com.android.camera.action.CROP"); // indicate image type and Uri cropIntent.setDataAndType(picUri, "image/*"); // set crop properties cropIntent.putExtra("crop", "true"); // indicate output X and Y if (targetWidth > 0) { cropIntent.putExtra("outputX", targetWidth); } if (targetHeight > 0) { cropIntent.putExtra("outputY", targetHeight); } if (targetHeight > 0 && targetWidth > 0 && targetWidth == targetHeight) { cropIntent.putExtra("aspectX", 1); cropIntent.putExtra("aspectY", 1); } // create new file handle to get full resolution crop croppedUri = Uri.fromFile(new File(getTempDirectoryPath(), System.currentTimeMillis() + ".jpg")); cropIntent.putExtra("output", croppedUri); // start the activity - we handle returning in onActivityResult if (this.cordova != null) { this.cordova.startActivityForResult((CordovaPlugin) this, cropIntent, CROP_CAMERA + destType); } } catch (ActivityNotFoundException anfe) { Log.e(LOG_TAG, "Crop operation not supported on this device"); try { processResultFromCamera(destType, cameraIntent); } catch (IOException e) { e.printStackTrace(); Log.e(LOG_TAG, "Unable to write to file"); } } }
From source file:com.bitants.wally.activities.ImageDetailsActivity.java
private void setImageAsWallpaperPicker(Uri path) { Intent intent = new Intent(Intent.ACTION_ATTACH_DATA); intent.setType("image/*"); MimeTypeMap map = MimeTypeMap.getSingleton(); String mimeType = map.getMimeTypeFromExtension("png"); intent.setDataAndType(path, mimeType); intent.putExtra("mimeType", mimeType); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(Intent.createChooser(intent, getString(R.string.action_set_as))); }
From source file:com.klinker.android.twitter.activities.tweet_viewer.TweetPager.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: onBackPressed();// w w w . j a va 2 s. c om return true; case R.id.menu_delete_tweet: new DeleteTweet().execute(); getSharedPreferences("com.klinker.android.twitter_world_preferences", 0).edit() .putBoolean("just_muted", true).commit(); return true; case R.id.menu_share: String text1 = tweet; text1 = "@" + screenName + ": " + text1 + "\n\n" + "https://twitter.com/" + screenName + "/status/" + tweetId; Log.v("my_text_on_share", text1); Intent share = new Intent(Intent.ACTION_SEND); share.setType("text/plain"); share.putExtra(Intent.EXTRA_TEXT, text1); startActivity(share); return true; case R.id.menu_copy_text: ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("tweet_text", tweet); clipboard.setPrimaryClip(clip); return true; /*case R.id.menu_open_web: Uri weburi; try { weburi = Uri.parse(otherLinks[0]); } catch (Exception e) { weburi = Uri.parse(webpage); } Intent launchBrowser = new Intent(Intent.ACTION_VIEW, weburi); startActivity(launchBrowser); return true;*/ case R.id.menu_save_image: new Thread(new Runnable() { @Override public void run() { Looper.prepare(); try { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_stat_icon) .setTicker(getResources().getString(R.string.downloading) + "...") .setContentTitle(getResources().getString(R.string.app_name)) .setContentText(getResources().getString(R.string.saving_picture) + "...") .setProgress(100, 100, true).setLargeIcon(BitmapFactory .decodeResource(context.getResources(), R.drawable.ic_action_save)); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(6, mBuilder.build()); String url = webpage; if (webpage.contains("insta")) { url = url.substring(0, url.length() - 1) + "l"; } URL mUrl = new URL(url); Bitmap bitmap = BitmapFactory.decodeStream(mUrl.openConnection().getInputStream()); Random generator = new Random(); int n = 1000000; n = generator.nextInt(n); String fname = "Image-" + n; Uri uri = IOUtils.saveImage(bitmap, fname, context); Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(uri, "image/*"); PendingIntent pending = PendingIntent.getActivity(context, 91, intent, 0); mBuilder = new NotificationCompat.Builder(context).setContentIntent(pending) .setSmallIcon(R.drawable.ic_stat_icon) .setTicker(getResources().getString(R.string.saved_picture) + "...") .setContentTitle(getResources().getString(R.string.app_name)) .setContentText(getResources().getString(R.string.saved_picture) + "!") .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_action_save)); mNotificationManager.notify(6, mBuilder.build()); } catch (Exception e) { e.printStackTrace(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_stat_icon) .setTicker(getResources().getString(R.string.error) + "...") .setContentTitle(getResources().getString(R.string.app_name)) .setContentText(getResources().getString(R.string.error) + "...") .setProgress(100, 100, true).setLargeIcon(BitmapFactory .decodeResource(context.getResources(), R.drawable.ic_action_save)); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(6, mBuilder.build()); } } }).start(); return true; case R.id.menu_quote: String text = tweet; switch (settings.quoteStyle) { case AppSettings.QUOTE_STYLE_TWITTER: text = " " + "https://twitter.com/" + screenName + "/status/" + tweetId; break; case AppSettings.QUOTE_STYLE_TALON: text = "\"@" + screenName + ": " + text + "\" "; break; case AppSettings.QUOTE_STYLE_RT: text = " RT @" + screenName + ": " + text; break; } Intent quote = new Intent(context, ComposeActivity.class); quote.putExtra("user", text); quote.putExtra("id", tweetId); startActivity(quote); return true; case R.id.menu_spam: new MarkSpam().execute(); getSharedPreferences("com.klinker.android.twitter_world_preferences", 0).edit() .putBoolean("just_muted", true).commit(); return super.onOptionsItemSelected(item); /*case R.id.menu_mute_hashtags: if (!hashtags[0].equals("")) { ArrayList<String> tags = new ArrayList<String>(); if (hashtags != null) { for (String s : hashtags) { if (!s.equals("")) { tags.add("#" + s); } } } final CharSequence[] fItems = new CharSequence[tags.size()]; for (int i = 0; i < tags.size(); i++) { fItems[i] = tags.get(i); } final SharedPreferences sharedPreferences = context.getSharedPreferences("com.klinker.android.twitter_world_preferences", 0); if (fItems.length > 1) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setItems(fItems, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { String touched = fItems[item] + ""; Toast.makeText(context, getResources().getString(R.string.muted) + " " + touched, Toast.LENGTH_SHORT).show(); touched = touched.replace("#", "") + " "; String current = sharedPreferences.getString("muted_hashtags", ""); sharedPreferences.edit().putString("muted_hashtags", current + touched).commit(); sharedPreferences.edit().putBoolean("refresh_me", true).commit(); dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); } else { String touched = fItems[0] + ""; Toast.makeText(context, getResources().getString(R.string.muted) + " " + touched, Toast.LENGTH_SHORT).show(); touched = touched.replace("#", "") + " "; String current = sharedPreferences.getString("muted_hashtags", ""); sharedPreferences.edit().putString("muted_hashtags", current + touched).commit(); sharedPreferences.edit().putBoolean("refresh_me", true).commit(); } } else { Toast.makeText(context, getResources().getString(R.string.no_hashtags), Toast.LENGTH_SHORT).show(); } PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("just_muted", true).commit(); return super.onOptionsItemSelected(item); case R.id.menu_share_links: if (!otherLinks[0].equals("")) { ArrayList<String> urls = new ArrayList<String>(); if (otherLinks != null) { for (String s : otherLinks) { if (!s.equals("")) { urls.add(s); } } } final CharSequence[] fItems = new CharSequence[urls.size()]; for (int i = 0; i < urls.size(); i++) { fItems[i] = urls.get(i); } if (fItems.length > 1) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setItems(fItems, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { String touched = fItems[item] + ""; Intent intent=new Intent(android.content.Intent.ACTION_SEND); intent.setType("text/plain"); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); intent.putExtra(Intent.EXTRA_TEXT, touched); context.startActivity(Intent.createChooser(intent, context.getResources().getString(R.string.menu_share))); dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); } else { String touched = fItems[0] + ""; Intent intent=new Intent(android.content.Intent.ACTION_SEND); intent.setType("text/plain"); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); intent.putExtra(Intent.EXTRA_TEXT, touched); context.startActivity(Intent.createChooser(intent, context.getResources().getString(R.string.menu_share))); } } else { Toast.makeText(context, getResources().getString(R.string.no_links), Toast.LENGTH_SHORT).show(); } return super.onOptionsItemSelected(item);*/ case R.id.menu_translate: try { String url = settings.translateURL + tweet; Uri uri = Uri.parse(url); Intent browser = new Intent(Intent.ACTION_VIEW, uri); browser.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(browser); } catch (Exception e) { } return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.klinker.android.twitter.ui.tweet_viewer.TweetPager.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: onBackPressed();/*from w w w . j a va 2s.co m*/ return true; case R.id.menu_delete_tweet: new DeleteTweet().execute(); getSharedPreferences("com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE).edit() .putBoolean("just_muted", true).commit(); return true; case R.id.menu_share: String text1 = tweet; text1 = "@" + screenName + ": " + text1 + "\n\n" + "https://twitter.com/" + screenName + "/status/" + tweetId; Log.v("my_text_on_share", text1); Intent share = new Intent(Intent.ACTION_SEND); share.setType("text/plain"); share.putExtra(Intent.EXTRA_TEXT, text1); startActivity(share); return true; case R.id.menu_copy_text: ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("tweet_text", tweet); clipboard.setPrimaryClip(clip); return true; /*case R.id.menu_open_web: Uri weburi; try { weburi = Uri.parse(otherLinks[0]); } catch (Exception e) { weburi = Uri.parse(webpage); } Intent launchBrowser = new Intent(Intent.ACTION_VIEW, weburi); startActivity(launchBrowser); return true;*/ case R.id.menu_save_image: new Thread(new Runnable() { @Override public void run() { Looper.prepare(); try { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_stat_icon) .setTicker(getResources().getString(R.string.downloading) + "...") .setContentTitle(getResources().getString(R.string.app_name)) .setContentText(getResources().getString(R.string.saving_picture) + "...") .setProgress(100, 100, true).setLargeIcon(BitmapFactory .decodeResource(context.getResources(), R.drawable.ic_action_save)); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(6, mBuilder.build()); String url = webpage; if (webpage.contains("insta")) { url = url.substring(0, url.length() - 1) + "l"; } URL mUrl = new URL(url); Bitmap bitmap = BitmapFactory.decodeStream(mUrl.openConnection().getInputStream()); Random generator = new Random(); int n = 1000000; n = generator.nextInt(n); String fname = "Image-" + n; Uri uri = IOUtils.saveImage(bitmap, fname, context); Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(uri, "image/*"); PendingIntent pending = PendingIntent.getActivity(context, 91, intent, 0); mBuilder = new NotificationCompat.Builder(context).setContentIntent(pending) .setSmallIcon(R.drawable.ic_stat_icon) .setTicker(getResources().getString(R.string.saved_picture) + "...") .setContentTitle(getResources().getString(R.string.app_name)) .setContentText(getResources().getString(R.string.saved_picture) + "!") .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_action_save)); mNotificationManager.notify(6, mBuilder.build()); } catch (Exception e) { e.printStackTrace(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_stat_icon) .setTicker(getResources().getString(R.string.error) + "...") .setContentTitle(getResources().getString(R.string.app_name)) .setContentText(getResources().getString(R.string.error) + "...") .setProgress(100, 100, true).setLargeIcon(BitmapFactory .decodeResource(context.getResources(), R.drawable.ic_action_save)); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(6, mBuilder.build()); } } }).start(); return true; case R.id.menu_quote: String text = tweet; if (!settings.preferRT) { text = "\"@" + screenName + ": " + text + "\" "; } else { text = " RT @" + screenName + ": " + text; } Intent quote = new Intent(context, ComposeActivity.class); quote.putExtra("user", text); quote.putExtra("id", tweetId); startActivity(quote); return true; case R.id.menu_spam: new MarkSpam().execute(); getSharedPreferences("com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE).edit() .putBoolean("just_muted", true).commit(); return super.onOptionsItemSelected(item); /*case R.id.menu_mute_hashtags: if (!hashtags[0].equals("")) { ArrayList<String> tags = new ArrayList<String>(); if (hashtags != null) { for (String s : hashtags) { if (!s.equals("")) { tags.add("#" + s); } } } final CharSequence[] fItems = new CharSequence[tags.size()]; for (int i = 0; i < tags.size(); i++) { fItems[i] = tags.get(i); } final SharedPreferences sharedPreferences = context.getSharedPreferences("com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); if (fItems.length > 1) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setItems(fItems, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { String touched = fItems[item] + ""; Toast.makeText(context, getResources().getString(R.string.muted) + " " + touched, Toast.LENGTH_SHORT).show(); touched = touched.replace("#", "") + " "; String current = sharedPreferences.getString("muted_hashtags", ""); sharedPreferences.edit().putString("muted_hashtags", current + touched).commit(); sharedPreferences.edit().putBoolean("refresh_me", true).commit(); dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); } else { String touched = fItems[0] + ""; Toast.makeText(context, getResources().getString(R.string.muted) + " " + touched, Toast.LENGTH_SHORT).show(); touched = touched.replace("#", "") + " "; String current = sharedPreferences.getString("muted_hashtags", ""); sharedPreferences.edit().putString("muted_hashtags", current + touched).commit(); sharedPreferences.edit().putBoolean("refresh_me", true).commit(); } } else { Toast.makeText(context, getResources().getString(R.string.no_hashtags), Toast.LENGTH_SHORT).show(); } PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("just_muted", true).commit(); return super.onOptionsItemSelected(item); case R.id.menu_share_links: if (!otherLinks[0].equals("")) { ArrayList<String> urls = new ArrayList<String>(); if (otherLinks != null) { for (String s : otherLinks) { if (!s.equals("")) { urls.add(s); } } } final CharSequence[] fItems = new CharSequence[urls.size()]; for (int i = 0; i < urls.size(); i++) { fItems[i] = urls.get(i); } if (fItems.length > 1) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setItems(fItems, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { String touched = fItems[item] + ""; Intent intent=new Intent(android.content.Intent.ACTION_SEND); intent.setType("text/plain"); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); intent.putExtra(Intent.EXTRA_TEXT, touched); context.startActivity(Intent.createChooser(intent, context.getResources().getString(R.string.menu_share))); dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); } else { String touched = fItems[0] + ""; Intent intent=new Intent(android.content.Intent.ACTION_SEND); intent.setType("text/plain"); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); intent.putExtra(Intent.EXTRA_TEXT, touched); context.startActivity(Intent.createChooser(intent, context.getResources().getString(R.string.menu_share))); } } else { Toast.makeText(context, getResources().getString(R.string.no_links), Toast.LENGTH_SHORT).show(); } return super.onOptionsItemSelected(item);*/ case R.id.menu_translate: try { String query = tweet.replaceAll(" ", "+"); String url = "http://translate.google.com/#auto|en|" + tweet; Uri uri = Uri.parse(url); Intent browser = new Intent(Intent.ACTION_VIEW, uri); browser.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(browser); } catch (Exception e) { } return true; default: return super.onOptionsItemSelected(item); } }
From source file:cgeo.geocaching.CacheListActivity.java
private static void startActivityWithAttachment(@NonNull final Context context, @NonNull final PocketQuery pocketQuery) { final Uri uri = pocketQuery.getUri(); final Intent cachesIntent = new Intent(Intent.ACTION_VIEW, uri, context, CacheListActivity.class); cachesIntent.setDataAndType(uri, "application/zip"); cachesIntent.putExtra(Intents.EXTRA_NAME, pocketQuery.getName()); context.startActivity(cachesIntent); }
From source file:com.owncloud.android.ui.fragment.FileDetailFragment.java
@Override public void onClick(View v) { switch (v.getId()) { case R.id.fdDownloadBtn: { FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder(); FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder(); if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) { downloaderBinder.cancel(mAccount, mFile); if (mFile.isDown()) { setButtonsForDown();/* ww w . jav a 2 s. c o m*/ } else { setButtonsForRemote(); } } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile)) { uploaderBinder.cancel(mAccount, mFile); if (!mFile.fileExists()) { // TODO make something better if (getActivity() instanceof FileDisplayActivity) { // double pane FragmentTransaction transaction = getActivity().getSupportFragmentManager() .beginTransaction(); transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null), FTAG); // empty FileDetailFragment transaction.commit(); mContainerActivity.onFileStateChanged(); } else { getActivity().finish(); } } else if (mFile.isDown()) { setButtonsForDown(); } else { setButtonsForRemote(); } } else { mLastRemoteOperation = new SynchronizeFileOperation(mFile, null, mStorageManager, mAccount, true, false, getActivity()); WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getSherlockActivity().getApplicationContext()); mLastRemoteOperation.execute(wc, this, mHandler); // update ui boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; getActivity().showDialog((inDisplayActivity) ? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); setButtonsForTransferring(); // disable button immediately, although the synchronization does not result in a file transference } break; } case R.id.fdKeepInSync: { CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync); mFile.setKeepInSync(cb.isChecked()); mStorageManager.saveFile(mFile); /// register the OCFile instance in the observer service to monitor local updates; /// if necessary, the file is download Intent intent = new Intent(getActivity().getApplicationContext(), FileObserverService.class); intent.putExtra(FileObserverService.KEY_FILE_CMD, (cb.isChecked() ? FileObserverService.CMD_ADD_OBSERVED_FILE : FileObserverService.CMD_DEL_OBSERVED_FILE)); intent.putExtra(FileObserverService.KEY_CMD_ARG_FILE, mFile); intent.putExtra(FileObserverService.KEY_CMD_ARG_ACCOUNT, mAccount); Log.e(TAG, "starting observer service"); getActivity().startService(intent); if (mFile.keepInSync()) { onClick(getView().findViewById(R.id.fdDownloadBtn)); // force an immediate synchronization } break; } case R.id.fdRenameBtn: { EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.rename_dialog_title), mFile.getFileName(), this); dialog.show(getFragmentManager(), "nameeditdialog"); break; } case R.id.fdRemoveBtn: { ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance( R.string.confirmation_remove_alert, new String[] { mFile.getFileName() }, mFile.isDown() ? R.string.confirmation_remove_remote_and_local : R.string.confirmation_remove_remote, mFile.isDown() ? R.string.confirmation_remove_local : -1, R.string.common_cancel); confDialog.setOnConfirmationListener(this); mCurrentDialog = confDialog; mCurrentDialog.show(getFragmentManager(), FTAG_CONFIRMATION); break; } case R.id.fdOpenBtn: { String storagePath = mFile.getStoragePath(); String encodedStoragePath = WebdavUtils.encodePath(storagePath); try { Intent i = new Intent(Intent.ACTION_VIEW); i.setDataAndType(Uri.parse("file://" + encodedStoragePath), mFile.getMimetype()); i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); startActivity(i); } catch (Throwable t) { Log.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + mFile.getMimetype()); boolean toastIt = true; String mimeType = ""; try { Intent i = new Intent(Intent.ACTION_VIEW); mimeType = MimeTypeMap.getSingleton() .getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1)); if (mimeType == null || !mimeType.equals(mFile.getMimetype())) { if (mimeType != null) { i.setDataAndType(Uri.parse("file://" + encodedStoragePath), mimeType); } else { // desperate try i.setDataAndType(Uri.parse("file://" + encodedStoragePath), "*/*"); } i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); startActivity(i); toastIt = false; } } catch (IndexOutOfBoundsException e) { Log.e(TAG, "Trying to find out MIME type of a file without extension: " + storagePath); } catch (ActivityNotFoundException e) { Log.e(TAG, "No activity found to handle: " + storagePath + " with MIME type " + mimeType + " obtained from extension"); } catch (Throwable th) { Log.e(TAG, "Unexpected problem when opening: " + storagePath, th); } finally { if (toastIt) { Toast.makeText(getActivity(), "There is no application to handle file " + mFile.getFileName(), Toast.LENGTH_SHORT) .show(); } } } break; } default: Log.e(TAG, "Incorrect view clicked!"); } /* else if (v.getId() == R.id.fdShareBtn) { Thread t = new Thread(new ShareRunnable(mFile.getRemotePath())); t.start(); }*/ }
From source file:com.ktouch.kdc.launcher4.camera.ui.ReviewDrawer.java
private void editInGallery(final int imageId) { if (imageId > 0) { Intent editIntent = new Intent(Intent.ACTION_EDIT); // Get URI Uri uri = null;//from ww w .j av a2 s . c o m if (Gallery.getCameraMode() == Gallery.CAMERA_MODE_VIDEO) { uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI.buildUpon().appendPath(Integer.toString(imageId)) .build(); } else { uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI.buildUpon().appendPath(Integer.toString(imageId)) .build(); } // Start gallery edit activity editIntent.setDataAndType(uri, "image/*"); editIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Context ctx = getContext(); if (ctx != null) { ctx.startActivity(Intent.createChooser(editIntent, null)); } } }
From source file:com.qiscus.sdk.ui.fragment.QiscusBaseChatFragment.java
@Override public void onFileDownloaded(File file, String mimeType) { Intent intent = new Intent(Intent.ACTION_VIEW); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { intent.setDataAndType(Uri.fromFile(file), mimeType); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } else {//from ww w . j a v a 2 s . co m intent.setDataAndType(FileProvider.getUriForFile(getActivity(), Qiscus.getProviderAuthorities(), file), mimeType); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } try { startActivity(intent); } catch (ActivityNotFoundException e) { showError(getString(R.string.chat_error_no_handler)); } }
From source file:com.amaze.carbonfilemanager.utils.files.Futils.java
public void openunknown(DocumentFile f, Context c, boolean forcechooser) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); String type = f.getType();/*w w w.j a v a 2s. co m*/ if (type != null && type.trim().length() != 0 && !type.equals("*/*")) { intent.setDataAndType(f.getUri(), type); Intent startintent; if (forcechooser) startintent = Intent.createChooser(intent, c.getResources().getString(R.string.openwith)); else startintent = intent; try { c.startActivity(startintent); } catch (ActivityNotFoundException e) { e.printStackTrace(); Toast.makeText(c, R.string.noappfound, Toast.LENGTH_SHORT).show(); openWith(f, c); } } else { openWith(f, c); } }
From source file:com.amaze.carbonfilemanager.utils.files.Futils.java
public void openWith(final DocumentFile f, final Context c) { MaterialDialog.Builder a = new MaterialDialog.Builder(c); a.title(c.getResources().getString(R.string.openas)); String[] items = new String[] { c.getResources().getString(R.string.text), c.getResources().getString(R.string.image), c.getResources().getString(R.string.video), c.getResources().getString(R.string.audio), c.getResources().getString(R.string.database), c.getResources().getString(R.string.other) }; a.items(items).itemsCallback(new MaterialDialog.ListCallback() { @Override// www . ja v a 2 s. c o m public void onSelection(MaterialDialog materialDialog, View view, int i, CharSequence charSequence) { Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); switch (i) { case 0: intent.setDataAndType(f.getUri(), "text/*"); break; case 1: intent.setDataAndType(f.getUri(), "image/*"); break; case 2: intent.setDataAndType(f.getUri(), "video/*"); break; case 3: intent.setDataAndType(f.getUri(), "audio/*"); break; case 4: intent = new Intent(c, DbViewer.class); intent.putExtra("path", f.getUri()); break; case 5: intent.setDataAndType(f.getUri(), "*/*"); break; } try { c.startActivity(intent); } catch (Exception e) { Toast.makeText(c, R.string.noappfound, Toast.LENGTH_SHORT).show(); openWith(f, c); } } }); try { a.build().show(); } catch (Exception e) { e.printStackTrace(); } }