List of usage examples for android.app PendingIntent getService
public static PendingIntent getService(Context context, int requestCode, @NonNull Intent intent, @Flags int flags)
From source file:com.google.android.apps.mytracks.widgets.TrackWidgetProvider.java
/** * Updates the record button./* w ww . jav a 2s.c o m*/ * * @param context the context * @param remoteViews the remote views * @param isRecording true if recording * @param recordingTrackPaused true if recording track is paused */ private void updateRecordButton(Context context, RemoteViews remoteViews, boolean isRecording, boolean recordingTrackPaused) { remoteViews.setImageViewResource(R.id.track_widget_record_button, isRecording && !recordingTrackPaused ? R.drawable.ic_pause : R.drawable.ic_record); int recordActionId; if (isRecording) { recordActionId = recordingTrackPaused ? R.string.track_action_resume : R.string.track_action_pause; } else { recordActionId = R.string.track_action_start; } Intent intent = new Intent(context, ControlRecordingService.class) .setAction(context.getString(recordActionId)); PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.track_widget_record_button, pendingIntent); }
From source file:com.nextgis.mobile.services.TrackerService.java
protected void ScheduleNextUpdate(Context context, String action, long nMinTimeBetweenSend, boolean bEnergyEconomy, boolean bStart) { if (context == null) return;//from ww w . j a va2 s . c o m Log.d(TAG, "Schedule Next Update for tracker " + bStart); if (bStart == false) return; Intent intent = new Intent(action); 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.example.android.wearable.wear.wearnotifications.MainActivity.java
private void generateBigTextStyleNotification() { Log.d(TAG, "generateBigTextStyleNotification()"); // Main steps for building a BIG_TEXT_STYLE notification: // 0. Get your data // 1. Build the BIG_TEXT_STYLE // 2. Set up main Intent for notification // 3. Create additional Actions for the Notification // 4. Build and issue the notification // 0. Get your data (everything unique per Notification) MockDatabase.BigTextStyleReminderAppData bigTextStyleReminderAppData = MockDatabase.getBigTextStyleData(); // 1. Build the BIG_TEXT_STYLE BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle() // Overrides ContentText in the big form of the template .bigText(bigTextStyleReminderAppData.getBigText()) // Overrides ContentTitle in the big form of the template .setBigContentTitle(bigTextStyleReminderAppData.getBigContentTitle()) // Summary line after the detail section in the big form of the template // Note: To improve readability, don't overload the user with info. If Summary Text // doesn't add critical information, you should skip it. .setSummaryText(bigTextStyleReminderAppData.getSummaryText()); // 2. Set up main Intent for notification Intent notifyIntent = new Intent(this, BigTextMainActivity.class); // When creating your Intent, you need to take into account the back state, i.e., what // happens after your Activity launches and the user presses the back button. // There are two options: // 1. Regular activity - You're starting an Activity that's part of the application's // normal workflow. // 2. Special activity - The user only sees this Activity if it's started from a // notification. In a sense, the Activity extends the notification by providing // information that would be hard to display in the notification itself. // For the BIG_TEXT_STYLE notification, we will consider the activity launched by the main // Intent as a special activity, so we will follow option 2. // For an example of option 1, check either the MESSAGING_STYLE or BIG_PICTURE_STYLE // examples.// w w w. j a v a 2 s . c om // For more information, check out our dev article: // https://developer.android.com/training/notify-user/navigation.html // Sets the Activity to start in a new, empty task notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); PendingIntent notifyPendingIntent = PendingIntent.getActivity(this, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); // 3. Create additional Actions (Intents) for the Notification // In our case, we create two additional actions: a Snooze action and a Dismiss action // Snooze Action Intent snoozeIntent = new Intent(this, BigTextIntentService.class); snoozeIntent.setAction(BigTextIntentService.ACTION_SNOOZE); PendingIntent snoozePendingIntent = PendingIntent.getService(this, 0, snoozeIntent, 0); NotificationCompat.Action snoozeAction = new NotificationCompat.Action.Builder( R.drawable.ic_alarm_white_48dp, "Snooze", snoozePendingIntent).build(); // Dismiss Action Intent dismissIntent = new Intent(this, BigTextIntentService.class); dismissIntent.setAction(BigTextIntentService.ACTION_DISMISS); PendingIntent dismissPendingIntent = PendingIntent.getService(this, 0, dismissIntent, 0); NotificationCompat.Action dismissAction = new NotificationCompat.Action.Builder( R.drawable.ic_cancel_white_48dp, "Dismiss", dismissPendingIntent).build(); // 4. Build and issue the notification // Because we want this to be a new notification (not updating a previous notification), we // create a new Builder. Later, we use the same global builder to get back the notification // we built here for the snooze action, that is, canceling the notification and relaunching // it several seconds later. NotificationCompat.Builder notificationCompatBuilder = new NotificationCompat.Builder( getApplicationContext()); GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder); Notification notification = notificationCompatBuilder // BIG_TEXT_STYLE sets title and content for API 16 (4.1 and after) .setStyle(bigTextStyle) // Title for API <16 (4.0 and below) devices .setContentTitle(bigTextStyleReminderAppData.getContentTitle()) // Content for API <24 (7.0 and below) devices .setContentText(bigTextStyleReminderAppData.getContentText()).setSmallIcon(R.drawable.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_alarm_white_48dp)) .setContentIntent(notifyPendingIntent) // Set primary color (important for Wear 2.0 Notifications) .setColor(getResources().getColor(R.color.colorPrimary)) // SIDE NOTE: Auto-bundling is enabled for 4 or more notifications on API 24+ (N+) // devices and all Android Wear devices. If you have more than one notification and // you prefer a different summary notification, set a group key and create a // summary notification via // .setGroupSummary(true) // .setGroup(GROUP_KEY_YOUR_NAME_HERE) .setCategory(Notification.CATEGORY_REMINDER).setPriority(Notification.PRIORITY_HIGH) // Shows content on the lock-screen .setVisibility(Notification.VISIBILITY_PUBLIC) // Adds additional actions specified above .addAction(snoozeAction).addAction(dismissAction) .build(); mNotificationManagerCompat.notify(NOTIFICATION_ID, notification); }
From source file:ca.zadrox.dota2esportticker.service.UpdateMatchService.java
private void cancelAutoUpdate() { final Intent updateMatchIntent = new Intent(UpdateMatchService.ACTION_AUTO_UPDATE_MATCHES, null, this, UpdateMatchService.class); final Intent updateResultIntent = new Intent(UpdateMatchService.ACTION_UPDATE_RESULTS, null, this, UpdateMatchService.class); PendingIntent umi = PendingIntent.getService(this.getApplicationContext(), 0, updateMatchIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent uri = PendingIntent.getService(this.getApplicationContext(), 0, updateResultIntent, PendingIntent.FLAG_UPDATE_CURRENT); final AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); am.cancel(umi);//from w ww.j a va 2 s . c o m am.cancel(uri); }
From source file:com.nextgis.mobile.TrackerService.java
protected void ScheduleNextUpdate(Context context, String action, long nMinTimeBetweenSend, boolean bEnergyEconomy, boolean bStart) { if (context == null) return;//from www. j a va2 s .com Log.d(MainActivity.TAG, "Schedule Next Update for tracker " + bStart); if (bStart == false) return; Intent intent = new Intent(action); 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.achow101.bitcointalkforum.MainActivity.java
public void onResume() { super.onResume(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); int seconds = Integer.parseInt(prefs.getString("notifications_sync_freq", "60")); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); Intent i = new Intent(this, NotificationService.class); i.putExtra("SESSION ID", sessId); i.putExtra("Username", mUsername); PendingIntent pi = PendingIntent.getService(this, 0, i, 0); am.cancel(pi);/*from w w w .j a va 2 s . c om*/ if (prefs.getBoolean("notifications_new_message", true)) { am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + seconds * 1000, seconds * 1000, pi); } }
From source file:com.samknows.measurement.test.TestExecutor.java
@SuppressWarnings("deprecation") public void showNotification(String message) { String title = tc.getString(R.string.ntf_title); NotificationManager manager = (NotificationManager) tc.getSystemService(Context.NOTIFICATION_SERVICE); Notification n = new Notification(R.drawable.icon, message, System.currentTimeMillis()); PendingIntent intent = PendingIntent.getService(tc.getServiceContext(), Constants.RC_NOTIFICATION, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT); n.setLatestEventInfo(tc.getServiceContext(), title, message, intent); manager.notify(Constants.NOTIFICATION_ID, n); }
From source file:com.prey.actions.geofences.GeofenceController.java
public void init(final Context ctx) { PreyLogger.d("_GeofenceController__init"); GeofenceDataSource dataSource = null; GoogleApiClient mGoogleApiClient = null; try {/* w w w .j av a 2 s . co m*/ mGoogleApiClient = connectGoogleApiClient(ctx); dataSource = new GeofenceDataSource(ctx); List<GeofenceDto> listBD = dataSource.getAllGeofences(); List<com.google.android.gms.location.Geofence> mGeofenceList = new ArrayList<Geofence>(); final List<GeofenceDto> listToBdAdd = new ArrayList<GeofenceDto>(); String info = "["; for (int i = 0; listBD != null && i < listBD.size(); i++) { GeofenceDto geo = listBD.get(i); listToBdAdd.add(geo); PreyLogger.d("__[START]___________id:" + geo.name + " lat:" + geo.latitude + " long:" + geo.longitude + " ra:" + geo.radius + " expires:" + geo.expires); int transitionTypes = com.google.android.gms.location.Geofence.GEOFENCE_TRANSITION_ENTER | com.google.android.gms.location.Geofence.GEOFENCE_TRANSITION_EXIT; mGeofenceList.add(new com.google.android.gms.location.Geofence.Builder().setRequestId(geo.id) .setCircularRegion(geo.latitude, geo.longitude, geo.radius) .setExpirationDuration(Geofence.NEVER_EXPIRE).setTransitionTypes(transitionTypes).build()); info += geo.id; if (i + 1 < listBD.size()) { info += ","; } } info += "]"; final String extraInfo = info; PreyLogger.d("info:" + extraInfo); GeofencingRequest.Builder builder = new GeofencingRequest.Builder(); builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_DWELL); builder.addGeofences(mGeofenceList); GeofencingRequest geofencingRequest = builder.build(); if (mGoogleApiClient.isConnected()) { PreyLogger.d("---->isConnected"); try { if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.M || ActivityCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { Intent intent = new Intent(ctx, GeofenceIntentService.class); PendingIntent pendingIntent = PendingIntent.getService(ctx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); PendingResult<Status> result = LocationServices.GeofencingApi.addGeofences(mGoogleApiClient, geofencingRequest, pendingIntent); result.setResultCallback(new ResultCallback<Status>() { @Override public void onResult(Status status) { PreyLogger.d("*********************connectionAddListener status :" + status); if (status.isSuccess()) { PreyLogger.d("********saveGeofence"); } else { PreyLogger.d("*********************Registering geofence failed: " + status.getStatusMessage() + " : " + status.getStatusCode()); sendNotify(ctx, UtilJson.makeMapParam("start", "geofencing", "failed", "status:" + status.isSuccess())); } } }); } } catch (Exception e) { PreyLogger.e("error ---->isConnected:" + e.getMessage(), e); sendNotify(ctx, UtilJson.makeMapParam("start", "geofencing", "failed", "error:" + e.getMessage())); } } else { PreyLogger.d("not connect mGoogleApiClient 3"); sendNotify(ctx, UtilJson.makeMapParam("start", "geofencing", "failed", "not connect mGoogleApiClient")); } } catch (Exception e) { } }
From source file:com.google.android.apps.iosched.calendar.SessionAlarmService.java
private PendingIntent createSnoozeIntent(final long sessionStart, final long sessionEnd, final int snoozeMinutes) { Intent scheduleIntent = new Intent(SessionAlarmService.ACTION_SCHEDULE_STARRED_BLOCK, null, this, SessionAlarmService.class); scheduleIntent.putExtra(SessionAlarmService.EXTRA_SESSION_START, sessionStart); scheduleIntent.putExtra(SessionAlarmService.EXTRA_SESSION_END, sessionEnd); scheduleIntent.putExtra(SessionAlarmService.EXTRA_SESSION_ALARM_OFFSET, snoozeMinutes * ONE_MINUTE_MILLIS); return PendingIntent.getService(this, 0, scheduleIntent, PendingIntent.FLAG_CANCEL_CURRENT); }
From source file:com.conferenceengineer.android.iosched.service.SessionAlarmService.java
private PendingIntent createSnoozeIntent(final long sessionStart, final long sessionEnd, final int snoozeMinutes) { Intent scheduleIntent = new Intent(SessionAlarmService.ACTION_SCHEDULE_STARRED_BLOCK, null, this, SessionAlarmService.class); scheduleIntent.putExtra(SessionAlarmService.EXTRA_SESSION_START, sessionStart); scheduleIntent.putExtra(SessionAlarmService.EXTRA_SESSION_END, sessionEnd); scheduleIntent.putExtra(SessionAlarmService.EXTRA_SESSION_ALARM_OFFSET, snoozeMinutes * MILLI_ONE_MINUTE); return PendingIntent.getService(this, 0, scheduleIntent, PendingIntent.FLAG_CANCEL_CURRENT); }