@SuppressWarnings("deprecation") private NotificationCompat.Builder notificationBuilder(int icon, String title, String text) { return new NotificationCompat.Builder(this) .setSmallIcon(icon) .setWhen(System.currentTimeMillis()) .setOnlyAlertOnce(true) .setAutoCancel(true) .setContentText(text) .setTicker(getString(R.string.app_name)) .setContentTitle(title) .setContentIntent(getPendingIntent(null)); }
private void notifyAboutBackup(BackupState state) { NotificationCompat.Builder builder = createNotification(R.string.status_backup); notification = builder.setContentTitle(getString(R.string.status_backup)) .setContentText(state.getNotificationLabel(getResources())) .setContentIntent(getPendingIntent(null)) .build(); startForeground(BACKUP_ID, notification); }
@Override protected void handleIntent(final Intent intent) { if (intent == null) return; // NB: should not happen with START_NOT_STICKY final BackupType backupType = BackupType.fromIntent(intent); if (LOCAL_LOGV) { Log.v(TAG, "handleIntent(" + intent + ", " + (intent.getExtras() == null ? "null" : intent.getExtras().keySet()) + ", " + intent.getAction() + ", type="+backupType+")"); } appLog(R.string.app_log_backup_requested, getString(backupType.resId)); // Only start a backup if there's no other operation going on at this time. if (!isWorking() && SmsRestoreService.isServiceIdle()) { backup(backupType); } else { appLog(R.string.app_log_skip_backup_already_running); } }
private void handleErrorState(BackupState state) { if (state.isAuthException()) { appLog(R.string.app_log_backup_failed_authentication, state.getDetailedErrorMessage(getResources())); if (shouldNotifyUser(state)) { notifyUser(NOTIFICATION_ID_WARNING, notificationBuilder(stat_sys_warning, getString(R.string.notification_auth_failure), getString(getAuthPreferences().useXOAuth() ? R.string.status_auth_failure_details_xoauth : R.string.status_auth_failure_details_plain))); } } else if (state.isConnectivityError()) { appLog(R.string.app_log_backup_failed_connectivity, state.getDetailedErrorMessage(getResources())); } else if (state.isPermissionException()) { if (state.backupType != MANUAL) { Bundle extras = new Bundle(); extras.putStringArray(MainActivity.EXTRA_PERMISSIONS, state.getMissingPermissions()); notifyUser(NOTIFICATION_ID_WARNING, notificationBuilder(R.drawable.ic_notification, getString(R.string.notification_missing_permission), formatMissingPermissionDetails(getResources(), state.getMissingPermissions())) .setContentIntent(getPendingIntent(extras))); } } else { appLog(R.string.app_log_backup_failed_general_error, state.getDetailedErrorMessage(getResources())); if (shouldNotifyUser(state)) { notifyUser(NOTIFICATION_ID_WARNING, notificationBuilder(stat_sys_warning, getString(R.string.notification_general_error), state.getErrorMessage(getResources()))); } } }