I am trying to start the sdk android sample DrEdit disk , but I am getting an exception:
04-23 16:49:19.642: E/DriveSyncAdapter(11914): Failed to get token 04-23 16:49:19.642: W/System.err(11914): com.google.android.gms.auth.UserRecoverableAuthException: NeedPermission 04-23 16:49:19.642: W/System.err(11914): at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source) 04-23 16:49:19.642: W/System.err(11914): at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source) 04-23 16:49:19.642: W/System.err(11914): at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:192) 04-23 16:49:19.642: W/System.err(11914): at com.example.android.notepad.DriveSyncer.getDriveService(DriveSyncer.java:381) 04-23 16:49:19.642: W/System.err(11914): at com.example.android.notepad.DriveSyncer.<init>(DriveSyncer.java:94) 04-23 16:49:19.642: W/System.err(11914): at com.example.android.notepad.DriveSyncAdapter.onPerformSync(DriveSyncAdapter.java:32) 04-23 16:49:19.642: W/System.err(11914): at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:254)
ABOUT:
credential.getToken();
In DriveSyncer.getDriveService ().
I already changed my identifier in the manifest and set the appropriate rights:
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.USE_CREDENTIALS" /> <uses-permission android:name="android.permission.READ_SYNC_STATS" /> <uses-permission android:name="android.permission.READ_SYNC_SETTINGS" /> <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" /> ... <meta-data android:name="com.google.android.apps.drive.APP_ID" android:value="id=XXXXXXXX.apps.googleusercontent.com" />
It also included a disk API and set credentials.
On my Android device, it asks me for an account, but never asks for another authorization, it shows a notification, but thatβs it. However, the quick launch pattern works fine.
Code where I get the error message:
private Drive getDriveService() { if (mService == null) { try { GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(mContext, DriveScopes.DRIVE_FILE); credential.setSelectedAccountName(mAccount.name); // Trying to get a token right away to see if we are authorized credential.getToken(); Log.e("MyTag", "Never Called"); mService = new Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential).build(); } catch (Exception e) { Log.e(TAG, "Failed to get token"); // If the Exception is User Recoverable, we display a notification that will trigger the // intent to fix the issue. if (e instanceof UserRecoverableAuthException) { UserRecoverableAuthException exception = (UserRecoverableAuthException) e; (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); Intent authorizationIntent = exception.getIntent(); authorizationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags( Intent.FLAG_FROM_BACKGROUND); PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, authorizationIntent, 0); Notification notification = new Notification.Builder(mContext) .setSmallIcon(android.R.drawable.ic_dialog_alert) .setTicker("Permission requested") .setContentTitle("Permission requested") .setContentText("for account " + mAccount.name) .setContentIntent(pendingIntent).setAutoCancel(true).build(); notificationManager.notify(0, notification); } else { e.printStackTrace(); } } } return mService; }
Any ideas would be great. Thanks.