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.olearyp.gusto.Expsetup.java

protected void sendCommand(final String command, final String description, final String state) {
    final Intent runCmd = new Intent("com.olearyp.gusto.SUEXEC");
    runCmd.setData(//  w  ww  . ja v  a 2 s  .c om
            Uri.fromParts("command", ". /system/bin/exp_script.sh.lib && read_in_ep_config && " + command, ""))
            .putExtra("com.olearyp.gusto.STATE", state);
    final Notification note = new Notification(R.drawable.icon,
            description.substring(0, 1).toUpperCase() + description.substring(1) + "...",
            System.currentTimeMillis());
    note.setLatestEventInfo(Expsetup.this, getString(R.string.app_name),
            getString(R.string.app_name) + " is " + description + "...",
            PendingIntent.getBroadcast(Expsetup.this, 0, null, 0));
    runCmd.putExtra("com.olearyp.gusto.RUN_NOTIFICATION", note);
    startService(runCmd);
    setServerState(state);
    if (getServerState().equals(getString(R.string.reboot_manual_flash_required))) {
        final Intent intent = new Intent("com.olearyp.gusto.SUEXEC")
                .setData(Uri.fromParts("commandid", Integer.toString(R.string.reboot_recovery), ""));
        final PendingIntent contentIntent = PendingIntent.getService(this, 0, intent, 0);
        final Notification rebootNote = new Notification(R.drawable.status_reboot,
                getString(R.string.reboot_recovery_required_msg), System.currentTimeMillis());
        rebootNote.setLatestEventInfo(this, "GUSTO reboot request",
                getString(R.string.reboot_recovery_doit_msg), contentIntent);
        rebootNote.deleteIntent = PendingIntent.getBroadcast(this, 0,
                new Intent("com.olearyp.gusto.RESET_SERVER_STATE"), 0);
        rebootNote.flags |= Notification.FLAG_SHOW_LIGHTS;
        rebootNote.ledOnMS = 200;
        rebootNote.ledOffMS = 400;
        rebootNote.ledARGB = Color.argb(255, 255, 0, 0);
        nm.notify(REBOOT_NOTIFICATION, rebootNote);
    } else if (getServerState().equals(getString(R.string.reboot_recovery_required))) {
        final Intent intent = new Intent("com.olearyp.gusto.SUEXEC")
                .setData(Uri.fromParts("commandid", Integer.toString(R.string.reboot), ""));
        final PendingIntent contentIntent = PendingIntent.getService(this, 0, intent, 0);
        final Notification rebootNote = new Notification(R.drawable.status_reboot,
                getString(R.string.reboot_autoflash_required_msg), System.currentTimeMillis());
        rebootNote.setLatestEventInfo(this, "GUSTO reboot request",
                getString(R.string.reboot_autoflash_doit_msg), contentIntent);
        rebootNote.deleteIntent = PendingIntent.getBroadcast(this, 0,
                new Intent("com.olearyp.gusto.RESET_SERVER_STATE"), 0);
        rebootNote.flags |= Notification.FLAG_SHOW_LIGHTS;
        rebootNote.ledOnMS = 200;
        rebootNote.ledOffMS = 600;
        rebootNote.ledARGB = Color.argb(255, 255, 255, 0);
        nm.notify(REBOOT_NOTIFICATION, rebootNote);
    } else if (getServerState().equals(getString(R.string.reboot_required))) {
        final Intent intent = new Intent("com.olearyp.gusto.SUEXEC")
                .setData(Uri.fromParts("commandid", Integer.toString(R.string.reboot), ""));
        final PendingIntent contentIntent = PendingIntent.getService(this, 0, intent, 0);
        final Notification rebootNote = new Notification(R.drawable.status_reboot,
                getString(R.string.reboot_required_msg), System.currentTimeMillis());
        rebootNote.setLatestEventInfo(this, "GUSTO reboot request", getString(R.string.reboot_doit_msg),
                contentIntent);
        rebootNote.deleteIntent = PendingIntent.getBroadcast(this, 0,
                new Intent("com.olearyp.gusto.RESET_SERVER_STATE"), 0);
        rebootNote.flags |= Notification.FLAG_SHOW_LIGHTS;
        rebootNote.ledOnMS = 200;
        rebootNote.ledOffMS = 600;
        rebootNote.ledARGB = Color.argb(255, 255, 255, 0);
        nm.notify(REBOOT_NOTIFICATION, rebootNote);
    }
}

From source file:com.negaheno.android.NotificationsController.java

private void scheduleNotificationRepeat() {
    try {/*from   www .j  a  v  a  2  s. com*/
        AlarmManager alarm = (AlarmManager) ApplicationLoader.applicationContext
                .getSystemService(Context.ALARM_SERVICE);
        PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0,
                new Intent(ApplicationLoader.applicationContext, NotificationRepeat.class), 0);
        SharedPreferences preferences = ApplicationLoader.applicationContext
                .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
        int minutes = preferences.getInt("repeat_messages", 60);
        if (minutes > 0 && personal_count > 0) {
            alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + minutes * 60 * 1000,
                    pintent);
        } else {
            alarm.cancel(pintent);
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}

