0

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 ...

Sushil
  • 147
  • 1
  • 9
  • Make sure that the APK you're using is signed with the same certificate that you used when you sent an APK to the review team. This error can occur when the certificates don't match. – Alain Oct 29 '14 at 23:51
  • @Alain After I install Signed APK this error was removed but I could not receive the Token and User ID from Account Manager – Sushil Nov 04 '14 at 05:21
  • When you installed a version of your APK signed with a different key, it might have removed the account from the account manager. To make sure you're not in some weird state, could you factory reset your Glass device, re-install your Glassware from MyGlass so that an Account is sent to your device. Once the Glassware is installed, install a new version of your APK with `adb install -r`. – Alain Nov 04 '14 at 17:10

0 Answers0