GET_ACCOUNTS permission while using GCM - Why is this needed?

前端 未结 6 1897
小鲜肉
小鲜肉 2020-12-07 20:50

I have an app, with Push notifications implemented.

I want to understand the reason why we need \"GET_ACCOUNTS\"(android.permission.GET_ACCOUNTS), while implementing

相关标签:
6条回答
  • 2020-12-07 20:54

    GET_ACCOUNT is to verify if user synced Google account in mobile, and generate the key value for each user(each Google account). This is required if the device is running a version lower than Android 4.0.4.

    0 讨论(0)
  • 2020-12-07 20:57

    The GET_ACCOUNTS permission is no longer needed for GCM to work. It used to be required for registration to GCM, but a recent Play Services update stopped using the Google account even on Froyo and Gingerbread. If you are registering to GCM with Play Services (i.e. With GoogleCloudMessaging.register), you no longer need this permission on any Android version. If you are using the deprecated library (GCMRegistrar.register), you still need a Google Account on pre 4.0.4 version, which requires that permission.

    Source (posted on android-gcm Google Group by a Google developer) :

    Some background:

    Froyo and Gingerbread registration is implemented in GoogleServicesFramework, using the Google account for registration. This has resulted in a lot of auth errors for people where the account was not in a good state.

    Starting with ICS, GCM doesn't depend or uses the Google account - you can use it before you add an account or without any accounts.

    The "Play Services" update is implementing the new scheme on all devices - but it seems a small number of devices have problems with this, we're investigating - but the numbers are far lower than those with the old scheme.

    0 讨论(0)
  • 2020-12-07 20:58

    when you use

    compile 'com.google.android.gms:play-services:7.5.0' add the build.gradle file means GET_ACCOUNT permission added automatically.

    • forexample if developer have to use only admob in project means only specify this permission in build.gradle file compile 'com.google.android.gms:play-services-ads:7.5.0' if have any another clarification see this link https://developers.google.com/android/guides/setup
    0 讨论(0)
  • 2020-12-07 21:01

    It uses an existing connection for Google services. For pre-3.0 devices, this requires users to set up their Google account on their mobile devices. A Google account is not a requirement on devices running Android 4.0.4 or higher.

    SO this is the reason for requirement of the permission

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

    to read Google account.

    Read more about this GCM Overview


    Google account login is no longer needed for GCM to work. So you no need the android.permission.GET_ACCOUNTS permission.

    If you are using GCM API with GoogleCloudMessaging.register), you no longer need to configure Google account on any Android version. But if you are using the deprecated library (GCMRegistrar.register), you still need a Google Account on older versions (before ICS).

    More details at https://groups.google.com/forum/#!topic/android-gcm/ecG-RfH-Aso. Another similer thread is Why google Account login is required for GCM to work for devices below 4.0.4 OS?

    0 讨论(0)
  • 2020-12-07 21:09

    As everyone else here has said, GET_ACCOUNT is needed for android devices lower than 4.0.4.

    If you are like me and have installed a library that automatically adds this permission but you do not need it to, you can tell the AndroidManifest to remove the permission by adding the permission to with the tools:node="remove" attribute like so:

    In your AndroidManifest.xml file, make sure the xmlns:tools attribute it defined in your manifest tag and then add the permission with remove set:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.com/tools"
              ...>
    
      ...
    
      <uses-permission android:name="android.permission.GET_ACCOUNTS" tools:node="remove" />
    
      ...
    
    </manifest>
    

    Word or warning that this never actually works for me but I know it has worked for others. If you can see what I might be doing wrong or have any more info about it, please comment!

    *Edit: There is a bug report open to get this feature working: https://bugzilla.xamarin.com/show_bug.cgi?id=48153

    0 讨论(0)
  • 2020-12-07 21:11

    I don't think this is actually the case. I tested it on a freshly factory reset Gingerbread device with a new Gmail account and I could receive GCM messages just fine without that permission. So the documentation is WRONG.

    0 讨论(0)
提交回复
热议问题