List of usage examples for android.content Intent EXTRA_STREAM
String EXTRA_STREAM
To view the source code for android.content Intent EXTRA_STREAM.
Click Source Link
From source file:com.krayzk9s.imgurholo.services.DownloadService.java
@Override protected void onHandleIntent(Intent intent) { final NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); ids = intent.getParcelableArrayListExtra("ids"); albumName = "/"; downloaded = 0;/*from w w w . j a v a 2s . com*/ if (ids.size() > 0) { albumName += intent.getStringExtra("albumName") + "/"; File myDirectory = new File( android.os.Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), albumName); if (!myDirectory.exists()) { myDirectory.mkdirs(); } } for (int i = 0; i < ids.size(); i++) { try { final String type = ids.get(i).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TYPE) .split("/")[1]; final String id = ids.get(i).getJSONObject().getString("id"); final String link = ids.get(i).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK); Log.d("data", ids.get(i).getJSONObject().toString()); Log.d(ImgurHoloActivity.IMAGE_DATA_TYPE, ids.get(0).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TYPE).split("/")[1]); Log.d("id", ids.get(i).getJSONObject().getString("id")); Log.d(ImgurHoloActivity.IMAGE_DATA_LINK, ids.get(0).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK)); final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder.setContentTitle(getString(R.string.picture_download)) .setContentText(getString(R.string.download_in_progress)) .setSmallIcon(R.drawable.icon_desaturated); Ion.with(getApplicationContext(), link).progress(new ProgressCallback() { @Override public void onProgress(int i, int i2) { notificationBuilder.setProgress(i2, i, false); } }).write(new File( android.os.Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + albumName + id + "." + type)) .setCallback(new FutureCallback<File>() { @Override public void onCompleted(Exception e, File file) { if (file == null) return; downloaded += 1; if (downloaded == ids.size()) { NotificationCompat.Builder notificationComplete = new NotificationCompat.Builder( getApplicationContext()); if (ids.size() == 1) { Intent viewImageIntent = new Intent(Intent.ACTION_VIEW); viewImageIntent.setDataAndType(Uri.fromFile(file), "image/*"); Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); shareIntent.setType("image/*"); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); PendingIntent viewImagePendingIntent = PendingIntent.getActivity( getApplicationContext(), (int) System.currentTimeMillis(), viewImageIntent, 0); PendingIntent sharePendingIntent = PendingIntent.getActivity( getApplicationContext(), (int) System.currentTimeMillis(), shareIntent, 0); notificationComplete.setContentTitle(getString(R.string.download_complete)) .setSmallIcon(R.drawable.icon_desaturated) .setContentText(String.format(getString(R.string.download_progress), downloaded)) .setContentIntent(viewImagePendingIntent) .addAction(R.drawable.dark_social_share, getString(R.string.share), sharePendingIntent); } else { Intent i = new Intent(Intent.ACTION_PICK); i.setDataAndType( Uri.fromFile(new File( android.os.Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES) + albumName)), "image/*"); PendingIntent viewImagePendingIntent = PendingIntent.getActivity( getApplicationContext(), (int) System.currentTimeMillis(), i, 0); notificationComplete.setContentTitle(getString(R.string.download_complete)) .setSmallIcon(R.drawable.icon_desaturated).setContentText(String .format(getString(R.string.download_progress), downloaded)) .setContentIntent(viewImagePendingIntent); } notificationManager.cancel(0); notificationManager.cancel(1); notificationManager.notify(1, notificationComplete.build()); } MediaScannerConnection.scanFile(getApplicationContext(), new String[] { android.os.Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES) + albumName + id + "." + type }, null, new MediaScannerConnection.OnScanCompletedListener() { @Override public void onScanCompleted(final String path, final Uri uri) { Log.i("Scanning", String.format("Scanned path %s -> URI = %s", path, uri.toString())); } }); } }); notificationManager.notify(0, notificationBuilder.build()); } catch (JSONException e) { Log.e("Error!", e.toString()); } } }
From source file:com.phonegap.cordova.FileOpener.java
private void openFile(String url, String type) throws IOException { // Create URI Uri uri = Uri.parse(url);//from w w w. j a v a 2s. c o m Intent intent = null; Log.v("FileOpener", "Type: " + type); if (type.equals("pdfshare")) { intent = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:")); // intent.setDataAndType(uri, "application/pdf"); intent.setType("application/pdf"); intent.putExtra(Intent.EXTRA_SUBJECT, "AMR Report"); intent.putExtra(Intent.EXTRA_TEXT, ""); intent.putExtra(Intent.EXTRA_STREAM, uri); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } else if (url.contains(".pdf")) { // PDF file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "application/pdf"); } else if (url.contains(".ppt") || url.contains(".pptx")) { // Powerpoint file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "application/vnd.ms-powerpoint"); } else if (url.contains(".xls") || url.contains(".xlsx")) { // Excel file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "application/vnd.ms-excel"); } else if (url.contains(".rtf")) { // RTF file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "application/rtf"); } else if (url.contains(".wav")) { // WAV audio file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "audio/x-wav"); } else if (url.contains(".gif")) { // GIF file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "image/gif"); } else if (url.contains(".jpg") || url.contains(".jpeg")) { // JPG file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "image/jpeg"); } else if (url.contains(".png")) { // PNG file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "image/png"); } else if (url.contains(".txt")) { // Text file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "text/plain"); } else if (url.contains(".mpg") || url.contains(".mpeg") || url.contains(".mpe") || url.contains(".mp4") || url.contains(".avi")) { // Video files intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "video/*"); } else if (url.contains(".doc") || url.contains(".docx")) { // Word document intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "application/msword"); } //if you want you can also define the intent type for any other file //additionally use else clause below, to manage other unknown extensions //in this case, Android will show all applications installed on the device //so you can choose which application to use else if (type.equals("none") || type.equals("*/*")) { intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "*/*"); } else { intent = new Intent(Intent.ACTION_VIEW); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(uri, type); } //TRY Catch error try { this.cordova.getActivity().startActivity(intent); } catch (ActivityNotFoundException e) { intent.setData(uri); this.cordova.getActivity().startActivity(intent); } }
From source file:com.normalexception.app.rx8club.preferences.Preferences.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getPreferenceManager().setSharedPreferencesName(PreferenceHelper.PREFS_NAME); addPreferencesFromResource(R.xml.preferences); Preference shareLog = (Preference) findPreference("exportLog"); shareLog.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override/*from w ww . j a v a 2 s .c om*/ public boolean onPreferenceClick(Preference preference) { String user = UserProfile.getInstance().getUsername(); if (user.equals("")) user = "Guest"; // We need to create an intent here for sharing Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); // The intent type is a text type sharingIntent.setType("message/rfc822"); // Add email details sharingIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { getResources().getString(R.string.bug_contact) }); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "RX8Club.com Log: " + user); // Open the file Uri uri = Uri.fromFile(new File(LogFile.getLogFile())); // Add the file to the intent sharingIntent.putExtra(Intent.EXTRA_STREAM, uri); // Start the intent try { startActivity( Intent.createChooser(sharingIntent, getResources().getString(R.string.sendEmail))); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(MainApplication.getAppContext(), R.string.noEmail, Toast.LENGTH_SHORT).show(); } return true; } }); Preference threadFilter = (Preference) findPreference("threadFilter"); threadFilter.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { //startActivity( // new Intent(MainApplication.getAppContext(), ThreadFilterFragment.class)); // Create new fragment and transaction Fragment newFragment = new ThreadFilterFragment(); FragmentTransaction transaction = getFragmentManager().beginTransaction(); // Replace whatever is in the fragment_container view with this fragment, // and add the transaction to the back stack transaction.add(R.id.content_frame, newFragment); transaction.addToBackStack("threadfilter"); // Commit the transaction transaction.commit(); return true; } }); Preference customAdv = (Preference) findPreference("customSig"); customAdv.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { SignatureDialog sd = new SignatureDialog(getActivity()); sd.show(); return true; } }); Preference man_fave = (Preference) findPreference("manage_favorites"); man_fave.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { if (FavoriteFactory.getInstance().getCount() > 0) { FavoriteDialog fd = new FavoriteDialog(getActivity()); fd.registerToRemove(); fd.show(); } else { notifyError("No Favorites Defined Yet!"); } return true; } }); final Preference cache = (Preference) findPreference("appcache"); cache.setSummary(String.format("Cache Size: %s", SpecialNumberFormatter.readableFileSize((new Cache(getActivity())).getCacheSize()))); cache.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { new AsyncTask<Void, String, Void>() { ProgressDialog loadingDialog; @Override protected void onPreExecute() { loadingDialog = ProgressDialog.show(getActivity(), getString(R.string.dialogClearingCache), getString(R.string.pleaseWait), true); } @Override protected Void doInBackground(Void... params) { try { (new FileCache(getActivity())).clear(); } catch (Exception e) { } return null; } @Override protected void onPostExecute(Void result) { try { loadingDialog.dismiss(); loadingDialog = null; } catch (Exception e) { Log.w(TAG, e.getMessage()); } cache.setSummary(String.format("Cache Size: %s", SpecialNumberFormatter .readableFileSize((new Cache(getActivity())).getCacheSize()))); Toast.makeText(getActivity(), R.string.dialogCacheCleared, Toast.LENGTH_SHORT).show(); } }.execute(); return true; } }); Preference rate = (Preference) findPreference("rate"); rate.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(WebUrls.marketUrl + MainApplication.APP_PACKAGE))); } catch (ActivityNotFoundException e) { // In the event that the market isn't installed // or is unavailable notifyError("Error Opening Market, Sorry!"); } return true; } }); try { Preference version = (Preference) findPreference("version"); version.setSummary(getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0).versionName); } catch (Exception e) { } try { Preference build = (Preference) findPreference("build"); build.setSummary(Integer.toString(getActivity().getPackageManager() .getPackageInfo(getActivity().getPackageName(), 0).versionCode)); } catch (Exception e) { } }
From source file:de.grundid.plusrad.map.ShowMap.java
public void performExport(String geoJsonData) { try {/*www . jav a 2 s . co m*/ File exportFile = createTrackFile(geoJsonData); Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); Uri shareUri = FileProvider.getUriForFile(this, "de.grundid.plusrad.fileprovider", exportFile); shareIntent.setData(shareUri); shareIntent.putExtra(Intent.EXTRA_STREAM, shareUri); shareIntent.setType("text/comma_separated_values/csv"); shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(Intent.createChooser(shareIntent, "Track exportieren")); } catch (IOException e) { e.printStackTrace(); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Fehler").setMessage("Fehler beim Exportieren des Tracks. [" + e.getMessage() + "]"); builder.setPositiveButton("OK", null).show(); } }
From source file:com.vladstirbu.cordova.CDVInstagramVideoPlugin.java
private void share(String videoUrl, String captionString) { if (videoUrl != null && videoUrl.length() > 0) { this.webView.loadUrl("javascript:console.log('processing " + videoUrl + "');"); byte[] videoData = null; try {//from w ww. j a va2 s .c o m URL url = new URL(videoUrl); URLConnection ucon = url.openConnection(); InputStream is = ucon.getInputStream(); videoData = new byte[is.available()]; is.read(videoData); is.close(); } catch (Exception e) { this.webView.loadUrl("javascript:console.log('" + e.getMessage() + "');"); e.printStackTrace(); } File file = null; FileOutputStream os = null; File parentDir = this.webView.getContext().getExternalFilesDir(null); File[] oldVideos = parentDir.listFiles(OLD_IMAGE_FILTER); for (File oldVideo : oldVideos) { oldVideo.delete(); } try { file = File.createTempFile("instagram_video", ".mp4", parentDir); os = new FileOutputStream(file, true); } catch (Exception e) { this.webView.loadUrl("javascript:console.log('" + e.getMessage() + "');"); e.printStackTrace(); } try { os.write(videoData); os.flush(); os.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("video/mp4"); //File media = new File(file); //Uri uri = Uri.fromFile(media); // Add the URI to the Intent. //share.putExtra(Intent.EXTRA_STREAM, uri); // Broadcast the Intent. //startActivity(Intent.createChooser(share, "Share to")); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file)); shareIntent.putExtra(Intent.EXTRA_TEXT, captionString); shareIntent.setPackage("com.instagram.android"); this.cordova.startActivityForResult((CordovaPlugin) this, shareIntent, 12345); } else { this.cbContext.error("Expected one non-empty string argument."); } }
From source file:at.wada811.utils.IntentUtils.java
/** * Intent???//from w w w .jav a 2 s .co m * * @param intent * @param filePaths * @param mimeType * @return */ public static Intent addFiles(Intent intent, ArrayList<String> filePaths, String mimeType) { intent.setAction(Intent.ACTION_SEND_MULTIPLE); intent.setType(mimeType); ArrayList<Uri> uris = new ArrayList<Uri>(filePaths.size()); for (String filePath : filePaths) { uris.add(Uri.fromFile(new File(filePath))); } intent.putExtra(Intent.EXTRA_STREAM, uris); return intent; }
From source file:de.jan.ledgerjournal.JournalActivity.java
private Intent createShareIntent() { Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("text/*"); File journalFile = new File( journal.exportFilePath(sharedPref.getString("exportpath", SettingsActivity.defaultPath(this)))); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(journalFile)); shareIntent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.app_name) + " " + getResources().getString(R.string.share_subject)); //startActivity(Intent.createChooser(shareIntent, "Share Ledger file using")); //ich mchte keinen "Chooser" sobald ich JournalActivity ffne! return shareIntent; }
From source file:at.tomtasche.reader.ui.activity.MainActivity.java
public void share(Uri uri) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setData(uri);/*from ww w.j a va 2s . c om*/ intent.setType("application/*"); intent.putExtra(Intent.EXTRA_STREAM, uri); try { startActivity(intent); } catch (Exception e) { e.printStackTrace(); showCrouton(R.string.crouton_error_open_app, null, AppMsg.STYLE_ALERT); } }
From source file:com.money.manager.ex.core.file.TextFileExport.java
private void offerFile(Uri fileUri, String title) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TITLE, title); intent.putExtra(Intent.EXTRA_STREAM, fileUri); Intent chooser = Intent.createChooser(intent, title); getContext().startActivity(chooser); }
From source file:com.callrecorder.android.RecordingsAdapter.java
private void sendMail(String fileName) { DocumentFile file = FileHelper.getStorageFile(context).findFile(fileName); Uri uri = FileHelper.getContentUri(context, file.getUri()); Intent sendIntent = new Intent(Intent.ACTION_SEND) .putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.mail_subject)) .putExtra(Intent.EXTRA_TEXT, context.getString(R.string.mail_body)) .putExtra(Intent.EXTRA_STREAM, uri).setData(uri).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) .setType("audio/3gpp"); context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.send_mail))); }