List of usage examples for android.app Notification CATEGORY_STATUS
String CATEGORY_STATUS
To view the source code for android.app Notification CATEGORY_STATUS.
Click Source Link
From source file:eu.faircode.netguard.Receiver.java
public static void notifyNewApplication(int uid, Context context) { if (uid < 0) return;//w w w . j a v a 2s . c o m SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); try { // Get application info String name = TextUtils.join(", ", Util.getApplicationNames(uid, context)); // Get application info PackageManager pm = context.getPackageManager(); String[] packages = pm.getPackagesForUid(uid); if (packages == null || packages.length < 1) throw new PackageManager.NameNotFoundException(Integer.toString(uid)); boolean internet = Util.hasInternet(uid, context); // Build notification Intent main = new Intent(context, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_REFRESH, true); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); PendingIntent pi = PendingIntent.getActivity(context, uid, main, PendingIntent.FLAG_UPDATE_CURRENT); Util.setTheme(context); TypedValue tv = new TypedValue(); context.getTheme().resolveAttribute(R.attr.colorPrimary, tv, true); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_security_white_24dp).setContentIntent(pi).setColor(tv.data) .setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) builder.setContentTitle(name).setContentText(context.getString(R.string.msg_installed_n)); else builder.setContentTitle(context.getString(R.string.app_name)) .setContentText(context.getString(R.string.msg_installed, name)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET); } // Get defaults SharedPreferences prefs_wifi = context.getSharedPreferences("wifi", Context.MODE_PRIVATE); SharedPreferences prefs_other = context.getSharedPreferences("other", Context.MODE_PRIVATE); boolean wifi = prefs_wifi.getBoolean(packages[0], prefs.getBoolean("whitelist_wifi", true)); boolean other = prefs_other.getBoolean(packages[0], prefs.getBoolean("whitelist_other", true)); // Build Wi-Fi action Intent riWifi = new Intent(context, ServiceSinkhole.class); riWifi.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set); riWifi.putExtra(ServiceSinkhole.EXTRA_NETWORK, "wifi"); riWifi.putExtra(ServiceSinkhole.EXTRA_UID, uid); riWifi.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]); riWifi.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !wifi); PendingIntent piWifi = PendingIntent.getService(context, uid, riWifi, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(wifi ? R.drawable.wifi_on : R.drawable.wifi_off, context.getString(wifi ? R.string.title_allow : R.string.title_block), piWifi); // Build mobile action Intent riOther = new Intent(context, ServiceSinkhole.class); riOther.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set); riOther.putExtra(ServiceSinkhole.EXTRA_NETWORK, "other"); riOther.putExtra(ServiceSinkhole.EXTRA_UID, uid); riOther.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]); riOther.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !other); PendingIntent piOther = PendingIntent.getService(context, uid + 10000, riOther, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(other ? R.drawable.other_on : R.drawable.other_off, context.getString(other ? R.string.title_allow : R.string.title_block), piOther); // Show notification if (internet) NotificationManagerCompat.from(context).notify(uid, builder.build()); else { NotificationCompat.BigTextStyle expanded = new NotificationCompat.BigTextStyle(builder); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) expanded.bigText(context.getString(R.string.msg_installed_n)); else expanded.bigText(context.getString(R.string.msg_installed, name)); expanded.setSummaryText(context.getString(R.string.title_internet)); NotificationManagerCompat.from(context).notify(uid, expanded.build()); } } catch (PackageManager.NameNotFoundException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } }
From source file:android_network.hetnet.vpn_service.Receiver.java
public static void notifyNewApplication(int uid, Context context) { if (uid < 0) return;/* w ww . j ava 2 s . c o m*/ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); try { // Get application info String name = TextUtils.join(", ", Util.getApplicationNames(uid, context)); // Get application info PackageManager pm = context.getPackageManager(); String[] packages = pm.getPackagesForUid(uid); if (packages == null || packages.length < 1) throw new PackageManager.NameNotFoundException(Integer.toString(uid)); boolean internet = Util.hasInternet(uid, context); // Build notification Intent main = new Intent(context, MainActivity.class); main.putExtra(MainActivity.EXTRA_REFRESH, true); main.putExtra(MainActivity.EXTRA_SEARCH, Integer.toString(uid)); PendingIntent pi = PendingIntent.getActivity(context, uid, main, PendingIntent.FLAG_UPDATE_CURRENT); Util.setTheme(context); TypedValue tv = new TypedValue(); context.getTheme().resolveAttribute(R.attr.colorPrimary, tv, true); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_security_white_24dp).setContentIntent(pi).setColor(tv.data) .setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) builder.setContentTitle(name).setContentText(context.getString(R.string.msg_installed_n)); else builder.setContentTitle(context.getString(R.string.app_name)) .setContentText(context.getString(R.string.msg_installed, name)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET); } // Get defaults SharedPreferences prefs_wifi = context.getSharedPreferences("wifi", Context.MODE_PRIVATE); SharedPreferences prefs_other = context.getSharedPreferences("other", Context.MODE_PRIVATE); boolean wifi = prefs_wifi.getBoolean(packages[0], prefs.getBoolean("whitelist_wifi", true)); boolean other = prefs_other.getBoolean(packages[0], prefs.getBoolean("whitelist_other", true)); // Build Wi-Fi action Intent riWifi = new Intent(context, ServiceSinkhole.class); riWifi.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set); riWifi.putExtra(ServiceSinkhole.EXTRA_NETWORK, "wifi"); riWifi.putExtra(ServiceSinkhole.EXTRA_UID, uid); riWifi.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]); riWifi.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !wifi); PendingIntent piWifi = PendingIntent.getService(context, uid, riWifi, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(wifi ? R.drawable.wifi_on : R.drawable.wifi_off, context.getString(wifi ? R.string.title_allow : R.string.title_block), piWifi); // Build mobile action Intent riOther = new Intent(context, ServiceSinkhole.class); riOther.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set); riOther.putExtra(ServiceSinkhole.EXTRA_NETWORK, "other"); riOther.putExtra(ServiceSinkhole.EXTRA_UID, uid); riOther.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]); riOther.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !other); PendingIntent piOther = PendingIntent.getService(context, uid + 10000, riOther, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(other ? R.drawable.other_on : R.drawable.other_off, context.getString(other ? R.string.title_allow : R.string.title_block), piOther); // Show notification if (internet) NotificationManagerCompat.from(context).notify(uid, builder.build()); else { NotificationCompat.BigTextStyle expanded = new NotificationCompat.BigTextStyle(builder); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) expanded.bigText(context.getString(R.string.msg_installed_n)); else expanded.bigText(context.getString(R.string.msg_installed, name)); expanded.setSummaryText(context.getString(R.string.title_internet)); NotificationManagerCompat.from(context).notify(uid, expanded.build()); } } catch (PackageManager.NameNotFoundException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } }
From source file:eu.faircode.adblocker.Receiver.java
public static void notifyNewApplication(int uid, Context context) { if (uid < 0) return;// w ww . j av a 2 s .c om SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); try { // Get application info String name = TextUtils.join(", ", Util.getApplicationNames(uid, context)); // Get application info PackageManager pm = context.getPackageManager(); String[] packages = pm.getPackagesForUid(uid); if (packages.length < 1) throw new PackageManager.NameNotFoundException(Integer.toString(uid)); boolean internet = Util.hasInternet(uid, context); // Build notification Intent main = new Intent(context, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_REFRESH, true); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); PendingIntent pi = PendingIntent.getActivity(context, uid, main, PendingIntent.FLAG_UPDATE_CURRENT); Util.setTheme(context); TypedValue tv = new TypedValue(); context.getTheme().resolveAttribute(R.attr.colorPrimary, tv, true); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_security_white_24dp) .setContentTitle(context.getString(R.string.app_name)) .setContentText(context.getString(R.string.msg_installed, name)).setContentIntent(pi) .setColor(tv.data).setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET); } // Get defaults SharedPreferences prefs_wifi = context.getSharedPreferences("wifi", Context.MODE_PRIVATE); SharedPreferences prefs_other = context.getSharedPreferences("other", Context.MODE_PRIVATE); boolean wifi = prefs_wifi.getBoolean(packages[0], prefs.getBoolean("whitelist_wifi", true)); boolean other = prefs_other.getBoolean(packages[0], prefs.getBoolean("whitelist_other", true)); // Build Wi-Fi action Intent riWifi = new Intent(context, ServiceSinkhole.class); riWifi.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set); riWifi.putExtra(ServiceSinkhole.EXTRA_NETWORK, "wifi"); riWifi.putExtra(ServiceSinkhole.EXTRA_UID, uid); riWifi.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]); riWifi.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !wifi); PendingIntent piWifi = PendingIntent.getService(context, uid, riWifi, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(wifi ? R.drawable.wifi_on : R.drawable.wifi_off, context.getString(wifi ? R.string.title_allow : R.string.title_block), piWifi); // Build mobile action Intent riOther = new Intent(context, ServiceSinkhole.class); riOther.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set); riOther.putExtra(ServiceSinkhole.EXTRA_NETWORK, "other"); riOther.putExtra(ServiceSinkhole.EXTRA_UID, uid); riOther.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]); riOther.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !other); PendingIntent piOther = PendingIntent.getService(context, uid + 10000, riOther, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(other ? R.drawable.other_on : R.drawable.other_off, context.getString(other ? R.string.title_allow : R.string.title_block), piOther); // Show notification if (internet) NotificationManagerCompat.from(context).notify(uid, builder.build()); else { NotificationCompat.BigTextStyle expanded = new NotificationCompat.BigTextStyle(builder); expanded.bigText(context.getString(R.string.msg_installed, name)); expanded.setSummaryText(context.getString(R.string.title_internet)); NotificationManagerCompat.from(context).notify(uid, expanded.build()); } } catch (PackageManager.NameNotFoundException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } }
From source file:com.master.metehan.filtereagle.Receiver.java
public static void notifyNewApplication(int uid, Context context) { if (uid < 0) return;/*from w w w.ja va 2 s.c om*/ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); try { // Get application info String name = TextUtils.join(", ", Util.getApplicationNames(uid, context)); // Get application info PackageManager pm = context.getPackageManager(); String[] packages = pm.getPackagesForUid(uid); if (packages == null || packages.length < 1) throw new PackageManager.NameNotFoundException(Integer.toString(uid)); boolean internet = Util.hasInternet(uid, context); // Build notification Intent main = new Intent(context, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_REFRESH, true); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); PendingIntent pi = PendingIntent.getActivity(context, uid, main, PendingIntent.FLAG_UPDATE_CURRENT); Util.setTheme(context); TypedValue tv = new TypedValue(); context.getTheme().resolveAttribute(R.attr.colorPrimary, tv, true); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_security_white_24dp) .setContentTitle(context.getString(R.string.app_name)) .setContentText(context.getString(R.string.msg_installed, name)).setContentIntent(pi) .setColor(tv.data).setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET); } // Get defaults SharedPreferences prefs_wifi = context.getSharedPreferences("wifi", Context.MODE_PRIVATE); SharedPreferences prefs_other = context.getSharedPreferences("other", Context.MODE_PRIVATE); boolean wifi = prefs_wifi.getBoolean(packages[0], prefs.getBoolean("whitelist_wifi", true)); boolean other = prefs_other.getBoolean(packages[0], prefs.getBoolean("whitelist_other", true)); // Build Wi-Fi action Intent riWifi = new Intent(context, ServiceSinkhole.class); riWifi.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set); riWifi.putExtra(ServiceSinkhole.EXTRA_NETWORK, "wifi"); riWifi.putExtra(ServiceSinkhole.EXTRA_UID, uid); riWifi.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]); riWifi.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !wifi); PendingIntent piWifi = PendingIntent.getService(context, uid, riWifi, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(wifi ? R.drawable.wifi_on : R.drawable.wifi_off, context.getString(wifi ? R.string.title_allow : R.string.title_block), piWifi); // Build mobile action Intent riOther = new Intent(context, ServiceSinkhole.class); riOther.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set); riOther.putExtra(ServiceSinkhole.EXTRA_NETWORK, "other"); riOther.putExtra(ServiceSinkhole.EXTRA_UID, uid); riOther.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]); riOther.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !other); PendingIntent piOther = PendingIntent.getService(context, uid + 10000, riOther, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(other ? R.drawable.other_on : R.drawable.other_off, context.getString(other ? R.string.title_allow : R.string.title_block), piOther); // Show notification if (internet) NotificationManagerCompat.from(context).notify(uid, builder.build()); else { NotificationCompat.BigTextStyle expanded = new NotificationCompat.BigTextStyle(builder); expanded.bigText(context.getString(R.string.msg_installed, name)); expanded.setSummaryText(context.getString(R.string.title_internet)); NotificationManagerCompat.from(context).notify(uid, expanded.build()); } } catch (PackageManager.NameNotFoundException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } }
From source file:com.zhengde163.netguard.Receiver.java
public static void notifyNewApplication(int uid, Context context) { if (uid < 0) return;//from www . j a v a 2 s . co m SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); try { // Get application info String name = TextUtils.join(", ", Util.getApplicationNames(uid, context)); // Get application info PackageManager pm = context.getPackageManager(); String[] packages = pm.getPackagesForUid(uid); if (packages == null || packages.length < 1) throw new PackageManager.NameNotFoundException(Integer.toString(uid)); boolean internet = Util.hasInternet(uid, context); // Build notification Intent main = new Intent(context, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_REFRESH, true); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); PendingIntent pi = PendingIntent.getActivity(context, uid, main, PendingIntent.FLAG_UPDATE_CURRENT); // Util.setTheme(context); context.setTheme(R.style.AppThemeBlue); TypedValue tv = new TypedValue(); context.getTheme().resolveAttribute(R.attr.colorPrimary, tv, true); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_security_white_24dp) .setContentTitle(context.getString(R.string.app_name)) .setContentText(context.getString(R.string.msg_installed, name)).setContentIntent(pi) .setColor(tv.data).setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET); } // Get defaults SharedPreferences prefs_wifi = context.getSharedPreferences("wifi", Context.MODE_PRIVATE); SharedPreferences prefs_other = context.getSharedPreferences("other", Context.MODE_PRIVATE); boolean wifi = prefs_wifi.getBoolean(packages[0], prefs.getBoolean("whitelist_wifi", true)); boolean other = prefs_other.getBoolean(packages[0], prefs.getBoolean("whitelist_other", true)); // Build Wi-Fi action Intent riWifi = new Intent(context, ServiceSinkhole.class); riWifi.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set); riWifi.putExtra(ServiceSinkhole.EXTRA_NETWORK, "wifi"); riWifi.putExtra(ServiceSinkhole.EXTRA_UID, uid); riWifi.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]); riWifi.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !wifi); PendingIntent piWifi = PendingIntent.getService(context, uid, riWifi, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(wifi ? R.drawable.wifi_on : R.drawable.wifi_off, context.getString(wifi ? R.string.title_allow : R.string.title_block), piWifi); // Build mobile action Intent riOther = new Intent(context, ServiceSinkhole.class); riOther.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set); riOther.putExtra(ServiceSinkhole.EXTRA_NETWORK, "other"); riOther.putExtra(ServiceSinkhole.EXTRA_UID, uid); riOther.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]); riOther.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !other); PendingIntent piOther = PendingIntent.getService(context, uid + 10000, riOther, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(other ? R.drawable.other_on : R.drawable.other_off, context.getString(other ? R.string.title_allow : R.string.title_block), piOther); // Show notification if (internet) NotificationManagerCompat.from(context).notify(uid, builder.build()); else { NotificationCompat.BigTextStyle expanded = new NotificationCompat.BigTextStyle(builder); expanded.bigText(context.getString(R.string.msg_installed, name)); expanded.setSummaryText(context.getString(R.string.title_internet)); NotificationManagerCompat.from(context).notify(uid, expanded.build()); } } catch (PackageManager.NameNotFoundException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } }
From source file:com.github.sryze.wirebug.DebugStatusService.java
private void updateStatus() { Log.i(TAG, "Performing a status update..."); boolean isEnabled = DebugManager.isTcpDebuggingEnabled(); if (isEnabled != isCurrentlyEnabled) { Log.i(TAG, String.format("Status has changed to %s", isEnabled ? "enabled" : "disabled")); sendStatusChangedBroadcast(isEnabled); } else {//w w w. j av a 2s .co m Log.i(TAG, "Status is unchanged"); } if (keyguardManager.inKeyguardRestrictedInputMode() && preferences.getBoolean("disable_on_lock", false)) { Log.i(TAG, "Disabling debugging because disable_on_lock is true"); DebugManager.setTcpDebuggingEnabled(false); } if (isEnabled) { boolean isConnectedToWifi = NetworkUtils.isConnectedToWifi(connectivityManager); Log.d(TAG, String.format("Connected to Wi-Fi: %s", isConnectedToWifi ? "yes" : "no")); Intent contentIntent = new Intent(this, MainActivity.class); contentIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); Intent stopIntent = new Intent(this, DebugStatusService.class); stopIntent.setAction(ACTION_STOP); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder.setSmallIcon(R.drawable.ic_notification) .setContentTitle(getString(R.string.notification_title)) .setContentIntent( PendingIntent.getActivity(this, 0, contentIntent, PendingIntent.FLAG_CANCEL_CURRENT)) .addAction(R.drawable.ic_stop, getString(R.string.notification_action_stop), PendingIntent.getService(this, 0, stopIntent, PendingIntent.FLAG_CANCEL_CURRENT)); if (isConnectedToWifi) { notificationBuilder.setContentText(String.format(getString(R.string.notification_text), NetworkUtils.getWifiIpAddressString(wifiManager), NetworkUtils.getWifiNetworkName(wifiManager))); } else { notificationBuilder.setContentText(getString(R.string.notification_text_not_connected)); } if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { notificationBuilder.setCategory(Notification.CATEGORY_STATUS) .setVisibility(Notification.VISIBILITY_PUBLIC); } Notification notification = notificationBuilder.build(); notification.flags |= Notification.FLAG_NO_CLEAR; notificationManager.notify(STATUS_NOTIFICATION_ID, notification); } else { Log.d(TAG, "Canceling the notification"); notificationManager.cancel(STATUS_NOTIFICATION_ID); } if (isEnabled && preferences.getBoolean("stay_awake", false)) { if (wakeLock != null && !wakeLock.isHeld()) { Log.i(TAG, "Acquiring a wake lock because stay_awake is true"); wakeLock.acquire(); } } else { if (wakeLock != null && wakeLock.isHeld()) { Log.i(TAG, "Releasing the wake lock"); wakeLock.release(); } } isCurrentlyEnabled = isEnabled; }
From source file:com.abhinavjhanwar.android.egg.neko.Cat.java
public Notification.Builder buildNotification(Context context) { final Bundle extras = new Bundle(); extras.putString("android.substName", context.getString(R.string.app_name)); final Intent intent = new Intent(Intent.ACTION_MAIN).setClass(context, NekoLand.class) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return new Notification.Builder(context) .setSmallIcon(Icon.createWithResource(context, R.drawable.stat_icon)) .setLargeIcon(createLargeIcon(context)).setColor(getBodyColor()) .setPriority(Notification.PRIORITY_DEFAULT).setContentTitle(NekoService.notificationText) .setShowWhen(true).setCategory(Notification.CATEGORY_STATUS).setContentText(getName()) .setContentIntent(PendingIntent.getActivity(context, 0, intent, 0)).setAutoCancel(true) .setVibrate(PURR).addExtras(extras); }//from w w w . ja v a2 s. c om return new Notification.Builder(context).setSmallIcon(R.drawable.stat_icon) .setPriority(Notification.PRIORITY_DEFAULT).setContentTitle(OldService.notificationText) .setContentText(getName()).setContentIntent(PendingIntent.getActivity(context, 0, intent, 0)) .setAutoCancel(true).setVibrate(PURR); }
From source file:graaby.app.wallet.services.GcmIntentService.java
private void sendNotification(final String msg) { try {/*from ww w . jav a 2 s .co m*/ JSONObject object = new JSONObject(msg); PendingIntent pendingIntent = null; String notificationTitle, smallContentText, smallContentInfo = ""; int notificationImageResource = R.drawable.ic_noty_point, notificationID, uniquePendingId = (int) (System.currentTimeMillis() & 0xfffffff); SharedPreferences pref = getSharedPreferences("pref_notification", Activity.MODE_PRIVATE); Uri noty_sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (!TextUtils.isEmpty(pref.getString("notifications_new_message_ringtone", ""))) { noty_sound = Uri.parse(pref.getString("notifications_new_message_ringtone", "")); } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSound(noty_sound) .setLights(0xff2ECC71, 300, 1000).setAutoCancel(Boolean.TRUE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) mBuilder.setCategory(Notification.CATEGORY_SOCIAL); if (pref.getBoolean("notifications_new_message_vibrate", true)) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } Intent activityIntent = new Intent(); switch (NotificationType.getType(object.getInt(getString(R.string.field_gcm_msg_type)))) { case SHARE_POINTS: //user received points from contact String sender = object.getString(getString(R.string.field_gcm_name)); int amount = object.getInt(getString(R.string.contact_send_amount)); notificationTitle = getString(R.string.gcm_message_recieved_points); smallContentText = String.format(getString(R.string.gcm_message_recieved_points_content), sender, amount); smallContentInfo = String.valueOf(amount); notificationImageResource = R.drawable.ic_noty_point; notificationID = getRandomInt(0, 50); mBuilder.setColor(getResources().getColor(R.color.alizarin)); activityIntent.setClass(this, PointReceivedActivity.class); activityIntent.setAction(NOTIFICATION_ACTION_POINTS); activityIntent.putExtra(Helper.INTENT_CONTAINER_INFO, msg); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(PointReceivedActivity.class); stackBuilder.addNextIntent(activityIntent); Intent broadcastIntent = new Intent(this, GraabyBroadcastReceiver.class); broadcastIntent.setAction(GraabyBroadcastReceiver.ACTION_THANK); broadcastIntent.putExtra(Helper.INTENT_CONTAINER_INFO, msg); broadcastIntent.putExtra(Helper.NOTIFICATIONID, notificationID); PendingIntent pendingBroadcastIntent = PendingIntent.getBroadcast(this, uniquePendingId, broadcastIntent, 0); mBuilder.addAction(R.drawable.ic_action_accept, "Say thanks", pendingBroadcastIntent); pendingIntent = stackBuilder.getPendingIntent(uniquePendingId, PendingIntent.FLAG_ONE_SHOT); break; case TRANSACTION: //user made a transaction amount = object.getInt(getString(R.string.contact_send_amount)); String outlet = object.getString(getString(R.string.field_business_name)); notificationTitle = getString(R.string.gcm_message_transaction); smallContentText = String.format(getString(R.string.gcm_message_transaction_content), amount, outlet); smallContentInfo = String.valueOf(amount); notificationImageResource = R.drawable.ic_noty_point; notificationID = getRandomInt(51, 100); mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(smallContentText)); mBuilder.setColor(getResources().getColor(R.color.alizarin)); activityIntent.setClass(this, PointReceivedActivity.class); activityIntent.setAction(NOTIFICATION_ACTION_TX); activityIntent.putExtra(Helper.INTENT_CONTAINER_INFO, msg); activityIntent.putExtra(Helper.NOTIFICATIONID, notificationID); pendingIntent = PendingIntent.getActivity(this, 0, activityIntent, PendingIntent.FLAG_ONE_SHOT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) mBuilder.setCategory(Notification.CATEGORY_STATUS); break; case NEW_VOUCHER: //new marketplace voucher has appeared outlet = object.getString(getString(R.string.field_business_name)); notificationTitle = getString(R.string.gcm_message_market); if (object.has("msg")) smallContentText = object.getString("msg") + " @ " + outlet; else smallContentText = String.format(getString(R.string.gcm_message_market_content), outlet); smallContentInfo = ""; notificationImageResource = R.drawable.ic_gcm_discount; notificationID = NOTIFICATION_ID_NEW_MARKET; mBuilder.setStyle(new NotificationCompat.BigTextStyle() .bigText(String.format(getString(R.string.gcm_message_market_content), outlet))); mBuilder.setColor(getResources().getColor(R.color.sunflower)); activityIntent.setClass(this, MarketActivity.class); activityIntent.setAction(NOTIFICATION_ACTION_NEW_DISCOUNT); activityIntent.putExtra(Helper.INTENT_CONTAINER_INFO, msg); activityIntent.putExtra(Helper.NOTIFICATIONID, NOTIFICATION_ID_NEW_MARKET); activityIntent.putExtra(Helper.MY_DISCOUNT_ITEMS_FLAG, false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) mBuilder.setCategory(Notification.CATEGORY_PROMO); break; case NEW_FEED: notificationTitle = "New message"; smallContentText = object.getString("msg"); notificationImageResource = R.drawable.ic_noty_announcement; notificationID = NOTIFICATION_ID_FEED; activityIntent.setClass(this, FeedActivity.class); activityIntent.putExtra(Helper.NOTIFICATIONID, NOTIFICATION_ID_FEED); activityIntent.setAction(NOTIFICATION_ACTION_FEED); mBuilder.setColor(getResources().getColor(R.color.alizarin)); pendingIntent = TaskStackBuilder.create(this).addNextIntentWithParentStack(activityIntent) .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); break; case THANK_CONTACT: //contact thanks you for sending points String thanksString = object.getString(getString(R.string.field_gcm_name)); notificationTitle = getString(R.string.gcm_message_thanked); smallContentText = String.format(getString(R.string.gcm_message_thanked_small_content), thanksString); mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(smallContentText)); notificationImageResource = R.drawable.ic_noty_thank; notificationID = NOTIFICATION_ID_THANKED; mBuilder.setColor(getResources().getColor(R.color.belizehole)); break; case CHECKIN: //checkin notification outlet = object.getString(getString(R.string.field_gcm_name)); notificationTitle = getString(R.string.gcm_message_checkin_title); smallContentText = String.format(getString(R.string.gcm_message_checkin_small_content), outlet); notificationImageResource = R.drawable.ic_gcm_checkin; notificationID = NOTIFICATION_ID_CHECKIN; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) mBuilder.setCategory(Notification.CATEGORY_STATUS); mBuilder.setColor(getResources().getColor(R.color.wisteria)); break; case INFO_NEEDED: notificationTitle = getString(R.string.gcm_message_meta_info_title); smallContentText = getString(R.string.gcm_message_meta_info_title); notificationImageResource = R.drawable.ic_noty_information; notificationID = NOTIFICATION_ID_INFO; mBuilder.setColor(getResources().getColor(R.color.emarald)); activityIntent.setClass(this, ExtraInfoActivity.class); activityIntent.setAction(NOTIFICATION_ACTION_INFO); activityIntent.putExtra(Helper.INTENT_CONTAINER_INFO, msg); activityIntent.putExtra(Helper.NOTIFICATIONID, notificationID); pendingIntent = PendingIntent.getActivity(this, 0, activityIntent, PendingIntent.FLAG_UPDATE_CURRENT); break; case NONE: default: notificationTitle = ""; smallContentText = ""; smallContentInfo = ""; notificationID = 0; } if (pendingIntent == null) pendingIntent = PendingIntent.getActivity(this, 0, activityIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationManager mNotificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); mBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), notificationImageResource)) .setSmallIcon(R.drawable.ic_noty_graaby).setContentTitle(notificationTitle) .setContentText(smallContentText).setContentInfo(smallContentInfo) .setContentIntent(pendingIntent); mNotificationManager.notify(notificationID, mBuilder.build()); } catch (JSONException e) { e.printStackTrace(); } }
From source file:com.devbrackets.android.exomedia.EMNotification.java
/** * Returns a fully constructed notification to use when moving a service to the * foreground. This should be called after the notification information is set with * {@link #setNotificationBaseInformation(int, int)} and {@link #updateNotificationInformation(String, String, String, Bitmap, Bitmap)}. * * @param pendingIntent The pending intent to use when the notification itself is clicked * @return The constructed notification//www. j a v a2 s . c o m */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN) public Notification getNotification(@Nullable PendingIntent pendingIntent) { setClickPendingIntent(pendingIntent); RemoteViews customNotificationViews = getCustomNotification(); boolean allowSwipe = notificationInfo.getMediaState() == null || !notificationInfo.getMediaState().isPlaying(); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setContent(customNotificationViews); builder.setContentIntent(pendingIntent); builder.setDeleteIntent(createPendingIntent(EMRemoteActions.ACTION_STOP, mediaServiceClass)); builder.setSmallIcon(notificationInfo.getAppIcon()); builder.setAutoCancel(allowSwipe); builder.setOngoing(!allowSwipe); if (pendingIntent != null) { customNotificationViews.setOnClickPendingIntent(R.id.exomedia_notification_touch_area, pendingIntent); } //Set the notification category on lollipop if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setCategory(Notification.CATEGORY_STATUS); builder.setVisibility(Notification.VISIBILITY_PUBLIC); } //Build the notification and set the expanded content view if there is a service to inform of clicks Notification notification = builder.build(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && mediaServiceClass != null) { notification.bigContentView = getBigNotification(); notification.bigContentView.setOnClickPendingIntent(R.id.exomedia_big_notification_touch_area, pendingIntent); } return notification; }
From source file:com.devbrackets.android.playlistcore.helper.NotificationHelper.java
/** * Returns a fully constructed notification to use when moving a service to the * foreground. This should be called after the notification information is set with * {@link #setNotificationBaseInformation(int, int)} and {@link #updateNotificationInformation(String, String, String, Bitmap, Bitmap)}. * * @param pendingIntent The pending intent to use when the notification itself is clicked * @return The constructed notification//ww w . jav a 2 s . c om */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN) public Notification getNotification(@Nullable PendingIntent pendingIntent, @NonNull Class<? extends Service> serviceClass) { setClickPendingIntent(pendingIntent); RemoteViews customNotificationViews = getCustomNotification(serviceClass); boolean allowSwipe = notificationInfo.getMediaState() == null || !notificationInfo.getMediaState().isPlaying(); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setContent(customNotificationViews); builder.setContentIntent(pendingIntent); builder.setDeleteIntent(createPendingIntent(RemoteActions.ACTION_STOP, serviceClass)); builder.setSmallIcon(notificationInfo.getAppIcon()); builder.setAutoCancel(allowSwipe); builder.setOngoing(!allowSwipe); if (pendingIntent != null) { customNotificationViews.setOnClickPendingIntent(R.id.playlistcore_notification_touch_area, pendingIntent); } //Set the notification category on lollipop if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setCategory(Notification.CATEGORY_STATUS); builder.setVisibility(Notification.VISIBILITY_PUBLIC); } //Build the notification and set the expanded content view if there is a service to inform of clicks if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && mediaServiceClass != null) { RemoteViews bigNotificationView = getBigNotification(serviceClass); bigNotificationView.setOnClickPendingIntent(R.id.playlistcore_big_notification_touch_area, pendingIntent); builder.setCustomBigContentView(bigNotificationView); } return builder.build(); }