关于Android中自定义权限的几个问题 [英] Few questions about custom permissions in Android

查看:158
本文介绍了关于Android中自定义权限的几个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Android编程,并且对自定义权限的概念有所了解.

I am learning Android programming and I have kind of understood the concept of custom permission.

根据我的理解,这是自定义权限的工作方式:

Based on my understanding this is how custom permissions works:

'Base app'可以通过声明自定义权限(即,使用清单文件中的<permission>标记)和调用受自定义保护的活动和服务的'client app'来保护其某些组件(例如,活动和服务)权限需要获取必要的权限(即,使用清单文件中的<uses-permission>标记)以调用base app中的那些组件.

'Base app'can protect some of its components (e.g., activity and services) by declaring custom permissions (i.e., using <permission> tags in the manifest file) and the'client app' that calls the activities and services protected by custom permissions need to acquire necessary permissions (i.e., using <uses-permission> tags in the manifest file) to call those components in the base app.

但是,我对自定义权限有以下疑问:

However, I have these questions regarding custom permissions:

  1. 如果自定义权限被声明为危险(即android:protectionLevel="dangerous"),client app是否需要在安装期间获得用户的批准?如果是这样,用户将如何知道这些自定义权限,因为将没有任何有关自定义权限的文档.
  2. 在安装期间,client app如何知道用户电话中已经安装了base app?反正client app是否知道此信息?
  3. 一旦安装了client app,如果用户决定删除base app,会发生什么?在这种情况下,如果用户尝试使用client app,会导致任何安全异常吗?
  1. If the custom permission is declared as dangerous (i.e., android:protectionLevel="dangerous"), does the client app needs to get the approval from the user during installation time? If so, how does the user aware of these custom permissions because there won't be any documentation for the custom permissions.
  2. During installation time how does the client app knows that base app is already installed in the user's phone? Is there anyway for the client app to know this information?
  3. Once the client app is installed, what will happen if the user decides to remove the base app? In this case, if the user tries to use client app will it cause any security exception?

我不知道这些问题是否有意义,但这让我想知道自定义权限在实际情况下如何实际工作.

I don't know whether these questions make sense but it makes me wonder how custom permissions actually work in real scenario.

谢谢.

推荐答案

下面给出了您的问题的答案.但是您可以参考 http://developer.android.com/guide/topics/manifest/permission-element.html ,以更好地了解Android权限.

The answers to your questions is give below. But you may refer http://developer.android.com/guide/topics/manifest/permission-element.html for a better understanding of Android permissions.

1.是的,如果您声明

1.Yes, if you declare

android:protectionLevel="dangerous"

然后系统可能不会自动将其授予请求的应用程序.应用程序请求的任何危险许可都可能显示给用户,并需要确认才能继续.

then the system may not automatically grant it to the requesting application.Any dangerous permissions requested by an application may be displayed to the user and require confirmation before proceeding.

定义自定义权限的基本应用应该通过

The base app defining custom permission is supposed to provide a description via

android:description="string resource"

这是示例权限定义.希望这是不言自明的.

Here is the an example permission definition. Hope it is self explanatory.

<permission android:description="string resource"
android:icon="drawable resource"
android:label="string resource"
android:name="string"
android:permissionGroup="string"
android:protectionLevel=["normal" | "dangerous" | 
 "signature" | "signatureOrSystem"] />

2.据我所知,客户端应用程序在安装时无法看到基本应用程序的存在.但是有可能在客户端应用程序启动时.无论如何,Android系统会根据您的android.xml文件授予权限.因此,客户端应用程序在安装时不必为基础应用程序而烦恼.

2.As far as I know, there is no way for the client app to see the presence of base app at the time of installation. But it is possible when the client App is started. Anyway, permissions are granted by the Android system based on your android.xml file. So the client app don't have to bother about base app at the time of installation.

3.即使仍安装了客户端应用程序,也可以删除基本应用程序.它在任何阶段都不会出现任何错误消息或安全异常.但是,当您尝试再次运行客户端应用程序时,当您尝试从客户端应用程序调用基本应用程序活动时,可能会收到找不到活动"的异常.

3.The base app can be removed even when client app is still installed. It won't through any error messages or security exceptions at any stage. But when you try to run client app again, you may get an 'Activity not found' exception at the point where you try to call a base app activity from client app.

这篇关于关于Android中自定义权限的几个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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