Get Google Glass Name or Email

2019-06-10 17:18发布

问题:

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?

回答1:

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: