Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to get login email when using google+ to login ...

Discussion in 'Android' started by ZynGie, Nov 20, 2014.

  1. ZynGie

    ZynGie

    Joined:
    Nov 20, 2014
    Posts:
    6
    I have integrated GooglePlayGame API into my project. I had set up everything and is authenticated successful~ After authenticated I want to get the login email, any idea how to get it~??
     
  2. chimdangsung

    chimdangsung

    Joined:
    Nov 20, 2014
    Posts:
    1
    sure, you'll have to wait to receive a response from google 1 again.
     
  3. cr0lli

    cr0lli

    Joined:
    Jan 20, 2014
    Posts:
    3
  4. ZynGie

    ZynGie

    Joined:
    Nov 20, 2014
    Posts:
    6
    cr0lli, thank for ur reply, what mean "before doge release" ?? Yes, I`m using the play play-games-plugin-for-unity which is download from GitHub.
     
  5. cr0lli

    cr0lli

    Joined:
    Jan 20, 2014
    Posts:
    3
    Looks like 20 Novemeber plugin maintainers released new plugin version named 'doge' (at least commits says "Commits all the relevant code for the new doge release."). So master branch on github uses Google Play Games C++ SDK, while old code uses java plugin, which is required for my solution.
    By the way, there is another way, but it will work well only if you have 1 ggogle account on device, google for android.accounts.AccountManager.getAccountsByType
    Code (CSharp):
    1.        
    2. AndroidJavaClass jc_unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    3. AndroidJavaObject jo_Activity = jc_unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
    4. // get android.accounts.AccountManager and call android.accounts.AccountManager.getAccountsByType
    5. AndroidJavaClass jc_AccountManager = new AndroidJavaClass("android.accounts.AccountManager");
    6. AndroidJavaObject jo_AccountManager = jc_AccountManager.CallStatic<AndroidJavaObject>("get", jo_Activity);
    7. AndroidJavaObject jo_Accounts = jo_AccountManager.Call<AndroidJavaObject>("getAccountsByType", "com.google");
    8. // convert java accounts into array
    9. AndroidJavaObject[] jo_AccountsArr = AndroidJNIHelper.ConvertFromJNIArray<AndroidJavaObject[]>(jo_Accounts.GetRawObject());
    10. if (jo_AccountsArr.Length > 0) accountName = jo_AccountsArr[0].Get<string>("name");
    11.  
    This way you dont need any modifications, but if you have 2 or more accounts on android you cant be sure which one is signed in currently :(
     
    iwunu likes this.
  6. ZynGie

    ZynGie

    Joined:
    Nov 20, 2014
    Posts:
    6
    chimdangsung, thanks for ur reply, how to receive the response?? Can u show me the example code?
     
  7. ZynGie

    ZynGie

    Joined:
    Nov 20, 2014
    Posts:
    6
    cr0lli, thank for ur example, but seems not suitable for me. XD~!