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.raddapp.radika.raddappv001.GpsLoggingService.java
private void StopAlarm() { Log.d("GPSLOGSERV 101", "StopAlarm"); Intent i = new Intent(this, GpsLoggingService.class); i.putExtra(IntentConstants.GET_NEXT_POINT, true); PendingIntent pi = PendingIntent.getService(this, 0, i, 0); nextPointAlarmManager.cancel(pi);//from w ww . j a va 2s. co m }
From source file:com.daiv.android.twitter.utils.NotificationUtils.java
public static void notifySecondMentions(Context context, int secondAccount) { MentionsDataSource data = MentionsDataSource.getInstance(context); int numberNew = data.getUnreadCount(secondAccount); int smallIcon = R.drawable.ic_stat_icon; Bitmap largeIcon;/*from w w w . ja v a2s .c o m*/ NotificationCompat.Builder mBuilder; String title = context.getResources().getString(R.string.app_name) + " - " + context.getResources().getString(R.string.sec_acc); String name = null; String message; String messageLong; String tweetText = null; NotificationCompat.Action replyAction = null; if (numberNew == 1) { name = data.getNewestName(secondAccount); SharedPreferences sharedPrefs = context.getSharedPreferences( "com.daiv.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); // if they are muted, and you don't want them to show muted mentions // then just quit if (sharedPrefs.getString("muted_users", "").contains(name) && !sharedPrefs.getBoolean("show_muted_mentions", false)) { return; } message = context.getResources().getString(R.string.mentioned_by) + " @" + name; tweetText = data.getNewestMessage(secondAccount); messageLong = "<b>@" + name + "</b>: " + tweetText; largeIcon = getImage(context, name); Intent reply = null; sharedPrefs.edit().putString("from_notification_second", "@" + name).commit(); long id = data.getLastIds(secondAccount)[0]; PendingIntent replyPending = PendingIntent.getActivity(context, 0, reply, 0); sharedPrefs.edit().putLong("from_notification_long_second", id).commit(); sharedPrefs.edit() .putString("from_notification_text_second", "@" + name + ": " + TweetLinkUtils.removeColorHtml(tweetText, AppSettings.getInstance(context))) .commit(); // Create the remote input RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel("@" + name + " ").build(); // Create the notification action replyAction = new NotificationCompat.Action.Builder(R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply), replyPending).addRemoteInput(remoteInput) .build(); } else { // more than one mention message = numberNew + " " + context.getResources().getString(R.string.new_mentions); messageLong = "<b>" + context.getResources().getString(R.string.mentions) + "</b>: " + numberNew + " " + context.getResources().getString(R.string.new_mentions); largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark); } Intent markRead = new Intent(context, MarkReadSecondAccService.class); PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0); AppSettings settings = AppSettings.getInstance(context); Intent deleteIntent = new Intent(context, NotificationDeleteReceiverTwo.class); mBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(TweetLinkUtils.removeColorHtml(message, settings)).setSmallIcon(smallIcon) .setLargeIcon(largeIcon).setAutoCancel(true) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)) .setPriority(NotificationCompat.PRIORITY_HIGH); if (numberNew == 1) { mBuilder.addAction(replyAction); mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml( settings.addonTheme ? messageLong.replaceAll("FF8800", settings.accentColor) : messageLong))); } else { NotificationCompat.InboxStyle inbox = getMentionsInboxStyle(numberNew, secondAccount, context, TweetLinkUtils.removeColorHtml(message, settings)); mBuilder.setStyle(inbox); } if (settings.vibrate) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } if (settings.sound) { try { mBuilder.setSound(Uri.parse(settings.ringtone)); } catch (Exception e) { mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } if (settings.led) mBuilder.setLights(0xFFFFFF, 1000, 1000); if (settings.notifications) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(9, mBuilder.build()); // if we want to wake the screen on a new message if (settings.wakeScreen) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG"); wakeLock.acquire(5000); } // Pebble notification if (context .getSharedPreferences("com.daiv.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE) .getBoolean("pebble_notification", false)) { sendAlertToPebble(context, title, messageLong); } // Light Flow notification sendToLightFlow(context, title, messageLong); } }
From source file:com.raddapp.radika.raddappv001.GpsLoggingService.java
private void SetAlarmForNextPoint() { Log.d("GPSLOGSERV 101", "SetAlarmForNextPoint"); //tracer.debug("Set alarm for " + 3 + " seconds");//AppSettings.getMinimumLoggingInterval() Intent i = new Intent(this, GpsLoggingService.class); i.putExtra(IntentConstants.GET_NEXT_POINT, true); PendingIntent pi = PendingIntent.getService(this, 0, i, 0); nextPointAlarmManager.cancel(pi);//from w w w. j a v a 2s.co m nextPointAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 1 * 1000, pi); //AppSettings.getMinimumLoggingInterval() }
From source file:com.mjhram.geodata.GpsLoggingService.java
private void StopAlarm() { Intent i = new Intent(this, GpsLoggingService.class); i.putExtra(IntentConstants.GET_NEXT_POINT, true); PendingIntent pi = PendingIntent.getService(this, 0, i, 0); nextPointAlarmManager.cancel(pi);//from w w w.ja v a2s .c om }
From source file:com.tct.email.NotificationController.java
/** * Show (or update) a exchange sync new contacts notification. If tapped, the user is taken to the Exchange permission view * where he can view the exchange permission. if tap never ask again,notification will not show. *//*from ww w . jav a2 s . co m*/ public void showContactsNotification(String packageName) { NotificationCompat.Builder notification = new NotificationCompat.Builder(mContext); //get the warning icon Bitmap icon = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_warning_grey); //The Martro style only supported after android L. if (com.tct.mail.utils.Utils.isRunningLOrLater()) { notification.setColor(mContext.getResources().getColor(R.color.notification_icon_mail_orange)); } notification.setContentTitle(mContext.getResources().getString(R.string.sync_contacts_title)); notification.setContentText(mContext.getResources().getString(R.string.sync_contacts_content)); notification.setLargeIcon(icon); notification.setSmallIcon(R.drawable.ic_notification_mail_24dp); notification.setAutoCancel(true);//TS: zheng.zou 2016-3-19 EMAIL BUGFIX-1841389 ADD_S //set the content click/tap intent //it will trigger going to app permissions settings Intent gotoSettingsIntent = gotoSettingsIntent(mContext, packageName); PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, gotoSettingsIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setContentIntent(contentIntent); //set the action click intent. //it will never receive notification. //never ask again Intent clickIntent = new Intent(NotificationActionIntentService.ACTION_CONTACTS_NEVER_ASK_AGAIN); clickIntent.setPackage(mContext.getPackageName()); PendingIntent pendButtonIntent = PendingIntent.getService(mContext, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.addAction(R.drawable.notification_button, mContext.getResources().getString(R.string.notification_never_ask_again).toUpperCase(), pendButtonIntent); Notification warningNotification = notification.build(); // warningNotification.flags |= Notification.FLAG_AUTO_CANCEL; // warningNotification.flags |= Notification.DEFAULT_VIBRATE; NotificationManager nm = (NotificationManager) mContext.getSystemService(mContext.NOTIFICATION_SERVICE); nm.notify(EXCHANGE_NEWCONTACTS_NOTIFICATION_ID, warningNotification); }
From source file:com.mjhram.geodata.GpsLoggingService.java
private void SetAlarmForNextPoint() { tracer.debug("Set alarm for " + AppSettings.getMinimumLoggingInterval() + " seconds"); Intent i = new Intent(this, GpsLoggingService.class); i.putExtra(IntentConstants.GET_NEXT_POINT, true); PendingIntent pi = PendingIntent.getService(this, 0, i, 0); nextPointAlarmManager.cancel(pi);// ww w . ja va2 s .c om nextPointAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + AppSettings.getMinimumLoggingInterval() * 1000, pi); }
From source file:com.klinker.android.twitter.utils.NotificationUtils.java
public static void notifySecondMentions(Context context, int secondAccount) { MentionsDataSource data = MentionsDataSource.getInstance(context); int numberNew = data.getUnreadCount(secondAccount); int smallIcon = R.drawable.ic_stat_icon; Bitmap largeIcon;//w w w . j a va 2 s . c om Intent resultIntent = new Intent(context, SwitchAccountsRedirect.class); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0); NotificationCompat.Builder mBuilder; String title = context.getResources().getString(R.string.app_name) + " - " + context.getResources().getString(R.string.sec_acc); ; String name = null; String message; String messageLong; String tweetText = null; NotificationCompat.Action replyAction = null; if (numberNew == 1) { name = data.getNewestName(secondAccount); SharedPreferences sharedPrefs = context.getSharedPreferences( "com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); // if they are muted, and you don't want them to show muted mentions // then just quit if (sharedPrefs.getString("muted_users", "").contains(name) && !sharedPrefs.getBoolean("show_muted_mentions", false)) { return; } message = context.getResources().getString(R.string.mentioned_by) + " @" + name; tweetText = data.getNewestMessage(secondAccount); messageLong = "<b>@" + name + "</b>: " + tweetText; largeIcon = getImage(context, name); Intent reply = new Intent(context, NotificationComposeSecondAcc.class); sharedPrefs.edit().putString("from_notification_second", "@" + name).commit(); long id = data.getLastIds(secondAccount)[0]; PendingIntent replyPending = PendingIntent.getActivity(context, 0, reply, 0); sharedPrefs.edit().putLong("from_notification_long_second", id).commit(); sharedPrefs.edit() .putString("from_notification_text_second", "@" + name + ": " + TweetLinkUtils.removeColorHtml(tweetText, AppSettings.getInstance(context))) .commit(); // Create the remote input RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel("@" + name + " ").build(); // Create the notification action replyAction = new NotificationCompat.Action.Builder(R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply), replyPending).addRemoteInput(remoteInput) .build(); } else { // more than one mention message = numberNew + " " + context.getResources().getString(R.string.new_mentions); messageLong = "<b>" + context.getResources().getString(R.string.mentions) + "</b>: " + numberNew + " " + context.getResources().getString(R.string.new_mentions); largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark); } Intent markRead = new Intent(context, MarkReadSecondAccService.class); PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0); AppSettings settings = AppSettings.getInstance(context); Intent deleteIntent = new Intent(context, NotificationDeleteReceiverTwo.class); mBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(TweetLinkUtils.removeColorHtml(message, settings)).setSmallIcon(smallIcon) .setLargeIcon(largeIcon).setContentIntent(resultPendingIntent).setAutoCancel(true) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)) .setPriority(NotificationCompat.PRIORITY_HIGH); if (numberNew == 1) { mBuilder.addAction(replyAction); mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml( settings.addonTheme ? messageLong.replaceAll("FF8800", settings.accentColor) : messageLong))); } else { NotificationCompat.InboxStyle inbox = getMentionsInboxStyle(numberNew, secondAccount, context, TweetLinkUtils.removeColorHtml(message, settings)); mBuilder.setStyle(inbox); } if (settings.vibrate) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } if (settings.sound) { try { mBuilder.setSound(Uri.parse(settings.ringtone)); } catch (Exception e) { mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } if (settings.led) mBuilder.setLights(0xFFFFFF, 1000, 1000); if (settings.notifications) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(9, mBuilder.build()); // if we want to wake the screen on a new message if (settings.wakeScreen) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG"); wakeLock.acquire(5000); } // Pebble notification if (context .getSharedPreferences("com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE) .getBoolean("pebble_notification", false)) { sendAlertToPebble(context, title, messageLong); } // Light Flow notification sendToLightFlow(context, title, messageLong); } }
From source file:com.tct.email.NotificationController.java
public void showStoragePermissionNotification(String pgkName) { NotificationCompat.Builder notification = new NotificationCompat.Builder(mContext); //get the warning icon Bitmap icon = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_warning_grey); //The Martro style only supported after android L. if (com.tct.mail.utils.Utils.isRunningLOrLater()) { notification.setColor(mContext.getResources().getColor(R.color.notification_icon_mail_orange)); }//from ww w . jav a 2 s . com notification.setContentTitle(mContext.getResources().getString(R.string.sync_storage_title)); notification.setContentText(mContext.getResources().getString(R.string.sync_storage_content)); notification.setLargeIcon(icon); notification.setSmallIcon(R.drawable.ic_notification_mail_24dp); //set the content click/tap intent //it will trigger going to app permissions settings Intent gotoSettingsIntent = gotoSettingsIntent(mContext, pgkName); PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, gotoSettingsIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setContentIntent(contentIntent); notification.setAutoCancel(true); //TS: zheng.zou 2016-3-19 EMAIL BUGFIX-1841389 ADD_S //set the action click intent. //it will never receive notification. //never ask again Intent clickIntent = new Intent(NotificationActionIntentService.ACTION_STORAGE_NEVER_ASK_AGAIN); clickIntent.setPackage(mContext.getPackageName()); PendingIntent pendButtonIntent = PendingIntent.getService(mContext, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.addAction(R.drawable.notification_button, mContext.getResources().getString(R.string.notification_never_ask_again).toUpperCase(), pendButtonIntent); Notification warningNotification = notification.build(); NotificationManager nm = (NotificationManager) mContext.getSystemService(mContext.NOTIFICATION_SERVICE); nm.notify(EXCHANGE_NEWSTORAGE_NOTIFICATION_ID, warningNotification); }
From source file:com.shinymayhem.radiopresets.ServiceRadioPlayer.java
protected PendingIntent getPreviousIntent() { Intent intent = new Intent(this, ServiceRadioPlayer.class).setAction(ACTION_PREVIOUS); return PendingIntent.getService(this, 0, intent, 0); }
From source file:com.shinymayhem.radiopresets.ServiceRadioPlayer.java
protected PendingIntent getStopIntent() { Intent intent = new Intent(this, ServiceRadioPlayer.class).setAction(ACTION_STOP); return PendingIntent.getService(this, 0, intent, 0); }