Retrieve the Auth Token in GDK
After Inserting the Mirror Account Successfully
Now getting the Auth Token in APK side (GDK side).
Mainfest.xml
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
Activity Code :
AccountManager accountManager = AccountManager.get(this);
// Use your Glassware's account type.
Account[] accounts = accountManager.getAccountsByType(ACCOUNT_TYPE);//Same Account_type which was passed from Mirror API
if (accounts != null && accounts.length > 0) {
Log.d("MainActivity ", "MainActivity Account");
for (int i =0;i<accounts.length;i++)
{
accountManager.getAuthToken(accounts[i], AUTH_TOKEN_TYPE, null, this, new AccountManagerCallback<Bundle>() {
public void run(AccountManagerFuture<Bundle> future) {
try {
Log.d("MainActivity ", "MainActivity AccountManagerFuture");
UserId = future.getResult().getString("USERID"); // Line Number 133
Log.d("EOS_USERID ","UserId :-"+ UserId);
String token = future.getResult().getString(AccountManager.KEY_AUTHTOKEN);
Log.d("token","token :-"+ token);
// Use the token.
} catch (Exception e) {
// Handle exception.
e.printStackTrace();
}
}
}, null);
}
I getting the Following error
10-29 18:00:31.718 13219-13219/com.whitehedge.glassware_eos W/System.err﹕ android.accounts.OperationCanceledException
10-29 18:00:31.718 13219-13219/com.whitehedge.glassware_eos W/System.err﹕ at android.accounts.AccountManager$AmsTask.internalGetResult(AccountManager.java:1503)
10-29 18:00:31.718 13219-13219/com.whitehedge.glassware_eos W/System.err﹕ at android.accounts.AccountManager$AmsTask.getResult(AccountManager.java:1531)
10-29 18:00:31.718 13219-13219/com.whitehedge.glassware_eos W/System.err﹕ at android.accounts.AccountManager$AmsTask.getResult(AccountManager.java:1452)
10-29 18:00:31.718 13219-13219/com.whitehedge.glassware_eos W/System.err﹕ at com.whitehedge.glassware_eos.MainActivity$1.run(MainActivity.java:133)
10-29 18:00:31.718 13219-13219/com.whitehedge.glassware_eos W/System.err﹕ at android.accounts.AccountManager$11.run(AccountManager.java:1427)
10-29 18:00:31.718 13219-13219/com.whitehedge.glassware_eos W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:733)
10-29 18:00:31.718 13219-13219/com.whitehedge.glassware_eos W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:95)
10-29 18:00:31.718 13219-13219/com.whitehedge.glassware_eos W/System.err﹕ at android.os.Looper.loop(Looper.java:149)
10-29 18:00:31.718 13219-13219/com.whitehedge.glassware_eos W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5045)
10-29 18:00:31.718 13219-13219/com.whitehedge.glassware_eos W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
10-29 18:00:31.726 13219-13219/com.whitehedge.glassware_eos W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:515)
10-29 18:00:31.726 13219-13219/com.whitehedge.glassware_eos W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-29 18:00:31.726 13219-13219/com.whitehedge.glassware_eos W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
10-29 18:00:31.726 13219-13219/com.whitehedge.glassware_eos W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)
Please where i am going wrong ...