我需要帮助解决这个问题,因为我是 Android 新手。
我的应用程序支持JellyBean (16)到Oreo (26)。
我有一个UploadService需要openInputStream()上传数据,因为牛轧糖中的新行为。
这段代码在 Marshmallow 及以下版本中运行良好,但总是让我SecurityException在 Nougat 上崩溃。它在错误openInputStream()调用的行上崩溃:
java.lang.SecurityException:权限拒绝:从 com.miui.gallery.provider.GalleryOpenProvider uri content://com.miui.gallery.open/raw/%2Fstorage%2Femulated%2F0%2FDCIM%2FCamera%2FIMG_20171008_182pid34.jpg 中读取=30846, uid=10195 需要提供者被导出,或者grantUriPermission()
The file uri could be from various app (gallery, camera, etc). I've narrowed down the problem to uri that comes from ACTION_GET_CONTENT intent (anything that comes from camera intent or MediaRecorder works fine).
I think it's because the uri lost its permission when passed into the …
android securityexception permission-denied android-7.0-nougat
我希望有人可以帮我解决这个问题.
我有一个应用程序,使用户可以拍摄视频(.mp4)或选择现有的视频.如果拍摄视频,视频会保存到公共目录,我会触发Android扫描文件以将其添加到媒体库.
问题是,视频运行正常,我可以在我的应用程序中预览完成的视频.但是同样的视频不会出现在媒体库中,也不会被其他应用程序访问 - 除了FileManager-,即使同一文件夹中的其他.mp4出现在列表中也不错.
更多信息:
是否需要额外的许可才能使用?我添加/询问/请求从ext写入和读取的权限.存储和相机在我的清单和代码中.
以下是我拍摄视频并将其扫描到图库的方式:
private void takeVideo() {
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (takeVideoIntent.resolveActivity(ctx.getPackageManager()) != null) {
// Create the file where photo should go
File mediaFile = null;
try {
mediaFile = getOutputMediaFile(ctx, MEDIA_TYPE_VIDEO);
} catch (IOException ex) {
Log.e("FragCamera", "takeVideo() : Error occurred while creating File." + ex);
}
if (mediaFile != null) {
Uri mediaUri = Uri.fromFile(mediaFile);
Log.d("FragCamera", "takeVideo() mediaUri: " + mediaUri);
currMediaUri = mediaUri;
currPhotoPath = …Run Code Online (Sandbox Code Playgroud)