Example usage for android.content Intent FLAG_RECEIVER_FOREGROUND

List of usage examples for android.content Intent FLAG_RECEIVER_FOREGROUND

Introduction

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

Prototype

int FLAG_RECEIVER_FOREGROUND

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

Click Source Link

Document

If set, when sending a broadcast the recipient is allowed to run at foreground priority, with a shorter timeout interval.

Usage

From source file:com.wojtechnology.sunami.TheBrain.java

private Notification.Builder getLollipopNotifBuilder(boolean isPlaying) {
    Intent notificationIntent = new Intent(this, MainActivity.class);
    notificationIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 1, notificationIntent, 0);

    Intent serviceLastIntent = new Intent(getApplicationContext(), TheBrain.class);
    serviceLastIntent.setAction(TheBrain.PLAY_LAST);
    serviceLastIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    PendingIntent pendingLastIntent = PendingIntent.getService(mContext, 1, serviceLastIntent, 0);
    Intent servicePlayIntent = new Intent(getApplicationContext(), TheBrain.class);
    servicePlayIntent.setAction(TheBrain.TOGGLE_PLAY);
    servicePlayIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    PendingIntent pendingPlayIntent = PendingIntent.getService(mContext, 1, servicePlayIntent, 0);
    Intent serviceNextIntent = new Intent(getApplicationContext(), TheBrain.class);
    serviceNextIntent.setAction(TheBrain.PLAY_NEXT);
    serviceNextIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    PendingIntent pendingNextIntent = PendingIntent.getService(mContext, 1, serviceNextIntent, 0);
    Intent serviceStopIntent = new Intent(getApplicationContext(), TheBrain.class);
    serviceStopIntent.setAction(TheBrain.PLAY_STOP);
    serviceStopIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    PendingIntent pendingStopIntent = PendingIntent.getService(mContext, 1, serviceStopIntent, 0);

    Notification.MediaStyle style = new Notification.MediaStyle();
    style.setShowActionsInCompactView(1, 2);
    Notification.Builder builder = new Notification.Builder(this).setSmallIcon(R.mipmap.sunaminotif)
            .setContentIntent(pendingIntent).setStyle(style);
    builder.addAction(R.drawable.ic_last_hint, "Last", pendingLastIntent);
    builder.addAction(isPlaying ? R.drawable.ic_pause_hint : R.drawable.ic_play_hint, "Play",
            pendingPlayIntent);/*from w w w  .j  ava 2 s  .  com*/
    builder.addAction(R.drawable.ic_next_hint, "Next", pendingNextIntent);
    builder.addAction(R.drawable.ic_stop_notif, "Stop", pendingStopIntent);
    return builder;
}

From source file:com.android.managedprovisioning.ProfileOwnerProvisioningService.java

/**
 * Notify the mdm that provisioning has completed. When the mdm has received the intent, stop
 * the service and notify the {@link ProfileOwnerProvisioningActivity} so that it can finish
 * itself./*from   w ww  .  j a v  a  2 s.c  o  m*/
 */
