Example usage for android.content Intent FLAG_FROM_BACKGROUND

List of usage examples for android.content Intent FLAG_FROM_BACKGROUND

Introduction

In this page you can find the example usage for android.content Intent FLAG_FROM_BACKGROUND.

Prototype

int FLAG_FROM_BACKGROUND

To view the source code for android.content Intent FLAG_FROM_BACKGROUND.

Click Source Link

Document

Can be set by the caller to indicate that this Intent is coming from a background operation, not from direct user interaction.

Usage

From source file:Main.java

public static void gotoWeb(Context context, String url) {
    try {//  w  w w . j  av a 2 s. c o m
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(url));
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY
                | Intent.FLAG_FROM_BACKGROUND);
        // intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.chromium.ChromeAlarms.java

public static void triggerAlarm(Context context, Intent intent) {
    if (webView != null) {
        String name = intent.getStringExtra(ALARM_NAME_LABEL);
        String javascript = "chrome.alarms.triggerAlarm('" + name + "')";
        webView.sendJavascript(javascript);
    } else {/* w w w  .  j  a  v a  2s.  co m*/
        intent.addFlags(Intent.FLAG_FROM_BACKGROUND);
        context.startActivity(intent);
    }
}

From source file:com.secupwn.aimsicd.utils.MiscUtils.java

public static void showNotification(Context context, String tickertext, String contentText,
        @DrawableRes int drawable_id, boolean auto_cancel) {
    int NOTIFICATION_ID = 1;

    Intent notificationIntent = new Intent(context, MainActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_FROM_BACKGROUND);

    PendingIntent contentIntent = PendingIntent.getActivity(context, NOTIFICATION_ID, notificationIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), drawable_id);
    Notification notification = new NotificationCompat.Builder(context).setSmallIcon(drawable_id)
            .setLargeIcon(largeIcon).setTicker(tickertext)
            .setContentTitle(context.getResources().getString(R.string.main_app_name))
            .setContentText(contentText).setOngoing(true).setAutoCancel(auto_cancel)
            .setContentIntent(contentIntent).build();
    NotificationManagerCompat.from(context).notify(NOTIFICATION_ID, notification);
}

From source file:com.marianhello.bgloc.BootCompletedReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Log.d(TAG, "Received boot completed");
    ConfigurationDAO dao = DAOFactory.createConfigurationDAO(context);
    Config config = null;//from  w  w w . j  av  a 2  s  .  com

    try {
        config = dao.retrieveConfiguration();
    } catch (JSONException e) {
        //noop
    }

    if (config == null) {
        return;
    }

    Log.d(TAG, "Boot completed " + config.toString());

    if (config.getStartOnBoot()) {
        Log.i(TAG, "Starting service after boot");
        Intent locationServiceIntent = new Intent(context, LocationService.class);
        locationServiceIntent.addFlags(Intent.FLAG_FROM_BACKGROUND);
        locationServiceIntent.putExtra("config", config);

        context.startService(locationServiceIntent);
    }
}

From source file:com.flowzr.export.flowzr.GoogleDrivePictureClient.java

public static Drive create(Context context) throws IOException, ImportExportException, GoogleAuthException {
    String googleDriveAccount = MyPreferences.getGoogleDriveAccount(context);
    if (googleDriveAccount == null) {
        throw new ImportExportException(R.string.google_drive_account_required);
    }// w ww. j  a va  2 s.  c  o m
    try {
        List<String> scope = new ArrayList<String>();
        scope.add(DriveScopes.DRIVE_FILE);
        if (MyPreferences.isGoogleDriveFullReadonly(context)) {
            scope.add(DriveScopes.DRIVE_READONLY);
        }
        GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(context, scope);
        credential.setSelectedAccountName(googleDriveAccount);
        credential.getToken();
        return new Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential).build();
    } catch (UserRecoverableAuthException e) {
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Intent authorizationIntent = e.getIntent();
        authorizationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(Intent.FLAG_FROM_BACKGROUND);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, authorizationIntent, 0);
        Notification notification = new NotificationCompat.Builder(context)
                .setSmallIcon(android.R.drawable.ic_dialog_alert)
                .setTicker(context.getString(R.string.google_drive_permission_requested))
                .setContentTitle(context.getString(R.string.google_drive_permission_requested))
                .setContentText(context.getString(R.string.google_drive_permission_requested_for_account,
                        googleDriveAccount))
                .setContentIntent(pendingIntent).setAutoCancel(true).build();
        notificationManager.notify(0, notification);
        throw new ImportExportException(R.string.google_drive_permission_required);
    }
}

From source file:com.flowzr.budget.holo.export.flowzr.GoogleDrivePictureClient.java

public static Drive create(Context context) throws IOException, GoogleAuthException, ImportExportException {
    String googleDriveAccount = MyPreferences.getGoogleDriveAccount(context);
    if (googleDriveAccount == null) {
        throw new ImportExportException(R.string.google_drive_account_required);
    }//from   w w w .  j ava 2s  . c  om
    try {
        List<String> scope = new ArrayList<String>();
        scope.add(DriveScopes.DRIVE_FILE);
        if (MyPreferences.isGoogleDriveFullReadonly(context)) {
            scope.add(DriveScopes.DRIVE_READONLY);
        }
        GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(context, scope);
        credential.setSelectedAccountName(googleDriveAccount);
        credential.getToken();
        return new Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential).build();
    } catch (UserRecoverableAuthException e) {
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Intent authorizationIntent = e.getIntent();
        authorizationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(Intent.FLAG_FROM_BACKGROUND);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, authorizationIntent, 0);
        Notification notification = new NotificationCompat.Builder(context)
                .setSmallIcon(android.R.drawable.ic_dialog_alert)
                .setTicker(context.getString(R.string.google_drive_permission_requested))
                .setContentTitle(context.getString(R.string.google_drive_permission_requested))
                .setContentText(context.getString(R.string.google_drive_permission_requested_for_account,
                        googleDriveAccount))
                .setContentIntent(pendingIntent).setAutoCancel(true).build();
        notificationManager.notify(0, notification);
        throw new ImportExportException(R.string.google_drive_permission_required);
    }
}

