targetSdkVersion 23 returns 0 length array via accountManager.getAccounts()

本秂侑毒 提交于 2019-12-04 05:15:35
Yvette Colomb

GET_ACCOUNTS is a dangerous permission and when using target sdk 23 needs to be managed with runtime permissions or it will not work.

You need to actually request permission from the user at runtime. example:

      ActivityCompat.requestPermissions(this, new String[] 
      {Manifest.permission.GET_ACCOUNTS}, 1);

      int permissionCheck = ContextCompat.checkSelfPermission(thisActivity,
      Manifest.permission.GET_ACCOUNTS);

I've gone into detail about this in this answer here.

Dangerous permissions cover areas where the app wants data or resources that involve the user's private information, or could potentially affect the user's stored data or the operation of other apps. For example, the ability to read the user's contacts is a dangerous permission. If an app declares that it needs a dangerous permission, the user has to explicitly grant the permission to the app.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!