Android 6 getAccountName()缺少android.permission.GET_ACCOUNTS [英] Android 6 getAccountName() Missing android.permission.GET_ACCOUNTS

查看:242
本文介绍了Android 6 getAccountName()缺少android.permission.GET_ACCOUNTS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android 6设备上运行时,出现以下异常.

I get the following Exception while running on a Android 6 device.

java.lang.SecurityException: Missing android.permission.GET_ACCOUNTS

这看起来很简单,但对我来说不是. 我的清单看起来像这样:

This looks like a fairly straight forward exception, but for me it's not. My manifest looks like this:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="..." >

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

<application
    ...

引发此异常的代码段如下:

The piece of code which throws this exception is the following line:

mLoggedInEmail = Plus.AccountApi.getAccountName(mGoogleApiClient);

在android 5设备上,它可以正常工作.

On an android 5 device it works just fine.

推荐答案

从Android M API 23开始,您需要在运行时请求一些权限,然后在清单中声明它们.

Starting with Android M, API 23, you need to request some permission at runtime on top of declaring them in your manifest.

有关更多信息,请参见此链接: https://developer.android.com/training/permissions/requesting. html

See this link for more info: https://developer.android.com/training/permissions/requesting.html

作为一种快速的解决方法,您可以在build.gradle中将targetSdkVersion设置为22.

As a quick workaround, you can set your targetSdkVersion to 22 in your build.gradle.

请记住,即使有了这种解决方法,如果用户进入设置禁用应用程序权限的权限,您的应用程序也会崩溃.

Keep in mind that even with this workaround, if the user goes in setting in disable the permission for your app, your app will crash.

这是此新更改影响的权限列表:

This is the list of permissions impacted by this new change:

  • ACCESS_COARSE_LOCATION
  • ACCESS_FINE_LOCATION
  • ADD_VOICEMAIL
  • BODY_SENSORS
  • CALL_PHONE
  • 相机
  • GET_ACCOUNTS
  • PROCESS_OUTGOING_CALLS
  • READ_CALENDAR
  • READ_CALL_LOG
  • READ_CELL_BROADCASTS
  • READ_CONTACTS
  • READ_EXTERNAL_STORAGE
  • READ_PHONE_STATE
  • READ_SMS
  • RECEIVE_MMS
  • RECEIVE_SMS
  • RECEIVE_WAP_PUSH
  • RECORD_AUDIO
  • SEND_SMS
  • USE_SIP
  • WRITE_CALENDAR
  • WRITE_CALL_LOG
  • WRITE_CONTACTS
  • WRITE_EXTERNAL_STORAGE
  • ACCESS_COARSE_LOCATION
  • ACCESS_FINE_LOCATION
  • ADD_VOICEMAIL
  • BODY_SENSORS
  • CALL_PHONE
  • CAMERA
  • GET_ACCOUNTS
  • PROCESS_OUTGOING_CALLS
  • READ_CALENDAR
  • READ_CALL_LOG
  • READ_CELL_BROADCASTS
  • READ_CONTACTS
  • READ_EXTERNAL_STORAGE
  • READ_PHONE_STATE
  • READ_SMS
  • RECEIVE_MMS
  • RECEIVE_SMS
  • RECEIVE_WAP_PUSH
  • RECORD_AUDIO
  • SEND_SMS
  • USE_SIP
  • WRITE_CALENDAR
  • WRITE_CALL_LOG
  • WRITE_CONTACTS
  • WRITE_EXTERNAL_STORAGE

这篇关于Android 6 getAccountName()缺少android.permission.GET_ACCOUNTS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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