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.fbbackup.ImageDetailActivity.java
private void setListener() { btn_share.setOnClickListener(new Button.OnClickListener() { @Override/* w w w. j a va 2s . c o m*/ public void onClick(View v) { // TODO Auto-generated method stub // Gets a handle to the clipboard service. ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(clipBoardText); PackageManager pm = getPackageManager(); Intent intent = pm.getLaunchIntentForPackage("jp.naver.line.android"); File file = new File(extStorageDirectory + "/DCIM/FBBackup/test.jpg"); Uri outputFileUri = Uri.fromFile(file); String[] path = { extStorageDirectory + "/DCIM/FBBackup/test.jpg" }; // MediaScannerConnection.scanFile(this, path, null, // new MediaScannerConnection.OnScanCompletedListener() { // public void onScanCompleted(String path, Uri uri) { // Log.i("ExternalStorage", "Scanned " + path + ":"); // Log.i("ExternalStorage", "-> uri=" + uri); // } // }); MediaScannerConnection.scanFile(getApplicationContext(), path, null, null); Log.w("RyanWang", outputFileUri.getPath()); intent.setAction(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_STREAM, outputFileUri); intent.setType("image/jpeg"); startActivity(intent); } }); btn_download_photo.setOnClickListener(new ImageButton.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub DownloadSinglePicTask download = new DownloadSinglePicTask(); download.setContext(ImageDetailActivity.this); download.setAlbunPhotoUrl(clipBoardText); Log.w("downloadpic", "ImageDetail albumName:" + albumName); download.setPath( extStorageDirectory + "/DCIM/FBBackup/" + name + "/" + Utils.getDirName(albumName) + "/"); download.execute("test"); } }); }
From source file:bupt.tiantian.callrecorder.callrecorder.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { Intent intent = new Intent(this, SettingsActivity.class); intent.putExtra("write_external", permissionWriteExternal); startActivity(intent);/*from www. j av a 2 s .co m*/ return true; } if (id == R.id.action_save) { if (null != selectedItems && selectedItems.length > 0) { Runnable runnable = new Runnable() { @Override public void run() { for (PhoneCallRecord record : selectedItems) { record.getPhoneCall().setKept(true); record.getPhoneCall().save(MainActivity.this); } LocalBroadcastManager.getInstance(MainActivity.this) .sendBroadcast(new Intent(LocalBroadcastActions.NEW_RECORDING_BROADCAST)); // Causes refresh } }; handler.post(runnable); } return true; } if (id == R.id.action_share) { if (null != selectedItems && selectedItems.length > 0) { Runnable runnable = new Runnable() { @Override public void run() { ArrayList<Uri> fileUris = new ArrayList<Uri>(); for (PhoneCallRecord record : selectedItems) { fileUris.add(Uri.fromFile(new File(record.getPhoneCall().getPathToRecording()))); } Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE); shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, fileUris); shareIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.email_title)); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { shareIntent.putExtra(Intent.EXTRA_HTML_TEXT, Html.fromHtml(getString(R.string.email_body_html), Html.FROM_HTML_MODE_LEGACY)); } else { shareIntent.putExtra(Intent.EXTRA_HTML_TEXT, Html.fromHtml(getString(R.string.email_body_html))); } shareIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.email_body)); shareIntent.setType("audio/*"); startActivity(Intent.createChooser(shareIntent, getString(R.string.action_share))); } }; handler.post(runnable); } return true; } if (id == R.id.action_delete) { if (null != selectedItems && selectedItems.length > 0) { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle(R.string.delete_recording_title); alert.setMessage(R.string.delete_recording_subject); alert.setPositiveButton(R.string.dialog_yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Runnable runnable = new Runnable() { @Override public void run() { Database callLog = Database.getInstance(MainActivity.this); for (PhoneCallRecord record : selectedItems) { int id = record.getPhoneCall().getId(); callLog.removeCall(id); } LocalBroadcastManager.getInstance(MainActivity.this).sendBroadcast( new Intent(LocalBroadcastActions.RECORDING_DELETED_BROADCAST)); //?selectedItems onListFragmentInteraction(new PhoneCallRecord[] {}); } }; handler.post(runnable); dialog.dismiss(); } }); alert.setNegativeButton(R.string.dialog_no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alert.show(); } return true; } if (id == R.id.action_delete_all) { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle(R.string.delete_recording_title); alert.setMessage(R.string.delete_all_recording_subject); alert.setPositiveButton(R.string.dialog_yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Runnable runnable = new Runnable() { @Override public void run() { Database.getInstance(MainActivity.this).removeAllCalls(false); LocalBroadcastManager.getInstance(getApplicationContext()) .sendBroadcast(new Intent(LocalBroadcastActions.RECORDING_DELETED_BROADCAST)); //?selectedItems onListFragmentInteraction(new PhoneCallRecord[] {}); } }; handler.post(runnable); dialog.dismiss(); } }); alert.setNegativeButton(R.string.dialog_no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alert.show(); return true; } if (R.id.action_whitelist == id) { if (permissionReadContacts) { Intent intent = new Intent(this, WhitelistActivity.class); startActivity(intent); } else { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle(R.string.permission_whitelist_title); alert.setMessage(R.string.permission_whitelist); } return true; } return super.onOptionsItemSelected(item); }
From source file:com.snowdream.wallpaper.ImagePagerActivity.java
private Intent createShareIntent() { if (pager == null || pager.getAdapter() == null || !(pager.getAdapter() instanceof ImagePagerAdapter)) { return null; }//from w w w. ja v a 2 s.co m ImagePagerAdapter adapter = (ImagePagerAdapter) pager.getAdapter(); List<Image> images = adapter.getImages(); if (images == null || images.size() <= 0) { return null; } int pos = pager.getCurrentItem(); if (pos >= images.size()) { return null; } Image image = images.get(pos); if (image == null) { return null; } String imageUrl = image.getUrl(); if (imageUrl == null || imageUrl == "") { return null; } File file = ImageLoader.getInstance().getDiscCache().get(imageUrl); if (file == null || !file.exists() || !file.canRead()) { return null; } Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("image/*"); Uri uri = Uri.fromFile(file); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); //shareIntent.putExtra(Intent.EXTRA_TEXT, "?"); return shareIntent; }
From source file:org.jnegre.android.osmonthego.service.ExportService.java
/** * Handle export in the provided background thread *//*from w ww . j av a 2 s .co m*/ private void handleOsmExport(boolean includeAddress, boolean includeFixme) { //TODO handle empty survey //TODO handle bounds around +/-180 if (!isExternalStorageWritable()) { notifyUserOfError(); return; } int id = 0; double minLat = 200; double minLng = 200; double maxLat = -200; double maxLng = -200; StringBuilder builder = new StringBuilder(); if (includeAddress) { Uri uri = AddressTableMetaData.CONTENT_URI; Cursor cursor = getContentResolver().query(uri, new String[] { //projection AddressTableMetaData.LATITUDE, AddressTableMetaData.LONGITUDE, AddressTableMetaData.NUMBER, AddressTableMetaData.STREET }, null, //selection string null, //selection args array of strings null); //sort order if (cursor == null) { notifyUserOfError(); return; } try { int iLat = cursor.getColumnIndex(AddressTableMetaData.LATITUDE); int iLong = cursor.getColumnIndex(AddressTableMetaData.LONGITUDE); int iNumber = cursor.getColumnIndex(AddressTableMetaData.NUMBER); int iStreet = cursor.getColumnIndex(AddressTableMetaData.STREET); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { //Gather values double lat = cursor.getDouble(iLat); double lng = cursor.getDouble(iLong); String number = cursor.getString(iNumber); String street = cursor.getString(iStreet); minLat = Math.min(minLat, lat); maxLat = Math.max(maxLat, lat); minLng = Math.min(minLng, lng); maxLng = Math.max(maxLng, lng); builder.append("<node id=\"-").append(++id).append("\" lat=\"").append(lat).append("\" lon=\"") .append(lng).append("\" version=\"1\" action=\"modify\">\n"); addOsmTag(builder, "addr:housenumber", number); addOsmTag(builder, "addr:street", street); builder.append("</node>\n"); } } finally { cursor.close(); } } if (includeFixme) { Uri uri = FixmeTableMetaData.CONTENT_URI; Cursor cursor = getContentResolver().query(uri, new String[] { //projection FixmeTableMetaData.LATITUDE, FixmeTableMetaData.LONGITUDE, FixmeTableMetaData.COMMENT }, null, //selection string null, //selection args array of strings null); //sort order if (cursor == null) { notifyUserOfError(); return; } try { int iLat = cursor.getColumnIndex(FixmeTableMetaData.LATITUDE); int iLong = cursor.getColumnIndex(FixmeTableMetaData.LONGITUDE); int iComment = cursor.getColumnIndex(FixmeTableMetaData.COMMENT); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { //Gather values double lat = cursor.getDouble(iLat); double lng = cursor.getDouble(iLong); String comment = cursor.getString(iComment); minLat = Math.min(minLat, lat); maxLat = Math.max(maxLat, lat); minLng = Math.min(minLng, lng); maxLng = Math.max(maxLng, lng); builder.append("<node id=\"-").append(++id).append("\" lat=\"").append(lat).append("\" lon=\"") .append(lng).append("\" version=\"1\" action=\"modify\">\n"); addOsmTag(builder, "fixme", comment); builder.append("</node>\n"); } } finally { cursor.close(); } } try { File destinationFile = getDestinationFile(); destinationFile.getParentFile().mkdirs(); PrintWriter writer = new PrintWriter(destinationFile, "UTF-8"); writer.println("<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>"); writer.println("<osm version=\"0.6\" generator=\"OsmOnTheGo\">"); writer.print("<bounds minlat=\""); writer.print(minLat - MARGIN); writer.print("\" minlon=\""); writer.print(minLng - MARGIN); writer.print("\" maxlat=\""); writer.print(maxLat + MARGIN); writer.print("\" maxlon=\""); writer.print(maxLng + MARGIN); writer.println("\" />"); writer.println(builder); writer.print("</osm>"); writer.close(); if (writer.checkError()) { notifyUserOfError(); } else { //FIXME i18n the subject and content Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); emailIntent.setType(HTTP.OCTET_STREAM_TYPE); //emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"johndoe@exemple.com"}); emailIntent.putExtra(Intent.EXTRA_SUBJECT, "OSM On The Go"); emailIntent.putExtra(Intent.EXTRA_TEXT, "Your last survey."); emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(destinationFile)); startActivity(emailIntent); } } catch (IOException e) { Log.e(TAG, "Could not write to file", e); notifyUserOfError(); } }
From source file:edu.ksu.cs.a4vm.bse.EditCollections.java
@Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantresults) { if (requestCode == REQUEST_EXTERNAL_STORAGE) { if (grantresults.length > 0 && grantresults[0] == PackageManager.PERMISSION_GRANTED) { File file;//w w w.jav a2 s.c o m File root = Environment.getExternalStorageDirectory(); File dir = new File(root.getAbsolutePath() + "/bull_collections"); dir.mkdirs(); file = new File(dir, "Data.csv"); try { if (!file.exists()) { file.createNewFile(); } FileOutputStream out = null; out = new FileOutputStream(file); String head = Constant.CSV_HEADING; ArrayList<ArrayList> list = CreateCSV.getData(getApplicationContext(), grpId); if (Constant.morphHeaders != null) { for (int i = 0; i < Constant.morphHeaders.size(); i++) { head = head + Constant.morphHeaders.get(i) + ","; } } out.write(head.getBytes()); if (list != null) { for (int i = 0; i < list.size(); i++) { out.write("\n".getBytes()); ArrayList<String> row = list.get(i); String contents; if (row != null) { contents = row.get(0); for (int j = 1; j < 103; j++) { contents = contents + "," + row.get(j); } out.write(contents.getBytes()); } } } out.close(); } catch (IOException e) { Log.e(Constant.CSV_MSG, "File writing error"); e.printStackTrace(); } Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Exported file"); sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); sendIntent.setType("text/html"); startActivityForResult(sendIntent, 119); } else { Toast.makeText(getApplicationContext(), "Permission denied!", Toast.LENGTH_SHORT).show(); } } else { Log.d("BSE Msg", "Request Storage permission failed!"); } }
From source file:com.cyberprism.libin.artourist.ARActivity.java
protected void saveScreenCaptureToExternalStorage(Bitmap screenCapture) { if (screenCapture != null) { // store screenCapture into external cache directory final File screenCaptureFile = new File(Environment.getExternalStorageDirectory().toString(), "screenCapture_" + System.currentTimeMillis() + ".jpg"); // 1. Save bitmap to file & compress to jpeg. You may use PNG too try {/*w w w . j a va 2 s . c om*/ final FileOutputStream out = new FileOutputStream(screenCaptureFile); screenCapture.compress(Bitmap.CompressFormat.JPEG, 90, out); out.flush(); out.close(); // 2. create send intent final Intent share = new Intent(Intent.ACTION_SEND); share.setType("image/jpg"); share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(screenCaptureFile)); // 3. launch intent-chooser final String chooserTitle = "Share Snaphot"; ARActivity.this.startActivity(Intent.createChooser(share, chooserTitle)); } catch (final Exception e) { // should not occur when all permissions are set ARActivity.this.runOnUiThread(new Runnable() { @Override public void run() { // show toast message in case something went wrong Toast.makeText(ARActivity.this, "Unexpected error, " + e, Toast.LENGTH_LONG).show(); } }); } } }
From source file:com.rks.musicx.misc.utils.Helper.java
/** * Share Music/* ww w .j a v a2 s . c om*/ * * @param id * @param context */ public static void shareMusic(long id, Context context) { if (permissionManager.isExternalReadStorageGranted(context)) { if (id == 0) { return; } Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; Uri trackUri = Uri.parse(uri.toString() + "/" + id); Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_STREAM, trackUri); intent.setType("audio/*"); context.startActivity(Intent.createChooser(intent, context.getString(R.string.share))); } else { Log.d("Helper", "Permission failed"); } }
From source file:com.jalotsav.aalayamnavjivan.ActvtyBookView.java
private void shareBook() { try {//w ww .ja va2 s . c o m File mBookFilePathLocal = new File(mBookPathLocal); if (mBookFilePathLocal.exists()) { Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setType("application/pdf"); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(mBookFilePathLocal)); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(Intent.createChooser(shareIntent, getString(R.string.share_appname_book_3dots, getString(R.string.app_name)))); } else Snackbar.make(mCrdntrlyot, mBookNotFound, Snackbar.LENGTH_LONG).show(); } catch (Exception e) { e.printStackTrace(); Snackbar.make(mCrdntrlyot, mBookNotFound, Snackbar.LENGTH_LONG).show(); } }
From source file:com.zia.freshdocs.widget.adapter.CMISAdapter.java
/** * Send the content using a built-in Android activity which can handle the * content type.//www . j av a 2 s . c om * * @param position */ public void shareContent(int position) { final NodeRef ref = getItem(position); downloadContent(ref, new Handler() { public void handleMessage(Message msg) { Context context = getContext(); boolean done = msg.getData().getBoolean("done"); if (done) { dismissProgressDlg(); File file = (File) mDlThread.getResult(); if (file != null) { Resources res = context.getResources(); Uri uri = Uri.fromFile(file); Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.putExtra(Intent.EXTRA_STREAM, uri); emailIntent.putExtra(Intent.EXTRA_SUBJECT, ref.getName()); emailIntent.putExtra(Intent.EXTRA_TEXT, res.getString(R.string.email_text)); emailIntent.setType(ref.getContentType()); try { context.startActivity( Intent.createChooser(emailIntent, res.getString(R.string.email_title))); } catch (ActivityNotFoundException e) { String text = "No suitable applications registered to send " + ref.getContentType(); int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show(); } } } else { int value = msg.getData().getInt("progress"); if (value > 0) { mProgressDlg.setProgress(value); } } } }); }
From source file:com.github.snowdream.android.apps.imageviewer.ImageViewerActivity.java
private Intent createShareIntent() { Intent shareIntent = null;//from www .java 2 s . c o m if (!TextUtils.isEmpty(imageUri)) { shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("image/*"); Uri uri = Uri.parse(imageUri); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); } return shareIntent; }