From source file:biz.bokhorst.bpt.BPTService.java

private Notification getNotification(String text) {
    // Build intent
    Intent toLaunch = new Intent(this, BackPackTrack.class);
    toLaunch.setAction("android.intent.action.MAIN");
    toLaunch.addCategory("android.intent.category.LAUNCHER");
    toLaunch.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    // Build pending intent
    PendingIntent intentBack = PendingIntent.getActivity(this, 0, toLaunch, PendingIntent.FLAG_UPDATE_CURRENT);

    // Build result intent update
    Intent resultIntentUpdate = new Intent(this, BPTService.class);
    resultIntentUpdate.setAction("Update");

    // Build pending intent waypoint
    PendingIntent pendingIntentUpdate = PendingIntent.getService(this, 2, resultIntentUpdate,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Build result intent waypoint
    Intent resultIntentWaypoint = new Intent(this, BPTService.class);
    resultIntentWaypoint.setAction("Waypoint");

    // Build pending intent waypoint
    PendingIntent pendingIntentWaypoint = PendingIntent.getService(this, 2, resultIntentWaypoint,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Build notification
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
    notificationBuilder.setSmallIcon(R.drawable.icon);
    notificationBuilder.setContentTitle(getString(R.string.app_name));
    notificationBuilder.setContentText(text);
    notificationBuilder.setContentIntent(intentBack);
    notificationBuilder.setWhen(System.currentTimeMillis());
    notificationBuilder.setAutoCancel(true);
    notificationBuilder.addAction(android.R.drawable.ic_menu_mylocation, getString(R.string.Update),
            pendingIntentUpdate);/*from  w  ww .jav a 2 s.  c o  m*/
    notificationBuilder.addAction(android.R.drawable.ic_menu_add, getString(R.string.Waypoint),
            pendingIntentWaypoint);
    Notification notification = notificationBuilder.build();
    return notification;
}

From source file:com.chen.mail.utils.NotificationActionUtils.java

public static Notification createUndoNotification(final Context context,
        final NotificationAction notificationAction, final int notificationId) {
    LogUtils.i(LOG_TAG, "createUndoNotification for %s", notificationAction.getNotificationActionType());

    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

    builder.setSmallIcon(R.drawable.stat_notify_email);
    builder.setWhen(notificationAction.getWhen());

    final RemoteViews undoView = new RemoteViews(context.getPackageName(), R.layout.undo_notification);
    undoView.setTextViewText(R.id.description_text, context.getString(notificationAction.getActionTextResId()));

    final String packageName = context.getPackageName();

    final Intent clickIntent = new Intent(NotificationActionIntentService.ACTION_UNDO);
    clickIntent.setPackage(packageName);
    putNotificationActionExtra(clickIntent, notificationAction);
    final PendingIntent clickPendingIntent = PendingIntent.getService(context, notificationId, clickIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    undoView.setOnClickPendingIntent(R.id.status_bar_latest_event_content, clickPendingIntent);

    builder.setContent(undoView);/*from  w  ww.  ja va 2  s  . co  m*/

    // When the notification is cleared, we perform the destructive action
    final Intent deleteIntent = new Intent(NotificationActionIntentService.ACTION_DESTRUCT);
    deleteIntent.setPackage(packageName);
    putNotificationActionExtra(deleteIntent, notificationAction);
    final PendingIntent deletePendingIntent = PendingIntent.getService(context, notificationId, deleteIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    builder.setDeleteIntent(deletePendingIntent);

    final Notification notification = builder.build();

    return notification;
}

From source file:com.amazonaws.mobileconnectors.pinpoint.targeting.notification.NotificationClient.java

private PendingIntent createOpenAppPendingIntent(final Bundle pushBundle, final Class<?> targetClass,
        final String campaignId, final int requestId, final String intentAction) {
    PendingIntent contentIntent = null;/*from  w w w  .  j av a 2s. co m*/
    if (intentAction.equals(GCM_INTENT_ACTION)) {
        contentIntent = PendingIntent.getService(pinpointContext.getApplicationContext(), requestId,
                this.notificationIntent(pushBundle, campaignId, requestId, GCM_INTENT_ACTION, targetClass),
                PendingIntent.FLAG_ONE_SHOT);
    } else {
        contentIntent = PendingIntent.getBroadcast(pinpointContext.getApplicationContext(), requestId,
                this.notificationIntent(pushBundle, campaignId, requestId, FCM_INTENT_ACTION, targetClass),
                PendingIntent.FLAG_ONE_SHOT);
        PinpointNotificationReceiver.setNotificationClient(this);
    }
    return contentIntent;

}

From source file:com.bangz.smartmute.services.LocationMuteService.java

private void NotificationUserFailed() {

    NotificationCompat.Builder nb = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_notification)
            .setColor(getResources().getColor(R.color.theme_accent_2))
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setAutoCancel(true);

    //        LocationManager lm = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
    //        boolean bProviderEnabled =
    //                lm.isProviderEnabled(LocationManager.GPS_PROVIDER) |
    //                lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

    int locationmode = ApiAdapterFactory.getApiAdapter().getLocationMode(this);
    if (locationmode <= ApiAdapter.LOCATION_MODE_SENSORS_ONLY) {
        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        PendingIntent pi = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        nb.setContentTitle(getResources().getString(R.string.location_provider_disabled_title));
        nb.setContentText(getResources().getString(R.string.location_provider_disabled_text));
        nb.setContentIntent(pi);/*from  w ww .j a  v  a 2s .c om*/
    } else {
        // GPS and Network location provider is OK. let use try again
        Intent intent = new Intent(ACTION_START_GEOFENCES, null, this, LocationMuteService.class);
        PendingIntent pi = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        nb.setContentTitle(getResources().getString(R.string.geo_not_available_retry_title));
        nb.setContentText(getResources().getString(R.string.geo_not_available_retry_text));
        nb.setContentIntent(pi);
    }
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    nm.notify(GEOFENCE_NOT_AVLIABLE_NOTIFICATION_ID, nb.build());

}

From source file:com.money.manager.ex.sync.SyncManager.java

private PendingIntent getPendingIntentForDelayedUpload() {
    DatabaseMetadata db = getDatabases().getCurrent();

    Intent intent = new Intent(getContext(), SyncService.class);

    intent.setAction(SyncConstants.INTENT_ACTION_SYNC);

    intent.putExtra(SyncConstants.INTENT_EXTRA_LOCAL_FILE, db.localPath);
    intent.putExtra(SyncConstants.INTENT_EXTRA_REMOTE_FILE, db.remotePath);

    return PendingIntent.getService(getContext(), SyncConstants.REQUEST_DELAYED_SYNC, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);
}

From source file:com.jasonmheim.rollout.station.CoreContentProvider.java

private PendingIntent getRideActionWithDestinationIntent(String destination) {
    Uri data = Constants.STATION_URI.buildUpon()
            .appendQueryParameter(UPDATE_KEY_ACTION, Integer.toString(ACTION_RIDE))
            .appendQueryParameter(UPDATE_KEY_DESTINATION, destination).build();
    Intent intent = new Intent(getContext(), ActionIntentService.class);
    intent.setData(data);/*from  ww w . java  2  s .c om*/

    PendingIntent pendingIntent = PendingIntent.getService(getContext(), 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    return pendingIntent;
}

From source file:com.tvs.signaltracker.STService.java

@Override
public void onDestroy() {
    ServiceHandler.removeCallbacks(ReCheck);
    ServiceHandler.removeCallbacks(ReSendRun);
    ServiceHandler.removeCallbacks(LightMode);

    if (CommonHandler.ServiceMode == 2 || CommonHandler.ServiceMode == 4) {
        Log.i("SignalTracker::STService", "Parando trabalhos");
        try {/*from   www .  j av  a 2s .  co m*/
            if (mlocManager != null) {
                mlocManager.removeGpsStatusListener(GPSs);
                mlocManager.removeUpdates(GPSLocListener);
                mlocManager.removeUpdates(NetLocListener);
            }
            if (Tel != null)
                Tel.listen(MyListener, PhoneStateListener.LISTEN_NONE);
        } catch (Exception e) {
        }
        ;

        MyListener = null;
        Tel = null;
        mlocManager = null;
        GPSs = null;
        GPSLocListener = null;
        NetLocListener = null;
        CommonHandler.GPSFix = false;
        CommonHandler.NumSattelites = 0;
        CommonHandler.NumConSattelites = 0;
        try {
            String ns = Context.NOTIFICATION_SERVICE;
            NotificationManager nMgr = (NotificationManager) this.getSystemService(ns);
            nMgr.cancel(NOTIFICATION);
        } catch (Exception e) {
        }
    }
    Toast.makeText(getApplicationContext(), getResources().getString(R.string.stservicestopped),
            Toast.LENGTH_LONG).show();
    if (!CommonHandler.KillService) {
        Intent myIntent = new Intent(STService.this, STService.class);
        PendingIntent pendingIntent = PendingIntent.getService(STService.this, 0, myIntent, 0);
        AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        calendar.add(Calendar.SECOND, 2);
        alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
    }
    CommonHandler.KillService = false;
    LocalRunning = false;
    Opened = false;
}

From source file:com.negaheno.android.NotificationsController.java

private void scheduleNotificationDelay(boolean onlineReason) {
    try {/*from w  ww  .  j  av a  2s .co  m*/
        FileLog.e("tmessages", "delay notification start");
        AlarmManager alarm = (AlarmManager) ApplicationLoader.applicationContext
                .getSystemService(Context.ALARM_SERVICE);
        PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0,
                new Intent(ApplicationLoader.applicationContext, NotificationDelay.class), 0);
        SharedPreferences preferences = ApplicationLoader.applicationContext
                .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
        if (onlineReason) {
            alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 3 * 1000, pintent);
        } else {
            alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 500, pintent);
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}