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.binarywalllabs.sendit.managers.gcm.GcmIntentService.java

PendingIntent createCopyToClipboardIntent(String message) {
    Intent clipboardIntent = CopyToClipboard.createIntent(this, message, message);

    return PendingIntent.getService(this, 0, clipboardIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}

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

protected void ScheduleNextUpdate(Context context, int nCommand, long nMinTimeBetweenSend,
        boolean bEnergyEconomy) {
    if (context == null)
        return;//from   ww w  .  j a  v a2  s  .  c  o  m

    Intent intent = new Intent(MainActivity.INTENT_NAME);
    intent.putExtra(RECEIVER, mUserNasaReceiver);
    intent.putExtra(RECEIVER_SCANEX, mScanexReceiver);
    intent.putExtra(COMMAND, nCommand);
    intent.putExtra(SOURCE, mnFilter);

    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.google.android.apps.mytracks.widgets.TrackWidgetProvider.java

/**
 * Updates the stop button.//from   ww  w .  j ava2s . com
 * 
 * @param context the context
 * @param remoteViews the remote views
 * @param isRecording true if recording
 */
private void updateStopButton(Context context, RemoteViews remoteViews, boolean isRecording) {
    remoteViews.setImageViewResource(R.id.track_widget_stop_button,
            isRecording ? R.drawable.ic_stop_1 : R.drawable.ic_stop_0);
    remoteViews.setBoolean(R.id.track_widget_stop_button, "setEnabled", isRecording);
    if (isRecording) {
        Intent intent = new Intent(context, ControlRecordingService.class)
                .setAction(context.getString(R.string.track_action_end));
        PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        remoteViews.setOnClickPendingIntent(R.id.track_widget_stop_button, pendingIntent);
    }
}

From source file:cl.iluminadoschile.pako.floatingdiv.CustomOverlayService.java

@Override
protected Notification foregroundNotification(int notificationId) {
    Notification notification;//from   w ww .ja  v  a  2 s .  c o m

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
            && activation_method.equals(Constants.SETTINGS.ACTIVATION_METHOD_MANUAL)) {
        Intent settingsIntent = new Intent(Intent.ACTION_MAIN);
        settingsIntent.setClassName(Constants.ACTION.prefix, Constants.ACTION.prefix + ".SettingsActivity");
        settingsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, settingsIntent, 0);

        Intent startFgIntent = new Intent(this, CustomOverlayService.class);
        startFgIntent.setAction(Constants.ACTION.STARTFOREGROUND_ACTION);
        PendingIntent pstartFgIntent = PendingIntent.getService(this, 0, startFgIntent, 0);

        Intent pauseFgIntent = new Intent(this, CustomOverlayService.class);
        pauseFgIntent.setAction(Constants.ACTION.PAUSEFOREGROUND_ACTION);
        PendingIntent ppauseFgIntent = PendingIntent.getService(this, 0, pauseFgIntent, 0);

        Intent stopFgIntent = new Intent(this, CustomOverlayService.class);
        stopFgIntent.setAction(Constants.ACTION.STOPFOREGROUND_ACTION);
        PendingIntent pstopFgIntent = PendingIntent.getService(this, 0, stopFgIntent, 0);

        Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);

        notification = new NotificationCompat.Builder(this)
                .setContentTitle(getString(R.string.title_notification))
                .setTicker(getString(R.string.title_notification))
                .setContentText(getString(R.string.message_notification)).setSmallIcon(R.drawable.ic_launcher)
                .setLargeIcon(Bitmap.createScaledBitmap(icon, 128, 128, false)).setContentIntent(pendingIntent)
                .setOngoing(true).addAction(android.R.drawable.ic_media_play, "Start", pstartFgIntent)
                .addAction(android.R.drawable.ic_media_pause, "Pause", ppauseFgIntent)
                .addAction(android.R.drawable.ic_delete, "Stop", pstopFgIntent).build();

    } else {
        notification = new Notification(R.drawable.ic_launcher, getString(R.string.title_notification),
                System.currentTimeMillis());

        notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT
                | Notification.FLAG_ONLY_ALERT_ONCE;

        notification.setLatestEventInfo(this, getString(R.string.title_notification),
                getString(R.string.message_notification_manual), notificationIntent());
    }
    return notification;
}

From source file:com.mishiranu.dashchan.content.service.AudioPlayerService.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void refreshDownloadingNotification(boolean recreate, boolean error, Uri uri) {
    Notification.Builder builder = this.builder;
    if (builder == null || recreate) {
        builder = new Notification.Builder(this);
        builder.setSmallIcon(/*ww w . j  ava2  s  .co  m*/
                error ? android.R.drawable.stat_sys_download_done : android.R.drawable.stat_sys_download);
        builder.setDeleteIntent(PendingIntent.getService(context, 0, obtainIntent(this, ACTION_CANCEL),
                PendingIntent.FLAG_UPDATE_CURRENT));
        TypedArray typedArray = context.obtainStyledAttributes(ICON_ATTRS);
        if (error) {
            PendingIntent retryIntent = PendingIntent.getService(
                    context, 0, obtainIntent(this, ACTION_START).setData(uri)
                            .putExtra(EXTRA_CHAN_NAME, chanName).putExtra(EXTRA_FILE_NAME, fileName),
                    PendingIntent.FLAG_UPDATE_CURRENT);
            ViewUtils.addNotificationAction(builder, context, typedArray, 0, R.string.action_retry,
                    retryIntent);
        } else {
            PendingIntent cancelIntent = PendingIntent.getService(context, 0, obtainIntent(this, ACTION_CANCEL),
                    PendingIntent.FLAG_UPDATE_CURRENT);
            ViewUtils.addNotificationAction(builder, context, typedArray, 1, android.R.string.cancel,
                    cancelIntent);
        }
        typedArray.recycle();
        if (C.API_LOLLIPOP) {
            builder.setColor(notificationColor);
        }
        this.builder = builder;
    }
    if (error) {
        builder.setContentTitle(getString(R.string.message_download_completed));
        builder.setContentText(getString(R.string.message_download_result_format, 0, 1));
        notificationManager.notify(C.NOTIFICATION_ID_AUDIO_PLAYER, builder.build());
    } else {
        builder.setContentTitle(getString(R.string.message_download_audio));
        builder.setContentText(getString(R.string.message_download_name_format, fileName));
        builder.setProgress(progressMax, progress, progressMax == 0 || progress > progressMax || progress < 0);
        startForeground(C.NOTIFICATION_ID_AUDIO_PLAYER, builder.build());
    }
}

