Example usage for android.app PendingIntent FLAG_NO_CREATE

List of usage examples for android.app PendingIntent FLAG_NO_CREATE

Introduction

In this page you can find the example usage for android.app PendingIntent FLAG_NO_CREATE.

Prototype

int FLAG_NO_CREATE

To view the source code for android.app PendingIntent FLAG_NO_CREATE.

Click Source Link

Document

Flag indicating that if the described PendingIntent does not already exist, then simply return null instead of creating it.

Usage

From source file:com.gpsmobitrack.gpstracker.MenuItems.SettingsPage.java

/**
 * Start the alarm service /*from   w  w w. j  av a2 s.  c  om*/
 * @param pos
 */
private void startAlarmService(int pos) {
    editor.putLong(AppConstants.FREQ_UPDATE_PREF, updateDurationValue[pos]);
    editor.commit();
    int updateTimeint = updateDurationValue[pos];
    AlarmManager alarm = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
    Calendar cal = Calendar.getInstance();
    Intent intent2 = new Intent(getActivity(), BackgroundService.class);
    PendingIntent pintent = PendingIntent.getService(getActivity(), 0, intent2, 0);
    if (PendingIntent.getService(getActivity(), 0, intent2, PendingIntent.FLAG_NO_CREATE) != null) {
        alarm.cancel(pintent);
    }
    alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), (updateTimeint * 1000 * 60), pintent);
}

From source file:opensource.zeocompanion.ZeoCompanionApplication.java

private void configAlarmManagerToPrefs() {
    // setup a daily alarm if auto-emailing is enabled
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    boolean enabledAutoEmail = prefs.getBoolean("email_auto_enable", false);
    boolean enabledDatabaseReplicate = prefs.getBoolean("database_replicate_zeo", false);
    long desiredTOD = prefs.getLong("email_auto_send_time", 0); // will default to midnight
    long configuredTOD = prefs.getLong("email_auto_send_time_configured", 0); // will default to midnight

    // determine whether there is an active AlarmManager entry that we have established
    AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
    Intent intentCheck = new Intent(this, ZeoCompanionApplication.AlarmReceiver.class);
    intentCheck.setAction(ZeoCompanionApplication.ACTION_ALARMMGR_WAKEUP_RTC);
    PendingIntent existingPi = PendingIntent.getBroadcast(this, 0, intentCheck, PendingIntent.FLAG_NO_CREATE);

    if (enabledAutoEmail || enabledDatabaseReplicate) {
        // Daily AlarmManager is needed
        if (existingPi != null && desiredTOD != configuredTOD) {
            // there is an existing AlarmManager entry, but it has the incorrect starting time-of-day;
            // so cancel it, and rebuild a new one
            Intent intent1 = new Intent(this, ZeoCompanionApplication.AlarmReceiver.class);
            intent1.setAction(ZeoCompanionApplication.ACTION_ALARMMGR_WAKEUP_RTC);
            PendingIntent pi1 = PendingIntent.getBroadcast(this, 0, intent1, PendingIntent.FLAG_CANCEL_CURRENT);
            am.cancel(pi1);//w  w w . j a v  a  2s  .c  om
            pi1.cancel();
            existingPi = null;
        }
        if (existingPi == null) {
            // there is no existing AlarmManager entry, so create it
            Date dt = new Date(desiredTOD);
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.HOUR_OF_DAY, dt.getHours());
            calendar.set(Calendar.MINUTE, dt.getMinutes());
            calendar.set(Calendar.SECOND, dt.getSeconds());
            Intent intent2 = new Intent(this, ZeoCompanionApplication.AlarmReceiver.class);
            intent2.setAction(ZeoCompanionApplication.ACTION_ALARMMGR_WAKEUP_RTC);
            PendingIntent pi2 = PendingIntent.getBroadcast(this, 0, intent2, PendingIntent.FLAG_UPDATE_CURRENT);
            am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY,
                    pi2);
            SharedPreferences.Editor editor = prefs.edit();
            editor.putLong("email_auto_send_time_configured", desiredTOD);
            editor.commit();
        }

    } else {
        // Daily AlarmManager is not needed
        if (existingPi != null) {
            // there is an AlarmManager entry pending; need to cancel it
            Intent intent3 = new Intent(this, ZeoCompanionApplication.AlarmReceiver.class);
            intent3.setAction(ZeoCompanionApplication.ACTION_ALARMMGR_WAKEUP_RTC);
            PendingIntent pi3 = PendingIntent.getBroadcast(this, 0, intent3, PendingIntent.FLAG_CANCEL_CURRENT);
            am.cancel(pi3);
            pi3.cancel();
        }
    }
}

From source file:edu.mit.media.funf.probe.Probe.java

/**
 * Resets all of the run data information, and removes all requests
 *///from   w w w. j  av a  2 s  .  c  o m
