简体   繁体   English

创建自己的权限

[英]Creating your own permissions

Is it possible to create your own permissions using the <uses-permission> tag? 是否可以使用<uses-permission>标签创建自己的权限?

Like this 像这样

<uses-permission android:name="com.android.myapp.INSTALL_LICENSE"></uses-permission>

Where com.android.myapp is the name of my package and INSTALL_LICENSE is the permission that users must accept com.android.myapp是我的包的名称,而INSTALL_LICENSE是用户必须接受的权限

In addition I would like to budle a whole lot of existing permissions into this one permission so client would only need to declare a single permission and they would get the INTERNET, PHONE_STATE and other permissions. 此外,我想将大量现有权限发布到这一权限中,因此客户端只需要声明一个权限,他们就可以获得INTERNET,PHONE_STATE和其他权限。

Yes, you can declare your own permission and if another app would like to use your app it in turn should declare your permission. 是的,您可以声明自己的权限,如果其他应用想要使用您的应用,则应该声明您的许可。

For example you declare in your manifest the following: 例如,您在清单中声明以下内容:

<permission
    android:name="com.examples.permissionexample.MY_APP"
    android:description="@string/boom_perm_string"
    android:label="@string/boom_permission_label_string">
</permission>

Then, in another app, the permission to access your app would will be: 然后,在另一个应用中,访问您的应用的权限将是:

<uses-permission android:name="com.examples.permissionexample.MY_APP" />

"In addition I would like to budle a whole lot of existing permissions into this one permission". “此外,我想在这一个权限中发布大量现有权限”。

Um, no. 不。 That would be deliberately introducing a security hole, allowing other applications to bypass the actual permissions. 这将故意引入安全漏洞,允许其他应用程序绕过实际权限。 I hope this would result in the app being pulled from Market, if it is found. 我希望这会导致应用程序从市场撤出,如果找到的话。

If an application is getting access to INTERNET, PHONE_STATE, or whatever else, they need to declare the real permission they are using which is directly associated with that functionality. 如果应用程序正在访问INTERNET,PHONE_STATE或其他任何内容,则需要声明他们正在使用的与该功能直接关联的真实权限。

What is okay is to have your own permission to restrict app access to your functionality, and inside of your own .apk you implement that functionality using other permissions... but do not directly expose that to the app. 什么好的是有自己的权限来限制你的功能的应用程序访问,以及你自己的内部的apk您使用其他权限实现该功能... ...但不要直接暴露,为应用程序。

In other words, this is okay: Declare a permission for DO_SOMETHING, that allows an application to say send a broadcast do you that will have you do something and return a "true" or "false" result indicating whether it succeeded. 换句话说,这是可以的:声明DO_SOMETHING的权限,允许应用程序说你发送广播,你会做什么,并返回一个“true”或“false”结果,表明它是否成功。

This is not okay: Declare a permission for DO_SOMETHING, which exposes an API that allows an application to retrieve the phone state, or send some data they provide off the device, or retrieve GPS information. 这不合适:声明DO_SOMETHING的权限,该权限公开允许应用程序检索手机状态的API,或者发送他们从设备提供的一些数据,或检索GPS信息。

To declare a permission in your app, you use the tag as described in the docs. 要在您的应用中声明权限,请使用文档中所述的标记。

However something you really need to be aware of: currently if an app is installed before your app and requests your permission, it will not be granted that permission. 但是,您确实需要注意一些事项:目前,如果您的应用程序之前安装了应用程序并请求您的许可,则不会授予该权限。 (Because the permission was not known at the time it was installed.) For it to be granted the permission, it needs to be re-installed or updated after your app is installed. (因为安装时未知该权限。)为了获得权限,需要在安装应用程序后重新安装或更新权限。

Not sure what you mean by "using the tag" but you can create new permission to specify how other applications can interact with activities and services provided by yours. 不确定“使用标记”是什么意思,但您可以创建新的权限来指定其他应用程序如何与您提供的活动和服务进行交互。

See "Declaring and enforcing permissions" at: 请参阅:“声明和强制执行权限”:

http://developer.android.com/guide/topics/security/security.html http://developer.android.com/guide/topics/security/security.html

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

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