From source file:org.geometerplus.android.fbreader.network.auth.ServiceNetworkContext.java

@Override
protected Map<String, String> authenticateWeb(URI uri, String realm, String authUrl, String completeUrl,
        String verificationUrl) {
    final NotificationManager notificationManager = (NotificationManager) myService
            .getSystemService(Context.NOTIFICATION_SERVICE);
    final Intent intent = new Intent(myService, WebAuthorisationScreen.class);
    intent.setData(Uri.parse(authUrl));/*  w  w w . j  a va2 s  . c o m*/
    intent.putExtra(WebAuthorisationScreen.COMPLETE_URL_KEY, completeUrl);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_FROM_BACKGROUND);
    final PendingIntent pendingIntent = PendingIntent.getActivity(myService, 0, intent, 0);
    final String text = ZLResource.resource("dialog").getResource("backgroundAuthentication")
            .getResource("message").getValue();
    final Notification notification = new NotificationCompat.Builder(myService)
            .setSmallIcon(R.drawable.fbreader).setTicker(text).setContentTitle(realm).setContentText(text)
            .setContentIntent(pendingIntent).setAutoCancel(true).build();
    notificationManager.notify(0, notification);
    return errorMap("Notification sent");
}

From source file:org.schabi.terminightor.NightKillerService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);

    if (intent != null) {
        Log.d(TAG, "get data from intent");
        try {/*from www .  jav a2  s .  c  o m*/
            alarm = Alarm.getFromCursorItem(AlarmDBOpenHelper.getAlarmDBOpenHelper(this)
                    .getReadableItem(intent.getLongExtra(Alarm.ID, -1)));
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (!alarm.isRepeatEnabled()) {
            alarm.setEnabled(false);
            AlarmDBOpenHelper.getAlarmDBOpenHelper(this).update(alarm);
        }

        indicator.saveAlarm(alarm);
    } else {
        Log.d(TAG, "get data from indicator");
        try {
            alarm = indicator.restoreAlarm(this);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    long[] pattern = { 1000, 200, 200, 200 };
    if (alarm.isVibrate()) {
        vibrator.vibrate(pattern, 0);
    }

    mediaPlayer = setupNewMediaPlayer(alarm);
    mediaPlayer.start();

    alarmActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
            | Intent.FLAG_FROM_BACKGROUND);
    alarmActivityIntent.putExtra(Alarm.ID, alarm.getId());
    alarmActivityIntent.putExtra(Alarm.NAME, alarm.getName());
    alarmActivityIntent.putExtra(Alarm.NFC_TAG_ID, alarm.getNfcTagId());
    this.startActivity(alarmActivityIntent);

    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Notification n = new NotificationCompat.Builder(this).setContentTitle(getString(R.string.alarm))
            .setContentText(alarm.getName()).setSmallIcon(R.drawable.terminightor_notify_small).setOngoing(true)
            .build();
    n.contentIntent = PendingIntent.getActivity(this.getApplicationContext(),
            SpecialPendingIds.OPEN_ALARM_ACTIVITY, alarmActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    nm.notify(NOTIFICATION_ID, n);

    return START_STICKY;
}

From source file:br.com.bioscada.apps.biotracks.io.sendtogoogle.SendToGoogleUtils.java

/**
 * Sends a notification to request permission.
 * /*  www. j  a va2  s.  c  om*/
 * @param context the context
 * @param accountName the account name
 * @param intent the intent
 * @param notificaitonId the notification id
 */
public static void sendNotification(Context context, String accountName, Intent intent, int notificaitonId) {
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(Intent.FLAG_FROM_BACKGROUND);

    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setAutoCancel(true)
            .setContentIntent(pendingIntent)
            .setContentText(context.getString(R.string.permission_request_message, accountName))
            .setContentTitle(context.getString(R.string.permission_request_title))
            .setSmallIcon(android.R.drawable.ic_dialog_alert)
            .setTicker(context.getString(R.string.permission_request_title));
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(notificaitonId, builder.build());
}

From source file:com.cloverstudio.spika.GCMIntentService.java

@SuppressWarnings("deprecation")
public void triggerNotification(Context context, String message, String fromName, Bundle pushExtras) {

    if (fromName != null) {
        final NotificationManager notificationManager = (NotificationManager) getSystemService(
                NOTIFICATION_SERVICE);/*from  w  ww.  j  a  v  a2  s. c  om*/
        Notification notification = new Notification(R.drawable.icon_notification, message,
                System.currentTimeMillis());
        notification.number = mNotificationCounter + 1;
        mNotificationCounter = mNotificationCounter + 1;

        Intent intent = new Intent(this, SplashScreenActivity.class);
        intent.replaceExtras(pushExtras);
        intent.putExtra(Const.PUSH_INTENT, true);
        intent.setAction(Long.toString(System.currentTimeMillis()));
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND
                | Intent.FLAG_ACTIVITY_TASK_ON_HOME);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, notification.number, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        notification.setLatestEventInfo(this, context.getString(R.string.app_name), message, pendingIntent);
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notification.defaults |= Notification.DEFAULT_SOUND;
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        String notificationId = Double.toString(Math.random());
        notificationManager.notify(notificationId, 0, notification);
    }
}