private void notifyMdmAndCleanup() {
    // Set DPM userProvisioningState appropriately and persist mParams for use during
    // FinalizationActivity if necessary.
    mUtils.markUserProvisioningStateInitiallyDone(this, mParams);

    if (mParams.provisioningAction.equals(ACTION_PROVISION_MANAGED_PROFILE)) {
        // Set the user_setup_complete flag on the managed-profile as setup-wizard is never run
        // for that user. This is not relevant for other cases since
        // Utils.markUserProvisioningStateInitiallyDone() communicates provisioning state to
        // setup-wizard via DPM.setUserProvisioningState() if necessary.
        mUtils.markUserSetupComplete(this, mManagedProfileOrUserInfo.id);
    }

    // If profile owner provisioning was started after current user setup is completed, then we
    // can directly send the ACTION_PROFILE_PROVISIONING_COMPLETE broadcast to the MDM.
    // But if the provisioning was started as part of setup wizard flow, we signal setup-wizard
    // should shutdown via DPM.setUserProvisioningState(), which will result in a finalization
    // intent being sent to us once setup-wizard finishes. As part of the finalization intent
    // handling we then broadcast ACTION_PROFILE_PROVISIONING_COMPLETE.
    if (mUtils.isUserSetupCompleted(this)) {
        UserHandle managedUserHandle = new UserHandle(mManagedProfileOrUserInfo.id);

        // Use an ordered broadcast, so that we only finish when the mdm has received it.
        // Avoids a lag in the transition between provisioning and the mdm.
        BroadcastReceiver mdmReceivedSuccessReceiver = new MdmReceivedSuccessReceiver(mParams.accountToMigrate,
                mParams.deviceAdminComponentName.getPackageName());

        Intent completeIntent = new Intent(ACTION_PROFILE_PROVISIONING_COMPLETE);
        completeIntent.setComponent(mParams.deviceAdminComponentName);
        completeIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES | Intent.FLAG_RECEIVER_FOREGROUND);
        if (mParams.adminExtrasBundle != null) {
            completeIntent.putExtra(EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE, mParams.adminExtrasBundle);
        }

        sendOrderedBroadcastAsUser(completeIntent, managedUserHandle, null, mdmReceivedSuccessReceiver, null,
                Activity.RESULT_OK, null, null);
        ProvisionLogger.logd(
                "Provisioning complete broadcast has been sent to user " + managedUserHandle.getIdentifier());
    }
}

From source file:com.rener.sea.DBHelper.java

public void authLogin(String username, String password) {

    String oldUsername = context//from w  w w. j  a v  a 2s. c  om
            .getSharedPreferences(context.getString(R.string.preference_file_key), Context.MODE_PRIVATE)
            .getString(context.getString(R.string.key_saved_username), null);
    String oldPassword = context
            .getSharedPreferences(context.getString(R.string.preference_file_key), Context.MODE_PRIVATE)
            .getString(context.getString(R.string.key_saved_password), null);
    String oldHash = context
            .getSharedPreferences(context.getString(R.string.preference_file_key), Context.MODE_PRIVATE)
            .getString(context.getString(R.string.key_saved_passhash), "");
    boolean log = context
            .getSharedPreferences(context.getString(R.string.preference_file_key), Context.MODE_PRIVATE)
            .getBoolean("Log", false);
    User user = findUserByUsername(username);
    boolean userN = username.equals(oldUsername);
    boolean hash = oldHash.equals(user.getPassword());
    boolean pass = password.equals(oldPassword);
    boolean exist = user.getId() != -1 ? true : false;

    if (userN && pass && hash && exist) {
        Intent intent = new Intent();
        intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
        intent.setAction("AUTH");
        intent.putExtra("AUTH_RESULT", DBSchema.LOGIN_SUCCESS);
        context.sendBroadcast(intent);

    }
    //        else if (userN && pass && hash && exist) {
    //                Intent intent = new Intent();
    //                intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    //                intent.setAction("AUTH");
    //                intent.putExtra("AUTH_RESULT", 1);
    //                context.sendBroadcast(intent);
    //            }
    //        else if ((userN && pass && !hash && exist) || exist) { // password has changed ask server for auth
    //
    //
    //
    //        }
    else { //ask db for credentials nothing local

        loginAuthentication(username, password);

        //            Intent intent = new Intent();
        //            intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
        //            intent.setAction("AUTH_RESULT");
        //            intent.putExtra("RESULT", -200);
        //            context.sendBroadcast(intent);
    }

    //            if (userN && pass && hash && exist) {
    //                Intent intent = new Intent();
    //                intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    //                intent.setAction("AUTH");
    //                intent.putExtra("AUTH_RESULT", 1);
    //                context.sendBroadcast(intent);
    //            }else {
    //            Intent intent = new Intent();
    //            intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    //            intent.setAction("AUTH");
    //            intent.putExtra("AUTH_RESULT", -200);
    //            context.sendBroadcast(intent);
    //            }
    //        }
    //
    //
    //
    //
    //        if(username.equals(oldUsername)){ // the user exist and has ben logged before
    //
    //            if(password.equals(oldPassword)){
    //                if(oldHash.equals(findUserByUsername(username).getPassword())){
    //
    //                }else{
    //                    // the password has changed
    //                    //call db
    //                    // authenticate in the server
    //                    logginAutentication(username,password);
    //
    ////                    Intent intent = new Intent();
    ////                    intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    ////                    intent.setAction("AUTH_RESULT");
    ////                    intent.putExtra("RESULT", 0); // the password has changed
    ////                    context.sendBroadcast(intent);
    //                }
    //
    //            }else { //the user exist but never logged in
    //
    //                // wrong password tray to sync
    //
    //
    //
    //
    //
    //            }
    //
    //            // send intent for for authentication
    //        }else if(username.equals(findUserByUsername(username).getUsername())){  // the user name is in the local db but i don have the password
    //
    //
    //
    //        }else{ // the user is not in the local db sync users
    //
    //        }
    //
    //        return false;
    ////        User user = findUserByUsername(username);
    //////      return user.authenticate(password);
    ////        return user.getId() == -1 ? false : true;
}

From source file:xyz.lebalex.lockscreen.MainActivity.java

private void startBackgroundService(int interval, int startTime) {
    try {/*  w  w  w.j ava2 s.  c o  m*/
        Intent alarmIntent = new Intent(this, LockScreenServiceReceiver.class);
        alarmIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
        PendingIntent pendingIntent;
        pendingIntent = PendingIntent.getBroadcast(this, 1001, alarmIntent, PendingIntent.FLAG_CANCEL_CURRENT);
        AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

        if (interval > 0) {
            Calendar curentTime = Calendar.getInstance();

            Calendar startCalen = Calendar.getInstance();
            startCalen.set(Calendar.HOUR_OF_DAY, startTime);
            startCalen.set(Calendar.MINUTE, 5);
            startCalen.set(Calendar.SECOND, 0);
            startCalen.set(Calendar.MILLISECOND, 0);

            boolean find = false;
            while (!find) {
                if (curentTime.before(startCalen))
                    find = true;
                else
                    startCalen.add(Calendar.MILLISECOND, interval);
            }

            //manager.setRepeating(AlarmManager.RTC_WAKEUP, startCalen.getTimeInMillis(), interval, pendingIntent);
            manager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, startCalen.getTimeInMillis(),
                    pendingIntent);

            SharedPreferences.Editor editor = sp.edit();
            editor.putBoolean("start_service", true);
            editor.commit();
            LogWrite.Log(this,
                    "start Alarm " + startCalen.get(Calendar.YEAR) + "-" + startCalen.get(Calendar.MONTH) + "-"
                            + startCalen.get(Calendar.DATE) + " " + startCalen.get(Calendar.HOUR_OF_DAY) + ":"
                            + startCalen.get(Calendar.MINUTE) + ":" + startCalen.get(Calendar.SECOND));
        } else {
            LogWrite.Log(this, "stop Alarm");
        }
    } catch (Exception e) {
        LogWrite.LogError(this, e.getMessage());
    }
}

From source file:com.vuze.android.remote.service.VuzeService.java

@Override
public void onTaskRemoved(Intent rootIntent) {
    if (CorePrefs.DEBUG_CORE) {
        Log.d(TAG, "onTaskRemoved: ");
    }//from  ww w  .ja v a  2 s .com

    AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(getApplicationContext(), getClass());
    intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 1, intent, 0);
}

From source file:com.android.deskclock.timer.TimerFullScreenFragment.java

private void updateTimersState(TimerObj t, String action) {
    if (Timers.DELETE_TIMER.equals(action)) {
        LogUtils.e("~~ update timer state");
        t.deleteFromSharedPref(mPrefs);/*from   ww  w. j  av  a  2 s  .  com*/
    } else {
        t.writeToSharedPref(mPrefs);
    }
    Intent i = new Intent();
    i.setAction(action);
    i.putExtra(Timers.TIMER_INTENT_EXTRA, t.mTimerId);
    // Make sure the receiver is getting the intent ASAP.
    i.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    getActivity().sendBroadcast(i);
}