List of usage examples for android.app PendingIntent getBroadcast
public static PendingIntent getBroadcast(Context context, int requestCode, Intent intent, @Flags int flags)
From source file:biz.bokhorst.bpt.BPTService.java
@Override public IBinder onBind(Intent intent) { // Start foreground service startForeground(1, getNotification(getString(R.string.Running))); // Instantiate helpers locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); databaseHelper = new DatabaseHelper(this); preferences = PreferenceManager.getDefaultSharedPreferences(this); PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); taskHandler = new Handler(); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "BPT"); notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Intent alarmIntent = new Intent("BPT_ALARM"); pendingAlarmIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmReceiver = new BPTAlarmReceiver(); registerReceiver(alarmReceiver, new IntentFilter("BPT_ALARM")); bound = true;/*from w w w . j a v a 2s . c o m*/ return serverMessenger.getBinder(); }
From source file:com.aafr.alfonso.sunshine.app.ForecastFragment.java
private void updateWeather() { Intent alarmIntent = new Intent(getActivity(), SunshineService.AlarmReceiver.class); alarmIntent.putExtra(SunshineService.LOCATION_QUERY_EXTRA, Utility.getPreferredLocation(getActivity())); //Wrap in a pending intent which only fires once. PendingIntent pi = PendingIntent.getBroadcast(getActivity(), 0, alarmIntent, PendingIntent.FLAG_ONE_SHOT);//getBroadcast(context, 0, i, 0); AlarmManager am = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE); //Set the AlarmManager to wake up the system. am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 5000, pi); }
From source file:com.example.android.xyztouristattractions.service.UtilityService.java
/** * Add geofences using Play Services// w ww .ja va 2s . c o m */ private void addGeofencesInternal() { Log.v(TAG, ACTION_ADD_GEOFENCES); GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API).build(); // It's OK to use blockingConnect() here as we are running in an // IntentService that executes work on a separate (background) thread. ConnectionResult connectionResult = googleApiClient.blockingConnect(Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS); if (connectionResult.isSuccess() && googleApiClient.isConnected()) { PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(this, UtilityReceiver.class), 0); GeofencingApi.addGeofences(googleApiClient, TouristAttractions.getGeofenceList(), pendingIntent); googleApiClient.disconnect(); } else { Log.e(TAG, String.format(Constants.GOOGLE_API_CLIENT_ERROR_MSG, connectionResult.getErrorCode())); } }
From source file:com.android.cts.verifier.sensors.SignificantMotionTestActivity.java
@SuppressWarnings("unused") public String testAPWakeUpOnSMDTrigger() throws Throwable { SensorTestLogger logger = getTestLogger(); logger.logInstructions(R.string.snsr_significant_motion_ap_suspend); waitForUserToBegin();//www . ja v a2s .co m mVerifier = new TriggerVerifier(); mSensorManager.requestTriggerSensor(mVerifier, mSensorSignificantMotion); long testStartTimeNs = SystemClock.elapsedRealtimeNanos(); Handler handler = new Handler(Looper.getMainLooper()); SuspendStateMonitor suspendStateMonitor = new SuspendStateMonitor(); Intent intent = new Intent(this, AlarmReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + ALARM_WAKE_TIME_DELAY_MS, pendingIntent); try { // Wait for the first event to trigger. Device is expected to go into suspend here. mVerifier.verifyEventTriggered(); long eventTimeStampNs = mVerifier.getTimeStampForTriggerEvent(); long endTimeNs = SystemClock.elapsedRealtimeNanos(); long lastWakeupTimeNs = TimeUnit.MILLISECONDS.toNanos(suspendStateMonitor.getLastWakeUpTime()); Assert.assertTrue(getString(R.string.snsr_device_did_not_go_into_suspend), testStartTimeNs < lastWakeupTimeNs && lastWakeupTimeNs < endTimeNs); long timestampDelta = Math.abs(lastWakeupTimeNs - eventTimeStampNs); Assert.assertTrue( String.format(getString(R.string.snsr_device_did_not_wake_up_at_trigger), TimeUnit.NANOSECONDS.toMillis(lastWakeupTimeNs), TimeUnit.NANOSECONDS.toMillis(eventTimeStampNs)), timestampDelta < MAX_ACCEPTABLE_DELAY_EVENT_AP_WAKE_UP_NS); } finally { am.cancel(pendingIntent); suspendStateMonitor.cancel(); mScreenManipulator.turnScreenOn(); playSound(); } return null; }
From source file:com.asburymotors.android.disneysocal.service.UtilityService.java
/** * Add geofences using Play Services// w w w. jav a 2 s . c om */ private void addGeofencesInternal() { Log.v(TAG, ACTION_ADD_GEOFENCES); if (!Utils.checkFineLocationPermission(this)) { return; } GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API).build(); // It's OK to use blockingConnect() here as we are running in an // IntentService that executes work on a separate (background) thread. ConnectionResult connectionResult = googleApiClient.blockingConnect(Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS); if (connectionResult.isSuccess() && googleApiClient.isConnected()) { PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(this, UtilityReceiver.class), 0); GeofencingApi.addGeofences(googleApiClient, TouristAttractions.getGeofenceList(), pendingIntent); googleApiClient.disconnect(); } else { Log.e(TAG, String.format(Constants.GOOGLE_API_CLIENT_ERROR_MSG, connectionResult.getErrorCode())); } }
From source file:com.jay.pea.mhealthapp2.utilityClasses.AlarmReceiver.java
public void CancelAlarm(Context context) { Intent intent = new Intent(context, AlarmReceiver.class); PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(sender);/* w w w . ja v a2s. c om*/ }
From source file:com.google.android.gms.location.sample.backgroundlocationupdates.MainActivity.java
private PendingIntent getPendingIntent() { Intent intent = new Intent(this, LocationUpdatesBroadcastReceiver.class); intent.setAction(LocationUpdatesBroadcastReceiver.ACTION_PROCESS_UPDATES); return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); }
From source file:com.devbrackets.android.playlistcore.helper.MediaControlsHelper.java
@NonNull protected PendingIntent getMediaButtonReceiverPendingIntent(@NonNull ComponentName componentName, @NonNull Class<? extends Service> serviceClass) { Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(componentName); mediaButtonIntent.putExtra(RECEIVER_EXTRA_CLASS, serviceClass.getName()); return PendingIntent.getBroadcast(context, 0, mediaButtonIntent, PendingIntent.FLAG_CANCEL_CURRENT); }
From source file:com.google.android.car.kitchensink.bluetooth.MapMceTestFragment.java
private void sendMessage(Uri[] recipients, String message) { synchronized (mLock) { BluetoothDevice remoteDevice;/*from w ww.jav a2 s. c om*/ try { remoteDevice = mBluetoothAdapter.getRemoteDevice(mBluetoothDevice.getText().toString()); } catch (java.lang.IllegalArgumentException e) { Log.e(TAG, e.toString()); return; } mSent.setChecked(false); mDelivered.setChecked(false); if (mMapProfile != null) { Log.d(TAG, "Sending reply"); if (recipients == null) { Log.d(TAG, "Recipients is null"); return; } if (mBluetoothDevice == null) { Log.d(TAG, "BluetoothDevice is null"); return; } mSentIntent = PendingIntent.getBroadcast(getContext(), 0, mSendIntent, PendingIntent.FLAG_ONE_SHOT); mDeliveredIntent = PendingIntent.getBroadcast(getContext(), 0, mDeliveryIntent, PendingIntent.FLAG_ONE_SHOT); mMapProfile.sendMessage(remoteDevice, recipients, message, mSentIntent, mDeliveredIntent); } } }
From source file:com.google.android.apps.santatracker.notification.SantaNotificationBuilder.java
/** * Schedule a basic notification at an approximate time. *///from w w w . ja v a2s .com public static void ScheduleSantaNotification(Context c, long timestamp, int notificationType) { // Only schedule a notification if the time is in the future if (timestamp < System.currentTimeMillis()) { return; } AlarmManager alarm = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(c, NotificationBroadcastReceiver.class); i.putExtra(NotificationConstants.KEY_NOTIFICATION_ID, NotificationConstants.NOTIFICATION_ID); // Type is "takeoff", "location", etc. i.putExtra(NotificationConstants.KEY_NOTIFICATION_TYPE, notificationType); // Generate unique pending intent PendingIntent pi = PendingIntent.getBroadcast(c, notificationType, i, 0); // Deliver next time the device is woken up alarm.set(AlarmManager.RTC, timestamp, pi); }