简体   繁体   English

共享未经WRITE_EXTERNAL_STORAGE许可的应用程序屏幕截图?

[英]share app screenshot without WRITE_EXTERNAL_STORAGE permission?

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, ""));
    }

Save your image to internal storage (eg, getCacheDir() ), then use FileProvider to make it available to other apps. 将图像保存到内部存储中(例如, getCacheDir() ),然后使用FileProvider使它可用于其他应用程序。 See the documentation for more. 有关更多信息,请参见文档

You are using getExternalCacheDir() 您正在使用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. youraplication应用程序始终可以访问它。 This only applies to paths generated for package name of the youraplication. 这仅适用于为youraplication的程序包名称生成的路径。

android.Manifest.permission.WRITE_EXTERNAL_STORAGE 
android.Manifest.permission.READ_EXTERNAL_STORAGE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM