1

Is it possible to share own app screenshots without adding any permissions ?

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

And this is my others apps code which is works on copy to cache and share

public void sendFile(File paramFile) {

        String fileExtension = ".apk";
        File temporaryFile;
        try {
            temporaryFile = File.createTempFile(paramFile.getName(), fileExtension, getApplicationContext().getExternalCacheDir());
            copy(paramFile, temporaryFile);
        } catch (Exception e) {
            temporaryFile = paramFile;
        }
        Intent localIntent = new Intent();
        localIntent.setAction("android.intent.action.SEND");
        localIntent.putExtra("android.intent.extra.STREAM", Uri.fromFile(temporaryFile));
        localIntent.setType("application/*");
        localIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        startActivity(Intent.createChooser(localIntent, ""));
    }
  • definitely not. how could you share the file without read it. – Noorul Mar 04 '17 at 12:25
  • some thing write to cache and then share? –  Mar 04 '17 at 12:26
  • Give a try. Definitely not. – Noorul Mar 04 '17 at 12:27
  • is it a best practice for sharing to save it somewhere and share? –  Mar 04 '17 at 12:28
  • How can you? Are you going save the cache in system chip memory. You are writing the application in android os . right? so you need to create the file as cache file and save it in temporary location. that location also will be in phone storage or external card. then, how can you? – Noorul Mar 04 '17 at 12:31
  • I have an app, and in this app , I copying file to cache and share, without any permissions ,and it really works. –  Mar 04 '17 at 12:35
  • Could you post your code. We will see what you have done. ? – Noorul Mar 04 '17 at 12:36
  • Posted in questions @Ahamed –  Mar 04 '17 at 12:39
  • but it don't exists in manifest and google play store, I need something like this. And also it works without it also –  Mar 04 '17 at 12:42
  • you can not share file directly, as you have to set URI as share in intent chooser. – Rajesh Mar 04 '17 at 12:43
  • 1
    Check this answer http://stackoverflow.com/a/29231467/7479343 – Kamil Ibadov Mar 04 '17 at 12:45

2 Answers2

2

Save your image to internal storage (e.g., getCacheDir()), then use FileProvider to make it available to other apps. See the documentation for more.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

You are using getExternalCacheDir()

it absolute the path to youraplication specific directory on the primary external storage device where the application can place cache files it owns. These files are internal to the application, and not typically visible to the user as media.

There is no security enforced with these files. no need to add the permissions to read or write to the returned path. it's always accessible to the youraplication app. This only applies to paths generated for package name of the youraplication.

android.Manifest.permission.WRITE_EXTERNAL_STORAGE 
android.Manifest.permission.READ_EXTERNAL_STORAGE
Noorul
  • 3,386
  • 3
  • 32
  • 54