Search in sources :

Example 56 with NotificationManager

use of android.app.NotificationManager in project AprilBeacon-Android-SDK by AprilBrother.

the class NotifyService method generateNotification.

private static void generateNotification(Context context, String message) {
    Intent launchIntent = new Intent(context, NotifyInContentActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, new NotificationCompat.Builder(context).setWhen(System.currentTimeMillis()).setSmallIcon(R.drawable.ic_launcher).setTicker(message).setContentTitle(context.getString(R.string.app_name)).setContentText(message).setContentIntent(PendingIntent.getActivity(context, 0, launchIntent, 0)).setAutoCancel(true).build());
}
Also used : NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 57 with NotificationManager

use of android.app.NotificationManager in project AprilBeacon-Android-SDK by AprilBrother.

the class NotificationUtils method generateNotification.

public static void generateNotification(Context context, String message, String title) {
    Intent launchIntent = new Intent(context, NotifyInContentActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, new NotificationCompat.Builder(context).setWhen(System.currentTimeMillis()).setSmallIcon(R.drawable.ic_launcher).setTicker(message).setContentTitle(title).setContentText(message).setContentIntent(PendingIntent.getActivity(context, 0, launchIntent, 0)).setAutoCancel(true).build());
}
Also used : NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 58 with NotificationManager

use of android.app.NotificationManager in project AprilBeacon-Android-SDK by AprilBrother.

the class NotificationUtils method generateNotification.

public static void generateNotification(Context context, String message, String title) {
    Intent launchIntent = new Intent(context, NotifyInContentActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, new NotificationCompat.Builder(context).setWhen(System.currentTimeMillis()).setSmallIcon(R.drawable.ic_launcher).setTicker(message).setContentTitle(title).setContentText(message).setContentIntent(PendingIntent.getActivity(context, 0, launchIntent, 0)).setAutoCancel(true).build());
}
Also used : NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 59 with NotificationManager

use of android.app.NotificationManager in project AprilBeacon-Android-SDK by AprilBrother.

the class NotifyService method generateNotification.

private static void generateNotification(Context context, String message) {
    Intent launchIntent = new Intent(context, NotifyInContentActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, new NotificationCompat.Builder(context).setWhen(System.currentTimeMillis()).setSmallIcon(R.drawable.ic_launcher).setTicker(message).setContentTitle(context.getString(R.string.app_name)).setContentText(message).setContentIntent(PendingIntent.getActivity(context, 0, launchIntent, 0)).setAutoCancel(true).build());
}
Also used : NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 60 with NotificationManager

use of android.app.NotificationManager in project ETSMobile-Android2 by ApplETS.

the class ETSGcmListenerService method sendNotification.

/**
     * Create and show a simple notification containing the received GCM message.
     *
     * @param data GCM message received.
     */
private void sendNotification(Bundle data) {
    SecurePreferences securePreferences = new SecurePreferences(this);
    Gson gson = new Gson();
    String receivedNotifString = securePreferences.getString(Constants.RECEIVED_NOTIF, "");
    ArrayList<MonETSNotification> receivedNotif = gson.fromJson(receivedNotifString, new TypeToken<ArrayList<MonETSNotification>>() {
    }.getType());
    if (receivedNotif == null) {
        receivedNotif = new ArrayList<>();
    }
    MonETSNotification nouvelleNotification = getMonETSNotificationFromBundle(data);
    receivedNotif.add(nouvelleNotification);
    int numberOfNotifications = receivedNotif.size();
    Intent intent = new Intent(this, NotificationActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
    Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_ets);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.school_48).setColor(getResources().getColor(R.color.red)).setContentTitle(getString(R.string.ets)).setContentText(getString(R.string.new_notifications)).setContentIntent(pendingIntent).setLargeIcon(icon).setAutoCancel(true).setNumber(numberOfNotifications);
    NotificationCompat.InboxStyle inBoxStyle = new NotificationCompat.InboxStyle();
    // Sets a title for the Inbox in expanded layout
    String bigContentTitle = getString(R.string.notification_content_title, numberOfNotifications + "", (numberOfNotifications == 1 ? "" : "s"), (numberOfNotifications == 1 ? "" : "s"));
    inBoxStyle.setBigContentTitle(bigContentTitle);
    String username = ApplicationManager.userCredentials.getUsername();
    Spannable sb = new SpannableString(username);
    sb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, username.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    inBoxStyle.setSummaryText(sb);
    securePreferences.edit().putString(Constants.RECEIVED_NOTIF, gson.toJson(receivedNotif)).commit();
    int minimumIndex = receivedNotif.size() - NUMBER_OF_NOTIF_TO_DISPLAY;
    minimumIndex = minimumIndex < 0 ? 0 : minimumIndex;
    for (int i = receivedNotif.size() - 1; i >= minimumIndex; i--) {
        inBoxStyle.addLine(receivedNotif.get(i).getNotificationTexte());
    }
    if (numberOfNotifications > NUMBER_OF_NOTIF_TO_DISPLAY) {
        int plusOthers = (numberOfNotifications - NUMBER_OF_NOTIF_TO_DISPLAY);
        String plusOthersString = getString(R.string.others_notifications, plusOthers + "", (plusOthers == 1 ? "" : "s"));
        Spannable others = new SpannableString(plusOthersString);
        others.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, others.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        inBoxStyle.addLine(others);
    }
    mBuilder.setStyle(inBoxStyle);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(1, mBuilder.build());
}
Also used : MonETSNotification(ca.etsmtl.applets.etsmobile.model.MonETSNotification) NotificationManager(android.app.NotificationManager) Gson(com.google.gson.Gson) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) SecurePreferences(ca.etsmtl.applets.etsmobile.util.SecurePreferences) SpannableString(android.text.SpannableString) SpannableString(android.text.SpannableString) Bitmap(android.graphics.Bitmap) TypeToken(com.google.gson.reflect.TypeToken) StyleSpan(android.text.style.StyleSpan) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent) Spannable(android.text.Spannable)

Aggregations

NotificationManager (android.app.NotificationManager)930 Intent (android.content.Intent)400 PendingIntent (android.app.PendingIntent)397 Notification (android.app.Notification)276 NotificationCompat (android.support.v4.app.NotificationCompat)267 NotificationChannel (android.app.NotificationChannel)129 Uri (android.net.Uri)62 Context (android.content.Context)59 SharedPreferences (android.content.SharedPreferences)41 Bitmap (android.graphics.Bitmap)41 Resources (android.content.res.Resources)39 Bundle (android.os.Bundle)36 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)35 SuppressLint (android.annotation.SuppressLint)27 TargetApi (android.annotation.TargetApi)26 TaskStackBuilder (android.app.TaskStackBuilder)25 StatusBarNotification (android.service.notification.StatusBarNotification)24 IOException (java.io.IOException)22 File (java.io.File)20 IntentFilter (android.content.IntentFilter)18