From source file:com.golden.android.eyecare.ForegroundService.java

void notify(Intent intent) {

    if (intent.getAction().equals(Constants.ACTION.STARTFOREGROUND_ACTION)) {
        Log.i(LOG_TAG, "Received Start Foreground Intent ");

        ////from w w  w . j  a  v  a  2  s. c o m
        //            Intent notificationIntent = new Intent(this, MainActivity.class);
        //            notificationIntent.setAction(Constants.ACTION.MAIN_ACTION);
        //            notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
        //                    | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        //            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
        //                    notificationIntent, 0);

        Intent notificationIntent = new Intent(this, ForegroundService.class);
        notificationIntent.setAction(Constants.ACTION.STOPFOREGROUND_ACTION);
        PendingIntent pendingIntent = PendingIntent.getService(this, 0, notificationIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        Intent previousIntent = new Intent(this, ForegroundService.class);
        previousIntent.setAction(Constants.ACTION.PREV_ACTION);
        PendingIntent ppreviousIntent = PendingIntent.getService(this, 0, previousIntent, 0);

        Intent playIntent = new Intent(this, ForegroundService.class);
        playIntent.setAction(Constants.ACTION.STOPFOREGROUND_ACTION);
        PendingIntent pplayIntent = PendingIntent.getService(this, 0, playIntent, 0);

        Intent nextIntent = new Intent(this, ForegroundService.class);
        nextIntent.setAction(Constants.ACTION.NEXT_ACTION);
        PendingIntent pnextIntent = PendingIntent.getService(this, 0, nextIntent, 0);

        Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_eye);
        Intent dialogIntent = new Intent(getApplicationContext(), Count.class);
        dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        dialogIntent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        //  startActivity(dialogIntent);
        PendingIntent pplayIntent1 = PendingIntent.getService(this, 0, dialogIntent, 0);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setContentTitle("Truiton Music Player");
        builder.setTicker("Truiton Music Player");
        builder.setContentText("My Music");
        builder.setSmallIcon(R.drawable.ic_eye);
        builder.setContentIntent(pendingIntent);
        builder.setOngoing(false);
        Notification notification = builder.build();
        startForeground(Constants.NOTIFICATION_ID.FOREGROUND_SERVICE, notification);
    } else if (intent.getAction().equals(Constants.ACTION.STOPFOREGROUND_ACTION)) {
        Log.i(LOG_TAG, "Received Stop Foreground Intent");
        launchCount();
    }
}

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

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

    String label = instance.mLabel;
    String alarmTime = AlarmUtils.getFormattedTime(context, instance.getAlarmTime());
    NotificationCompat.Builder notification = new NotificationCompat.Builder(context).setShowWhen(false)
            .setContentTitle(context.getString(com.wizardsofm.deskclock.R.string.alarm_missed_title))
            .setContentText(instance.mLabel.isEmpty() ? alarmTime
                    : context.getString(com.wizardsofm.deskclock.R.string.alarm_missed_text, alarmTime, label))
            .setColor(ContextCompat.getColor(context, com.wizardsofm.deskclock.R.color.default_background))
            .setSortKey(createSortKey(instance))
            .setSmallIcon(com.wizardsofm.deskclock.R.drawable.stat_notify_alarm)
            .setPriority(NotificationCompat.PRIORITY_HIGH).setCategory(NotificationCompat.CATEGORY_ALARM)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setLocalOnly(true);

    if (Utils.isNOrLater()) {
        notification.setGroup(MISSED_GROUP_KEY);
    }//w ww  . j a v  a2 s  . c o  m

    final int hashCode = instance.hashCode();

    // Setup dismiss intent
    Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context,
            AlarmStateManager.ALARM_DISMISS_TAG, instance, AlarmInstance.DISMISSED_STATE);
    notification.setDeleteIntent(
            PendingIntent.getService(context, hashCode, dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    // Setup content intent
    Intent showAndDismiss = AlarmInstance.createIntent(context, AlarmStateManager.class, instance.mId);
    showAndDismiss.putExtra(EXTRA_NOTIFICATION_ID, hashCode);
    showAndDismiss.setAction(AlarmStateManager.SHOW_AND_DISMISS_ALARM_ACTION);
    notification.setContentIntent(
            PendingIntent.getBroadcast(context, hashCode, showAndDismiss, PendingIntent.FLAG_UPDATE_CURRENT));

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

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

private PendingIntent pendingServiceIntent(Intent intent) {
    return PendingIntent.getService(mContext, 0, intent, FLAG_UPDATE_CURRENT);
}

From source file:com.lithiumli.fiction.PlaybackService.java

private PendingIntent createAction(String action) {
    Intent actionIntent = new Intent(getApplicationContext(), PlaybackService.class);
    actionIntent.setAction(action);//from   w  ww .  j av  a2 s  . c  o  m
    PendingIntent pit = PendingIntent.getService(getApplicationContext(), 0, actionIntent, 0);
    return pit;
}