Example usage for android.app PendingIntent getService

List of usage examples for android.app PendingIntent getService

Introduction

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

Prototype

public static PendingIntent getService(Context context, int requestCode, @NonNull Intent intent,
        @Flags int flags) 

Source Link

Document

Retrieve a PendingIntent that will start a service, like calling Context#startService Context.startService() .

Usage

From source file:com.mjhram.geodata.GpsLoggingService.java

private void RequestActivityRecognitionUpdates() {
    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(getApplicationContext())
            .addApi(ActivityRecognition.API).addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {

                @Override//ww w .  j a  v  a 2  s.  com
                public void onConnectionSuspended(int arg) {
                }

                @Override
                public void onConnected(Bundle arg0) {
                    try {
                        tracer.debug("Requesting activity recognition updates");
                        Intent intent = new Intent(getApplicationContext(), GpsLoggingService.class);
                        activityRecognitionPendingIntent = PendingIntent.getService(getApplicationContext(), 0,
                                intent, PendingIntent.FLAG_UPDATE_CURRENT);
                        ActivityRecognition.ActivityRecognitionApi.requestActivityUpdates(googleApiClient,
                                AppSettings.getMinimumLoggingInterval() * 1000,
                                activityRecognitionPendingIntent);
                    } catch (Throwable t) {
                        tracer.warn(SessionLogcatAppender.MARKER_INTERNAL,
                                "Can't connect to activity recognition service", t);
                    }

                }

            }).addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {
                @Override
                public void onConnectionFailed(ConnectionResult arg0) {

                }
            });

    googleApiClient = builder.build();
    googleApiClient.connect();
}

From source file:com.lloydtorres.stately.push.TrixHelper.java

/**
 * Cancels any previous alarms set for Alphys.
 * @param c App context./*from w  ww .  ja v a2s . co  m*/
 */
public static void stopAlarmForAlphys(Context c) {
    Intent alphysIntent = new Intent(c, AlphysService.class);
    PendingIntent pendingIntent = PendingIntent.getService(c, 0, alphysIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager am = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE);
    am.cancel(pendingIntent);
}

From source file:com.wizardsofm.deskclock.alarms.AlarmNotifications.java

public static void showHighPriorityNotification(Context context, AlarmInstance instance) {
    LogUtils.v("Displaying high priority notification for alarm instance: " + instance.mId);

    mcontext = context;//from w w w .j ava 2  s.co m

    NotificationCompat.Builder notification = new NotificationCompat.Builder(context).setShowWhen(false)
            .setContentTitle(context.getString(com.wizardsofm.deskclock.R.string.alarm_alert_predismiss_title))
            .setContentText(AlarmUtils.getAlarmText(context, instance, true /* includeLabel */))
            .setColor(ContextCompat.getColor(context, com.wizardsofm.deskclock.R.color.default_background))
            .setSmallIcon(com.wizardsofm.deskclock.R.drawable.stat_notify_alarm).setAutoCancel(false)
            .setSortKey(createSortKey(instance)).setPriority(NotificationCompat.PRIORITY_HIGH)
            .setCategory(NotificationCompat.CATEGORY_ALARM).setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setLocalOnly(true);

    if (Utils.isNOrLater()) {
        notification.setGroup(UPCOMING_GROUP_KEY);
    }

    // Setup up dismiss action
    Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context,
            AlarmStateManager.ALARM_DISMISS_TAG, instance, AlarmInstance.PREDISMISSED_STATE);
    notification.addAction(com.wizardsofm.deskclock.R.drawable.ic_alarm_off_24dp,
            context.getString(com.wizardsofm.deskclock.R.string.alarm_alert_dismiss_now_text),
            PendingIntent.getService(context, instance.hashCode(), dismissIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT));

    // Setup content action if instance is owned by alarm
    Intent viewAlarmIntent = createViewAlarmIntent(context, instance);
    notification.setContentIntent(PendingIntent.getActivity(context, instance.hashCode(), viewAlarmIntent,
            PendingIntent.FLAG_UPDATE_CURRENT));

    NotificationManagerCompat nm = NotificationManagerCompat.from(context);
    nm.notify(instance.hashCode(), notification.build());
    updateAlarmGroupNotification(context);
}

From source file:de.hero.vertretungsplan.MainActivity.java