public void reset() {
    getHistoryPrefs().edit().clear().commit();
    if (requestsIntent != null) {
        requestsIntent.removeExtra(INTERNAL_REQUESTS_KEY);
    }
    PendingIntent selfLaunchingIntent = PendingIntent.getService(this, 0, getRequestsIntent(),
            PendingIntent.FLAG_NO_CREATE);
    if (selfLaunchingIntent != null) {
        selfLaunchingIntent.cancel();
    }
}

From source file:cw.kop.autobackground.LiveWallpaperService.java

private void startAlarms() {
    if (AppSettings.useTimer() && AppSettings.getTimerDuration() > 0
            && PendingIntent.getBroadcast(getApplicationContext(), 0,
                    new Intent(LiveWallpaperService.DOWNLOAD_WALLPAPER),
                    PendingIntent.FLAG_NO_CREATE) != null) {

        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        calendar.set(Calendar.HOUR_OF_DAY, AppSettings.getTimerHour());
        calendar.set(Calendar.MINUTE, AppSettings.getTimerMinute());

        alarmManager.cancel(pendingDownloadIntent);

        if (calendar.getTimeInMillis() > System.currentTimeMillis()) {
            alarmManager.setInexactRepeating(AlarmManager.RTC, calendar.getTimeInMillis(),
                    AppSettings.getTimerDuration(), pendingDownloadIntent);
        } else {/*w w  w.j  av a2s .c  om*/
            alarmManager.setInexactRepeating(AlarmManager.RTC,
                    calendar.getTimeInMillis() + AlarmManager.INTERVAL_DAY, AppSettings.getTimerDuration(),
                    pendingDownloadIntent);
        }
    }
    if (AppSettings.useInterval() && AppSettings.getIntervalDuration() > 0
            && PendingIntent.getBroadcast(getApplicationContext(), 0,
                    new Intent(LiveWallpaperService.UPDATE_WALLPAPER), PendingIntent.FLAG_NO_CREATE) != null) {
        alarmManager.setInexactRepeating(AlarmManager.RTC,
                System.currentTimeMillis() + AppSettings.getIntervalDuration(),
                AppSettings.getIntervalDuration(), pendingIntervalIntent);
    }
}

From source file:com.android.deskclock.data.TimerModel.java

/**
 * Updates the callback given to this application from the {@link AlarmManager} that signals the
 * expiration of the next timer. If no timers are currently set to expire (i.e. no running
 * timers exist) then this method clears the expiration callback from AlarmManager.
 *///from ww  w  .  j a  v  a2 s .  c  o m
private void updateAlarmManager() {
    // Locate the next firing timer if one exists.
    Timer nextExpiringTimer = null;
    for (Timer timer : getMutableTimers()) {
        if (timer.isRunning()) {
            if (nextExpiringTimer == null) {
                nextExpiringTimer = timer;
            } else if (timer.getExpirationTime() < nextExpiringTimer.getExpirationTime()) {
                nextExpiringTimer = timer;
            }
        }
    }

    // Build the intent that signals the timer expiration.
    final Intent intent = TimerService.createTimerExpiredIntent(mContext, nextExpiringTimer);

    if (nextExpiringTimer == null) {
        // Cancel the existing timer expiration callback.
        final PendingIntent pi = PendingIntent.getService(mContext, 0, intent,
                PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_NO_CREATE);
        if (pi != null) {
            mAlarmManager.cancel(pi);
            pi.cancel();
        }
    } else {
        // Update the existing timer expiration callback.
        final PendingIntent pi = PendingIntent.getService(mContext, 0, intent,
                PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);
        schedulePendingIntent(nextExpiringTimer.getExpirationTime(), pi);
    }
}

From source file:com.gpsmobitrack.gpstracker.MenuItems.SettingsPage.java

/**
 *  Background updates show ON or OFF/*from ww w.ja  v a 2s  .c  o m*/
 */
private void showAlert(String Message, String Title, final int alertCode) {
    final Dialog dialog = new Dialog(getActivity(), android.R.style.Theme_Translucent);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCancelable(false);
    dialog.setContentView(R.layout.alert_dialog_main);
    final TextView alertTitle = (TextView) dialog.findViewById(R.id.alert_title);
    final TextView alertMsg = (TextView) dialog.findViewById(R.id.alert_msg);
    final EditText alertEditTxt = (EditText) dialog.findViewById(R.id.alert_edit_txt);
    Button okBtn = (Button) dialog.findViewById(R.id.alert_ok_btn);
    Button cancelBtn = (Button) dialog.findViewById(R.id.alert_cancel_btn);
    alertTitle.setText(Title);
    alertMsg.setText(Message);
    alertEditTxt.setVisibility(View.GONE);
    if (alertCode == 0 || alertCode == UPDATE_INT || alertCode == 7) {
        cancelBtn.setVisibility(View.VISIBLE);
    } else {
        cancelBtn.setVisibility(View.GONE);
    }
    cancelBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
            if (alertCode == 7) {
                backUpdateToggle.setChecked(true);
                editor.putBoolean(AppConstants.IS_SERVICE_ENABLED_PREF, true);
                editor.commit();
            }
        }
    });
    okBtn.setOnClickListener(new OnClickListener() {
        @SuppressWarnings("unused")
        @Override
        public void onClick(View v) {
            dialog.dismiss();
            if (alertCode == 3 || alertCode == 4) {

                session.logoutUser(getActivity());
                Intent i = new Intent(getActivity(), Login.class);
                startActivity(i);
                getActivity().finish();
            } else if (alertCode == 0) {
                deactivateAcc();
            } else if (alertCode == UPDATE_INT) {
                getActivity().finish();
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse("market://details?id=com.gpstracker.pro"));
                startActivity(intent);
            } else if (alertCode == 7) {
                backUpdateToggle.setChecked(false);
                editor.putBoolean(AppConstants.IS_SERVICE_ENABLED_PREF, false);
                editor.commit();
                AlarmManager alarm = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
                Calendar cal = Calendar.getInstance();
                Intent intent2 = new Intent(getActivity(), BackgroundService.class);
                PendingIntent pintent = PendingIntent.getService(getActivity(), 0, intent2, 0);
                if (PendingIntent.getService(getActivity(), 0, intent2, PendingIntent.FLAG_NO_CREATE) != null) {
                    alarm.cancel(pintent);
                }
            }
        }
    });
    dialog.show();
}

