在Lollipop及更高版本上仅获得一次sdcard窗口的权限 [英] Getting only once permission for sdcard window on Lollipop and above version
问题描述
您好,我正在从SD卡中删除某些项目.在棒棒糖中,我第一次请求许可和用户授予许可,但是现在我不想每次都请求许可.这非常令人恼火,许多人对此行为感到恐惧.我该如何保存我的许可,即下次我不需要一次又一次地传递该意图
Hello I am deleting some items from SD card. And in lollipop first time i ask for permission and user grant permission, but now i don't want to ask every time for permission. Its very irritating and many of guys they afraid from this behavior. How can i save my permission i.e. next time i don't need to pass that Intent again and again
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
谢谢
推荐答案
您可以使用以下代码来保留权限
You can use the following code to persist permission
getContentResolver().takePersistableUriPermission(treeUri,
Intent.FLAG_GRANT_READ_URI_PERMISSION |
Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
此外,一旦您保留权限,就将uri保存在sharedPreference中,以便以后无需确认即可删除文件.
Also once you persist permission save the uri in a sharedPreference so that you can delete files later without confirmation.
这篇关于在Lollipop及更高版本上仅获得一次sdcard窗口的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!