简体   繁体   English

带有解析推送通知的Android M权限

[英]Android M Permissions with Parse Push Notifications

I am still a little confused about the new runtime permissions model. 我对新的运行时权限模型仍然有些困惑。 Would any of the following required permissions for Parse push notifications (GCM) require a runtime permission ? 解析推送通知(GCM)的以下任何必需权限是否需要运行时权限?

<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<uses-permission android:name="android.permission.WAKE_LOCK" />

<uses-permission android:name="android.permission.VIBRATE" />

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<uses-permission android:name="android.permission.GET_ACCOUNTS" />

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

 <permission android:protectionLevel="signature"       android:name="com.parse.starter.permission.C2D_MESSAGE" />

<uses-permission android:name="com.parse.starter.permission.C2D_MESSAGE" />

Among the permissions you listed above, GET_ACCOUNTS requires runtime check because its protection level is dangerous. 在上面列出的权限中, GET_ACCOUNTS需要运行时检查,因为它的保护级别很危险。

But the thing is, while GET_ACCOUNTS permission is no longer needed for GCM to work (starting with 7.5 Play Services, I guess), it's still needed if you're using Parse Push Notifications. 但事实是,虽然GCM不再需要GET_ACCOUNTS权限(我想是从7.5 Play服务开始),但是如果您使用解析推送通知,则仍然需要它。

It seems that in order for Parse to provide full compatibility to whole range of android powered devices (ie non GCM based devices like Kindle Fires, where GCM isn't supported and they have to fall back to their own persistent socket implementation and of course the devices with 4.0.3 and below), Parse still needs this permission and some other ones. 为了使Parse能够完全兼容所有Android设备(例如,非基于GCM的设备,例如Kindle Fires),其中不支持GCM,因此必须退回自己的持久套接字实现,当然,设备具有4.0.3及更低版本),则Parse仍需要此权限和其他一些权限。

A guy from Parse mentioned that: 来自Parse的一个人提到:

We require it being requested, aka being in AndroidManifest.xml, but don't require it being granted. 我们要求在AndroidManifest.xml中要求它,但是不要求它被授予。

the issue is in discussion, you might want to take a look at these topics : 该问题正在讨论中,您可能需要看看以下主题:

https://github.com/ParsePlatform/Parse-SDK-Android/issues/129 https://parse.com/questions/android-use-only-gcm-dont-require-additional-permissions https://github.com/ParsePlatform/Parse-SDK-Android/issues/129 https://parse.com/questions/android-use-only-gcm-dont-require-additional-permissions

The GET_ACCOUNTS permission requires the permission to be checked at runtime, since it belongs to the dangerous permissions group ( https://developer.android.com/guide/topics/security/permissions.html#normal-dangerous ). 由于GET_ACCOUNTS权限属于危险权限组( https://developer.android.com/guide/topics/security/permissions.html#normal-dangerous ),因此需要在运行时检查该权限。

The other ones are normal permissions, and will be granted as long as they are declared on the manifest file ( https://developer.android.com/guide/topics/security/normal-permissions.html ) 其他权限是普通权限,只要它们在清单文件( https://developer.android.com/guide/topics/security/normal-permissions.html )中声明,就将被授予权限。

If you realize you don't have the permission at runtime, you will need to request it, using the method requestPermissions(Activity yourActivity, String[] permissions, int requestCode) . 如果您意识到在运行时没有权限,则需要使用requestPermissions(Activity yourActivity,String [] Permissions,int requestCode)方法来请求它。 After that an non-customizable dialog will be shown to the user, requesting the permission. 之后,将向用户显示一个不可定制的对话框,请求权限。

Finally you need to override the onRequestPermissionsResult(int requestCode,String permissions[], int[] grantResults) method on your Activity, checking if the requestCode is the same requestCode you sent on requestPermissions and if the target permission was granted. 最后,您需要在Activity上重写onRequestPermissionsResult(int requestCode,StringPermission [],int [] grantResults)方法,检查requestCode是否与您在requestPermissions上发送的requestCode相同,以及是否已授予目标权限。

There are other cases you need to consider, like when the user does not grant the permission for the first time, and you still wanna ask him/her. 您还需要考虑其他情况,例如当用户首次不授予权限时,您仍然想问问他/她。 In order to known how to handle this cases I suggest you read this: http://developer.android.com/intl/pt-br/training/permissions/requesting.html . 为了知道如何处理这种情况,建议您阅读以下内容: http : //developer.android.com/intl/pt-br/training/permissions/requesting.html It also have sample codes for requesting permissions and checking the results 它还具有用于请求权限和检查结果的示例代码。

According to the Android developers documents, as long as you define these permissions in your manifest, the system will automatically grant you these permissions and will not allow the user to revoke them. 根据Android开发人员文档,只要您在清单中定义这些权限,系统就会自动为您授予这些权限,并且不允许用户撤消它们。 Therefore, you do not need to check for these permissions on runtime. 因此,您不需要在运行时检查这些权限。

https://developer.android.com/preview/features/runtime-permissions.html https://developer.android.com/preview/features/runtime-permissions.html

This is said at the bottom of the page in the Normal Permissions section. 这是在页面底部“常规权限”部分中说的。

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

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