Question

I'm trying to implement a "Share Image" button in my Android app. Since the image might be private for the user, I did not want it to be saved on the device publicly, so I chose to use the cache.

Before I figured out that the cache directory only was accessible by the owner app, I noticed that sharing the image to Dropbox worked just fine (whereas other apps threw Exceptions). How does Dropbox access that file if its located in my apps cache?

My share-bitmap method (stripped of exception handling):

    final File outputFile = new File(getCacheDir(), filename);                                            

    // Save file
    FileOutputStream out = new FileOutputStream(outputFile);
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);

    // Get path of file
    Uri bmpUri = Uri.parse(outputFile.getAbsolutePath());

    // Share image
    final Intent intent = new Intent(android.content.Intent.ACTION_SEND);
    intent.setData(bmpUri);
    intent.putExtra(Intent.EXTRA_STREAM, bmpUri);
    intent.setType("image/*");

    startActivity(Intent.createChooser(intent,"Share Image"));
Was it helpful?

Solution

I think this is because the Dropbox app has specific permissions to do so:

System tools
test access to protected storage

I also find out that this permission seems to be a child of the WRITE_EXTERNAL_STORAGE permission.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top