public static void setNewAlarm(Context context, boolean set, String interval) {
    Intent i = new Intent(context, de.hero.vertretungsplan.CheckForUpdates.class);
    PendingIntent pi = PendingIntent.getService(context, 0, i, 0);
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    am.cancel(pi); // cancel any existing alarms
    Log.d("MainActivity", "cancelAlarm");
    if (set) {// w  ww .  ja v a  2s .com

        long lngInterval;
        switch (interval) {
        case "1/2":
            lngInterval = AlarmManager.INTERVAL_HALF_HOUR;
            break;
        case "1":
            lngInterval = AlarmManager.INTERVAL_HOUR;
            break;
        case "6":
            lngInterval = AlarmManager.INTERVAL_HALF_DAY / 2;
            break;
        case "3":
        default:
            lngInterval = AlarmManager.INTERVAL_HOUR * 3;
            break;
        }
        Log.d("MainActivity", "setAlarm " + interval + " Stunden");
        am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME,
                SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_HALF_HOUR / 3, lngInterval, pi);
        // For debugging after 10 seconds
        // am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
        // SystemClock.elapsedRealtime() + 25000 ,
        // AlarmManager.INTERVAL_HOUR , pi);

    }
}

From source file:com.apps.howard.vicissitude.services.NotificationService.java

private void buildNotification(String message, String sender) {
    String newNotificationMessage = maybeSetNotificationMessage(sender);

    newNotificationMessage += message + System.getProperty("line.separator");

    NotificationCompat.Builder mBuilder = getNotificationBuilder(message, sender);

    // Creates an explicit intent for an Activity in your app
    Notification mNotification;//ww  w.j ava2s  .c  o  m

    Intent resultIntent = new Intent(this, NotificationService.class);
    resultIntent.setAction(sender);

    PendingIntent resultPendingIntent = PendingIntent.getService(this, 0, resultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder.setContentIntent(resultPendingIntent);
    mBuilder.setDeleteIntent(resultPendingIntent);

    mNotification = mBuilder.build();
    mNotification.flags |= Notification.FLAG_INSISTENT;

    this.lastNotificationMessage.put(sender, newNotificationMessage);

    maybeOverrideVolumeBeforeNotify();

    notificationManager.notify(sender, 1, mNotification);
    vibrator.vibrate(vibrationPattern, 0);
}

From source file:com.rks.musicx.services.NotificationHandler.java

private static void controls(RemoteViews remoteViews, RemoteViews smallViews, MusicXService musicXService) {
    PendingIntent toggleIntent = PendingIntent.getService(musicXService, 0,
            new Intent(musicXService, MusicXService.class).setAction(ACTION_TOGGLE), 0);
    PendingIntent nextIntent = PendingIntent.getService(musicXService, 0,
            new Intent(musicXService, MusicXService.class).setAction(ACTION_NEXT), 0);
    PendingIntent previousIntent = PendingIntent.getService(musicXService, 0,
            new Intent(musicXService, MusicXService.class).setAction(ACTION_PREVIOUS), 0);
    PendingIntent savefavIntent = PendingIntent.getService(musicXService, 0,
            new Intent(musicXService, MusicXService.class).setAction(ACTION_FAV), 0);

    remoteViews.setOnClickPendingIntent(R.id.toggle, toggleIntent);
    remoteViews.setOnClickPendingIntent(R.id.next, nextIntent);
    remoteViews.setOnClickPendingIntent(R.id.prev, previousIntent);
    remoteViews.setOnClickPendingIntent(R.id.action_favorite, savefavIntent);

    smallViews.setOnClickPendingIntent(R.id.small_toggle, toggleIntent);
    smallViews.setOnClickPendingIntent(R.id.small_next, nextIntent);
    smallViews.setOnClickPendingIntent(R.id.small_prev, previousIntent);
}

From source file:de.azapps.mirakel.sync.taskwarrior.services.SyncAdapter.java

private void showSyncNotification(final boolean showNotification) throws ClassNotFoundException {
    final Intent intent = new Intent(this.mContext, Class.forName(DefinitionsHelper.MAINACTIVITY_CLASS));
    intent.setAction(DefinitionsHelper.SHOW_LISTS);
    final PendingIntent p = PendingIntent.getService(this.mContext, 0, intent, 0);
    final NotificationCompat.Builder mNB = new NotificationCompat.Builder(this.mContext)
            .setContentTitle("Mirakel").setContentText("Sync").setSmallIcon(android.R.drawable.stat_notify_sync)
            .setWhen(System.currentTimeMillis()).setOngoing(true).setContentIntent(p);
    if (showNotification) {
        this.mNotificationManager.notify(SyncAdapter.NOTIFY_ID, mNB.build());
    }/*from   ww w  .j av a 2  s  .co m*/
}

From source file:com.arcusapp.soundbox.player.MediaPlayerNotification.java

private void setUpMediaPlayerActions() {
    //open the PlayActivity when the user clicks the notification
    Intent notificationIntent = new Intent(SoundBoxApplication.getContext(), MainActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent clickPendingIntent = PendingIntent.getActivity(SoundBoxApplication.getContext(), 1,
            notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    mNotificationBuilder.setContentIntent(clickPendingIntent);

    Intent togglePlayPauseIntent = new Intent(MediaPlayerService.TOGGLEPLAYPAUSE_ACTION, null,
            SoundBoxApplication.getContext(), MediaPlayerService.class);
    PendingIntent togglePlayPausePendingIntent = PendingIntent.getService(SoundBoxApplication.getContext(), 2,
            togglePlayPauseIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    mBaseView.setOnClickPendingIntent(R.id.notificationBasePlay, togglePlayPausePendingIntent);
    mExpandedView.setOnClickPendingIntent(R.id.notificationExpandedPlay, togglePlayPausePendingIntent);

    Intent nextIntent = new Intent(MediaPlayerService.NEXT_ACTION, null, SoundBoxApplication.getContext(),
            MediaPlayerService.class);
    PendingIntent nextPendingIntent = PendingIntent.getService(SoundBoxApplication.getContext(), 3, nextIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mBaseView.setOnClickPendingIntent(R.id.notificationBaseNext, nextPendingIntent);
    mExpandedView.setOnClickPendingIntent(R.id.notificationExpandedNext, nextPendingIntent);

    Intent collapseIntent = new Intent(MediaPlayerService.STOP_ACTION, null, SoundBoxApplication.getContext(),
            MediaPlayerService.class);
    PendingIntent collapsePendingIntent = PendingIntent.getService(SoundBoxApplication.getContext(), 4,
            collapseIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    mBaseView.setOnClickPendingIntent(R.id.notificationBaseCollapse, collapsePendingIntent);
    mExpandedView.setOnClickPendingIntent(R.id.notificationExpandedCollapse, collapsePendingIntent);

    Intent previousIntent = new Intent(MediaPlayerService.PREVIOUS_ACTION, null,
            SoundBoxApplication.getContext(), MediaPlayerService.class);
    PendingIntent previousPendingIntent = PendingIntent.getService(SoundBoxApplication.getContext(), 5,
            previousIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    mExpandedView.setOnClickPendingIntent(R.id.notificationExpandedPrevious, previousPendingIntent);
}

From source file:com.nextgis.firereporter.ReporterService.java

public void ScheduleNextUpdate(Context context, long nMinTimeBetweenSend, boolean bEnergyEconomy) {
    if (context == null)
        return;/*  w  w  w  . j a  v a  2 s  . c  om*/

    Intent intent = new Intent(ReporterService.ACTION_START);
    PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // The update frequency should often be user configurable.  This is not.

    long currentTimeMillis = System.currentTimeMillis();
    long nextUpdateTimeMillis = currentTimeMillis + nMinTimeBetweenSend;
    Time nextUpdateTime = new Time();
    nextUpdateTime.set(nextUpdateTimeMillis);

    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    if (bEnergyEconomy)
        alarmManager.set(AlarmManager.RTC, nextUpdateTimeMillis, pendingIntent);
    else
        alarmManager.set(AlarmManager.RTC_WAKEUP, nextUpdateTimeMillis, pendingIntent);
}

From source file:com.raddapp.radika.raddappv001.GpsLoggingService.java

private void RequestActivityRecognitionUpdates() {
    Log.d("GPSLOGSERV 101", "RequestActivityRecognitionUpdates");
    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(getApplicationContext())
            .addApi(ActivityRecognition.API).addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {

                @Override// w  w  w .j av  a2 s  .c o m
                public void onConnectionSuspended(int arg) {
                }

                @Override
                public void onConnected(Bundle arg0) {
                    try {
                        //tracer.debug("Requesting activity recognition updates");
                        Intent intent = new Intent(getApplicationContext(), GpsLoggingService.class);
                        activityRecognitionPendingIntent = PendingIntent.getService(getApplicationContext(), 0,
                                intent, PendingIntent.FLAG_UPDATE_CURRENT);
                        ActivityRecognition.ActivityRecognitionApi.requestActivityUpdates(googleApiClient,
                                60 * 1000, activityRecognitionPendingIntent); // 60 en vez de AppSettings.getMinimumLoggingInterval()
                    } catch (Throwable t) {
                        //tracer.warn(SessionLogcatAppender.MARKER_INTERNAL, "Can't connect to activity recognition service", t);
                    }

                }

            }).addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {
                @Override
                public void onConnectionFailed(ConnectionResult arg0) {

                }
            });

    googleApiClient = builder.build();
    googleApiClient.connect();
}