简体   繁体   English

如何在 Java 中以编程方式重置 Android 用户权限

[英]How to Reset Android User Permissions Programatically in Java

I am trying to reset the android permissions defined by the user through a java program.我正在尝试通过 java 程序重置用户定义的 android 权限。

this is the part of android.webkit API and i found out on- GeolocationPermissions.Callback这是 android.webkit API 的一部分,我发现了 - GeolocationPermissions.Callback

Although there are a lot of android permissions that user may define in AndroidManifest.xml.So how do i reset all the permissions of android device in Java ?虽然用户可以在 AndroidManifest.xml 中定义很多 android 权限。那么我如何在 Java 中重置 android 设备的所有权限? Is there any common way to do that?有没有什么通用的方法可以做到这一点?

Thanks in Advance.提前致谢。

In short, I don't think this is possible.简而言之,我认为这是不可能的。

From what I have understood, you are referring to the new permission model (Runtime Permissions) introduced in Marshmallow and by "reset" you want user to grant it to you.据我了解,您指的是 Marshmallow 中引入的新权限模型(运行时权限),并通过“重置”您希望用户将其授予您。

Runtime Permissions is a step to give users full control over the permissions used by the apps.运行时权限是让用户完全控制应用程序使用的权限的一个步骤。 Apps can only request for the permissions but cannot change it programmatically without any user interaction.应用程序只能请求权限,但不能在没有任何用户交互的情况下以编程方式更改它。

The solution here is to ask for the permission and check if user has granted it or not.这里的解决方案是请求权限并检查用户是否已授予权限。 If not, explain him about why you need that specific permission.如果没有,请向他解释为什么您需要该特定许可。

For more read:更多阅读:

(Correct me if I'm wrong / misunderstood the question. You can edit the question with more details.) (如果我错了/误解了问题,请纠正我。您可以使用更多详细信息编辑问题。)

There's this API有这个 API

((ActivityManager)context.getSystemService(ACTIVITY_SERVICE)).clearApplicationUserData();

Permits an application to erase its own data from disk.允许应用程序从磁盘擦除自己的数据。 This is equivalent to the user choosing to clear the app's data from within the device settings UI.这相当于用户选择从设备设置 UI 中清除应用程序的数据。 It erases all dynamic data associated with the app -- its private data and data in its private area on external storage -- but does not remove the installed application itself, nor any OBB files.它会删除与应用程序相关的所有动态数据——它的私有数据和外部存储私有区域中的数据——但不会删除已安装的应用程序本身,也不会删除任何 OBB 文件。 It also revokes all runtime permissions that the app has acquired , clears all notifications and removes all Uri grants related to this application.它还撤销应用程序已获得的所有运行时权限,清除所有通知并删除与此应用程序相关的所有 Uri 授权。

However, this api will force close your app.但是,此 api 将强制关闭您的应用程序。 More info in this answer: https://stackoverflow.com/a/29197259/5673746此答案中的更多信息: https : //stackoverflow.com/a/29197259/5673746

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

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