0

Is there a way to get the current glass username/email or some identification (maybe Mac address) of a current glass user in a GDK application?

For example they are signed into gmail. I just want to know their email... For registration or to help create a unique account, Is that possible?

msj121
  • 2,812
  • 3
  • 28
  • 55

1 Answers1

4

Based on what you are trying to do, You don't need their email to create a unique ID for account. You can use Mac Address.

Code to get the Mac Address:

WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
String myMac= wifiInfo.getMacAddress();

with the permission below:

ACCESS_WIFI_STATE 

The Wifi may return null if the Wifi is diabled. Since glass has text to speech API, you can make it tell the user to enable the Wifi.

You can also use Serial Number. from android.os.Build

Build.SERIAL

Another option is to use the Android ID (Prefered method)

import android.provider.Settings.Secure;
private String androidID = Secure.getString(getContext().getContentResolver(),Secure.ANDROID_ID);

With User Account / Glass registered Email Address?

What you want to accomplish does not require you to access email the user's Email Address. If you misuse it, things will go really really bad and you must notify the user before accessing their email. You can make your own privacy policy that they will read and agree before you access their email. That's my heads up to you to avoid trouble in the future while accessing email on any device that's not yours.

To get the Email Address:

Account[] glassAccount = AccountManager.get(this).getAccountsByType("com.google");
if(glassAccount.length > 0) {
  Log.i("Glass Email: ", glassAccount[0].name); 
}

Don't know if it is possible for Glass to have more than 1 account. If so, you can loop through glassAccount to get all email addresses.

Account[] glassAccount = AccountManager.get(this).getAccountsByType("com.google");
if(glassAccount.length > 0) {
 for(int i= 0; i<glassAccount.length; i++){
     Log.i("Glass Email: ", glassAccount[i].name);
  }
}

You must use the permision below:

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

For more information. http://android-developers.blogspot.com/2011/03/identifying-app-installations.htmls:

Programmer
  • 121,791
  • 22
  • 236
  • 328
  • Hopefully someone will show me how to get an email address or something more readable, but otherwise, I will highlight yours as the answer. – msj121 Dec 18 '14 at 20:28
  • Modified my answer to show how you can get email address of the Glass user. Please read the statement I made before the code. – Programmer Dec 18 '14 at 22:18
  • I understand the implications. There will be no access to the email or spamming the user, but certainly misuse would get one banned quite quickly from glass. – msj121 Dec 19 '14 at 04:57
  • Glad you know about that. I also put that to notify others who find your question and my answer helpful. – Programmer Dec 19 '14 at 05:00