List of usage examples for android.app PendingIntent send
public void send() throws CanceledException
From source file:Main.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) public static void openNotification(AccessibilityEvent event) { if (!(event.getParcelableData() instanceof Notification)) { return;/*from w ww. j a va 2 s.com*/ } Notification notification = (Notification) event.getParcelableData(); PendingIntent pendingIntent = notification.contentIntent; try { pendingIntent.send(); } catch (PendingIntent.CanceledException e) { e.printStackTrace(); } }
From source file:Main.java
public static boolean sendPendingIntent(PendingIntent contentIntent) { if (contentIntent != null) try {//www . j ava2s . c o m contentIntent.send(); return true; } catch (PendingIntent.CanceledException e) { /* unused */ } return false; }
From source file:Main.java
public static boolean sendPendingIntent(@Nullable PendingIntent contentIntent) { if (contentIntent != null) try {/* ww w . ja va 2 s . c o m*/ contentIntent.send(); return true; } catch (PendingIntent.CanceledException e) { /* unused */ } return false; }
From source file:com.liato.bankdroid.appwidget.AutoRefreshService.java
public static void sendWidgetRefresh(final Context context) { // Send intent to BankdroidWidgetProvider final Intent updateIntent = new Intent(BROADCAST_WIDGET_REFRESH); final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, updateIntent, PendingIntent.FLAG_UPDATE_CURRENT); try {/*from w w w. ja v a 2s .co m*/ pendingIntent.send(); } catch (final CanceledException e) { // TODO Auto-generated catch block Log.e("", e.getMessage(), e); } }
From source file:com.codename1.impl.android.LocalNotificationPublisher.java
public void onReceive(Context context, Intent intent) { //Fire the notification to the display NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Bundle extras = intent.getExtras();//from w w w .j av a 2 s . c om PendingIntent content = extras.getParcelable(NOTIFICATION_INTENT); Bundle b = extras.getParcelable(NOTIFICATION); LocalNotification notif = AndroidImplementation.createNotificationFromBundle(b); if (AndroidImplementation.BACKGROUND_FETCH_NOTIFICATION_ID.equals(notif.getId())) { PendingIntent backgroundFetchIntent = extras.getParcelable(BACKGROUND_FETCH_INTENT); if (backgroundFetchIntent != null) { try { backgroundFetchIntent.send(); } catch (Exception ex) { Log.e("Codename One", "Failed to send BackgroundFetchHandler intent", ex); } } else { Log.d("Codename One", "BackgroundFetch intent was null"); } } else { Notification notification = createAndroidNotification(context, notif, content); notification.when = System.currentTimeMillis(); try { int notifId = Integer.parseInt(notif.getId()); notificationManager.notify("CN1", notifId, notification); } catch (Exception e) { //that was a mistake, the first param is the tag not the id notificationManager.notify(notif.getId(), 0, notification); } } }
From source file:com.mb.kids_mind.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras();/*from www . j a va 2s . c o m*/ GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); Log.v(TAG, "messageType" + messageType); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /* * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { sendNotification("Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { sendNotification("Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // This loop represents the service doing some work. for (int i = 0; i < 5; i++) { Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime()); try { Thread.sleep(5000); } catch (InterruptedException e) { } } Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime()); // Post notification of received message. sendNotification("Received: " + extras.toString()); if (PushWakeLock.ScreenOn(this)) { Log.v(TAG, "toast"); mHandler.post(new ToastRunnable("", this)); } else { PushWakeLock.acquireCpuWakeLock(this); Bundle bun = new Bundle(); int start = extras.toString().indexOf("adviceId="); int size = extras.toString().length(); String text = extras.toString().substring(start + 9); //int size=text.length(); text = extras.toString().substring(start + 9, size - 2); Log.v(TAG, "text" + text); bun.putString("notiMessage", text); Intent popupIntent = new Intent(getApplicationContext(), KidsMindNotiActivity.class); popupIntent.putExtras(bun); PendingIntent pie = PendingIntent.getActivity(getApplicationContext(), 0, popupIntent, PendingIntent.FLAG_ONE_SHOT); try { pie.send(); } catch (CanceledException e) { } Log.v(TAG, "?"); } Log.i(TAG, "Received: " + extras.toString()); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:markson.visuals.sitapp.settingActivity.java
public void notifications() { // get a Calendar object with current time Intent intent = new Intent(getApplicationContext(), ClassesService.class); //intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pi = PendingIntent.getService(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); try {/*from www .j a va 2 s.c o m*/ pi.send(); } catch (PendingIntent.CanceledException e) { // the stack trace isn't very helpful here. Just log the exception message. System.out.println("Sending Notification failed "); } /*Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, 07); calendar.set(Calendar.MINUTE, 00); calendar.set(Calendar.SECOND, 00); // add 5 minutes to the calendar object //cal.add(Calendar.SECOND, 10); Log.e("Testing", "Calender Set time:"+calendar.getTime()); //Log.e("Testing", "Intent created"); //intent.putExtra("alarm_message", "O'Doyle Rules!"); // In reality, you would want to have a static variable for the request code instead of 192837 AlarmManager alarm_manager = (AlarmManager)getSystemService(Context.ALARM_SERVICE); alarm_manager.setRepeating(AlarmManager.RTC, calendar.getTimeInMillis(),24*60*60*1000, pi);*/ }
From source file:com.lambdasoup.quickfit.ui.WorkoutListActivity.java
private void readIntentExtras() { if (getIntent().hasExtra(EXTRA_SHOW_WORKOUT_ID)) { idToSelect = getIntent().getLongExtra(EXTRA_SHOW_WORKOUT_ID, NO_ID); }//from w ww . ja va 2 s . c om if (getIntent().hasExtra(EXTRA_NOTIFICATIONS_CANCEL_INTENT)) { PendingIntent cancelIntent = getIntent().getParcelableExtra(EXTRA_NOTIFICATIONS_CANCEL_INTENT); try { cancelIntent.send(); } catch (PendingIntent.CanceledException e) { // intent is already canceled, do nothing Timber.d("sending notification cancel intent failed: pending intent already canceled"); } } }
From source file:com.alexandrepiveteau.library.tutorial.TutorialActivity.java
@Override public void onClick(View v) { if (v.getId() == R.id.tutorial_button_left || v.getId() == R.id.tutorial_button_image_left) { boolean hasCustomAction = false; if (mFragmentList.get(mViewPager.getCurrentItem()) instanceof CustomAction) { if (((CustomAction) mFragmentList.get(mViewPager.getCurrentItem())).isEnabled()) { hasCustomAction = true;//w w w . j av a 2 s.c o m } } if (hasCustomAction) { PendingIntent intent = ((CustomAction) mFragmentList.get(mViewPager.getCurrentItem())) .getCustomActionPendingIntent(); try { intent.send(); } catch (PendingIntent.CanceledException exception) { exception.printStackTrace(); } } else if (mViewPager.getCurrentItem() == 0) { finish(); } else { mViewPager.setCurrentItem(mViewPager.getCurrentItem() - 1, true); } } else if (v.getId() == R.id.tutorial_button_image_right) { if (mViewPager.getCurrentItem() == getCount() - 1) { finish(); } else { mViewPager.setCurrentItem(mViewPager.getCurrentItem() + 1, true); } } }
From source file:com.googlecode.mindbell.accessors.ContextAccessor.java
/** * Send a newly created intent to Scheduler to update notification and setup a new bell schedule for reminder, if * requested cancel and newly setup alarms to update noticiation status depending on day-night mode. *//* w w w .ja v a2 s. co m*/ public void updateBellScheduleForReminder(boolean renewDayNightAlarm) { MindBell.logDebug("Update bell schedule for reminder requested, renewDayNightAlarm=" + renewDayNightAlarm); if (renewDayNightAlarm) { scheduleUpdateStatusNotificationDayNight(); } PendingIntent sender = createSchedulerBroadcastIntent(false, null, null); try { sender.send(); } catch (PendingIntent.CanceledException e) { Log.e(TAG, "Could not update bell schedule for reminder: " + e.getMessage(), e); } }