From source file:com.androidinspain.deskclock.data.TimerModel.java

/**
 * Updates the callback given to this application from the {@link AlarmManager} that signals the
 * expiration of the next timer. If no timers are currently set to expire (i.e. no running
 * timers exist) then this method clears the expiration callback from AlarmManager.
 *//*from  w w w .ja  v  a2s.co  m*/
private void updateAlarmManager() {
    // Locate the next firing timer if one exists.
    Timer nextExpiringTimer = null;
    for (Timer timer : getMutableTimers()) {
        if (timer.isRunning()) {
            if (nextExpiringTimer == null) {
                nextExpiringTimer = timer;
            } else if (timer.getExpirationTime() < nextExpiringTimer.getExpirationTime()) {
                nextExpiringTimer = timer;
            }
        }
    }

    // Build the intent that signals the timer expiration.
    final Intent intent = TimerService.createTimerExpiredIntent(mContext, nextExpiringTimer);

    if (nextExpiringTimer == null) {
        // Cancel the existing timer expiration callback.
        final PendingIntent pi = PendingIntent.getService(mContext, 0, intent,
                PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_NO_CREATE);
        if (pi != null) {
            mAlarmManager.cancel(pi);
            pi.cancel();
        }
    } else {
        // Update the existing timer expiration callback.
        final PendingIntent pi = PendingIntent.getService(mContext, 0, intent,
                PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);
        schedulePendingIntent(mAlarmManager, nextExpiringTimer.getExpirationTime(), pi);
    }
}

From source file:me.tatarka.support.internal.job.JobStore.java

private void unmarkForBootSession(JobStatus jobStatus) {
    Intent intent = new Intent(mContext, JobSchedulerService.class).setAction(jobStatus.toShortString());
    PendingIntent pendingIntent = PendingIntent.getService(mContext, jobStatus.getJobId(), intent,
            PendingIntent.FLAG_NO_CREATE);
    if (pendingIntent != null) {
        AlarmManager am = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
        am.cancel(pendingIntent);//from   w  w w  .  ja v  a 2  s.  co m
        pendingIntent.cancel();
    }
}

From source file:me.tatarka.support.internal.job.JobStore.java

private boolean isMarkedForBootSession(JobStatus jobStatus) {
    Intent intent = new Intent(mContext, JobSchedulerService.class).setAction(jobStatus.toShortString());
    PendingIntent pendingIntent = PendingIntent.getService(mContext, jobStatus.getJobId(), intent,
            PendingIntent.FLAG_NO_CREATE);
    return pendingIntent != null;
}

From source file:com.umundus.service.NCallServiceOld.java

public void onCreate() {
    Log.d(TAG, "[*]Service-onCreate");
    super.onCreate();

    IntentFilter filter = new IntentFilter(ACTION_START_PATTERN_SEND_DATA);
    filter.addAction(ACTION_END_PATTERN_SEND_DATA);
    registerReceiver(mBroadcastReceiver, filter);

    int myID = 1234;
    Intent intent = new Intent(this, NCallServiceOld.class);
    //PendingIntent pendIntent = PendingIntent.getActivity(this, 0, bindIntent, 0);
    PendingIntent pi = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_NO_CREATE);
    Notification notice = new Notification.Builder(this).setContentTitle("(Rang)")
            .setContentText("(Rang)? .").setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)).setOngoing(true)
            .setContentIntent(pi).build();
    notice.flags |= Notification.FLAG_NO_CLEAR;
    notice.flags |= Notification.FLAG_ONGOING_EVENT;
    startForeground(myID, notice);/*from   w w  w. ja  v  a 2s.co  m*/

    AlarmManager al = (AlarmManager) this.getSystemService(this.ALARM_SERVICE);
    al.setRepeating(AlarmManager.RTC, System.currentTimeMillis(), 1000 * 15, pi);
}