Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>getFileStreamPath()</code> or <code>openFileOutput()</code> will create files in a private directory that is inaccessible to other apps (i.e. Gmail). Use external storage to create publicly-accessible files:</p> <pre><code>private static final int REQUEST_SHARE = 39714; private File png = null; private void startSendIntent() { png = new File(new File(Environment.getExternalStorageDirectory(), "Pictures"), getString(R.string.file_name)); FileOutputStream out = null; try { out = new FileOutputStream(png); bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); out.flush(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (out != null) out.close(); } catch (IOException ignore) {} } final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(png)); emailIntent.setType("image/png"); startActivityForResult(Intent.createChooser(emailIntent, getString(R.string.send_intent_name)), REQUEST_SHARE); } } </code></pre> <p>This will not work when the external storage is unavailable, like when it is mounted as a USB drive. See the <a href="http://developer.android.com/guide/topics/data/data-storage.html#filesExternal" rel="noreferrer">Storage API Guide</a> for more about detecting whether external storage is available.</p> <p>If your minimum API level is 8 or above, you can use <code>Context.getExternalCacheDir()</code> or <code>Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)</code> as the parent directory.</p> <p>Unless you end up using <code>getExternalCacheDir()</code>, make sure you use a unique filename to prevent one of the users' files from accidentally getting overwritten.</p> <p>Finally, you can override <code>onActivityResult()</code> to delete the file after the share operation completes:</p> <pre><code>protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(requestCode == REQUEST_SHARE) { if(this.png == null) { return; } this.png.delete(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload