- Notification notification = new Notification(R.drawable.icon, getContext().getString(R.string.sync_fail_ticker), System.currentTimeMillis());
- notification.flags |= Notification.FLAG_AUTO_CANCEL;
- // TODO put something smart in the contentIntent below
- notification.contentIntent = PendingIntent.getActivity(getContext().getApplicationContext(), (int)System.currentTimeMillis(), new Intent(), 0);
- notification.setLatestEventInfo(getContext().getApplicationContext(),
- getContext().getString(R.string.sync_fail_ticker),
- String.format(getContext().getString(R.string.sync_fail_content), getAccount().name),
- notification.contentIntent);
- ((NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE)).notify(R.string.sync_fail_ticker, notification);
+ NotificationCompat.Builder notificationBuilder = createNotificationBuilder();
+ boolean needsToUpdateCredentials = (
+ mLastFailedResult != null && (
+ mLastFailedResult.getCode() == ResultCode.UNAUTHORIZED ||
+ mLastFailedResult.isIdPRedirection()
+ )
+ );
+ if (needsToUpdateCredentials) {
+ // let the user update credentials with one click
+ Intent updateAccountCredentials = new Intent(getContext(), AuthenticatorActivity.class);
+ updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, getAccount());
+ updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION,
+ AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN);
+ updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
+ updateAccountCredentials.addFlags(Intent.FLAG_FROM_BACKGROUND);
+ notificationBuilder
+ .setTicker(i18n(R.string.sync_fail_ticker_unauthorized))
+ .setContentTitle(i18n(R.string.sync_fail_ticker_unauthorized))
+ .setContentIntent(PendingIntent.getActivity(
+ getContext(), (int)System.currentTimeMillis(), updateAccountCredentials,
+ PendingIntent.FLAG_ONE_SHOT
+ ))
+ .setContentText(i18n(R.string.sync_fail_content_unauthorized, getAccount().name));
+ } else {
+ notificationBuilder
+ .setTicker(i18n(R.string.sync_fail_ticker))
+ .setContentTitle(i18n(R.string.sync_fail_ticker))
+ .setContentText(i18n(R.string.sync_fail_content, getAccount().name));
+ }
+
+ showNotification(R.string.sync_fail_ticker, notificationBuilder);