在运行时授予用户权限后,Android 6.0需要重新启动 [英] Android 6.0 needs restart after granting user permission at runtime

查看:156
本文介绍了在运行时授予用户权限后,Android 6.0需要重新启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照本指南要求获取Android 6.0的权限, https://developer.android.com/preview/features/runtime-permissions.html#support-lib

I follow this guide to ask for permissions for Android 6.0, https://developer.android.com/preview/features/runtime-permissions.html#support-lib

但是,我必须销毁我的应用程序,然后重新启动才能真正拥有WRITE_EXTERNAL_STORAGE权限,否则它将始终无法创建文件.

However, I have to destroy my application and re-launch to actually have the WRITE_EXTERNAL_STORAGE permission, otherwise it keeps failing for file creation.

我想念什么吗?

if(ActivityCompat.checkSelfPermission(mContext, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED){
    ActivityCompat.requestPermissions((MainActivity)mContext,new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},MY_PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
} else {
    Intent i = new Intent(v.getContext(), ServiceDownload.class);
    v.getContext().startService(i);
}

文件是在服务中创建的,它是模拟器,而不是真实的设备.

File is created in the service and this is emulator not a real device.

推荐答案

这是一个已经提到的错误,但是我在这个问题中发现可以添加以下行:

It is a bug as someone already mentioned, but I found in this question that you can add this line:

android.os.Process.killProcess(android.os.Process.myPid());

获得您的许可后.这不是真正的解决方法,只是有助于避免崩溃.

after your permission has been granted. This is not a real fix, just helps avoid crashing.

这篇关于在运行时授予用户权限后,Android 6.0需要重新启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