Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Create a notification if the application is being sent to background (i.e behind
- * another application's Activity).
- *
- * @param context the context of the application
- * @param message the message to show in the notification bar
- */
- private static void generateNotification(Context context, String message) {
- Log.d(TAG, "Entered generateNotification()...........");
- //PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
- //if (Util.isRunningInBackground(context) || !powerManager.isScreenOn()) {
- long when = System.currentTimeMillis();
- // This Intent will explicitly activate the notification sub-activity
- Intent notificationIntent = new Intent(context, NotificationActivity.class);
- notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
- notificationIntent.setAction(NOTIFICATION_MESSAGE_ACTION);
- notificationIntent.putExtra(EXTRA_MESSAGE, message);
- // get the pending Intent
- PendingIntent pendingIntent = PendingIntent.getActivity(context, NOTIFICATION_ID, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
- Uri notificationSoundDefaultUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
- Notification.Builder notificationBuilder = new Notification.Builder(context)
- .setTicker(message)
- .setContentText(message)
- .setAutoCancel(true)
- .setContentIntent(pendingIntent)
- .setSound(notificationSoundDefaultUri)
- .setWhen(when)
- .setSmallIcon(R.drawable.logo)
- .setContentTitle(context.getString(R.string.app_name));
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
- Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle();
- bigTextStyle.bigText(message);
- notificationBuilder.setStyle(bigTextStyle);
- }
- android.app.NotificationManager notificationManager = (android.app.NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
- notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement