Ewan Arends
Ewan Arends

Reputation: 41

Android 5.1 Notificatios

For school i just need to make a simple app that will notifiy me when i press the button.

I made up the class for the activity but the google docs are for android 8.0 oreo and not for my development version of android (5.1.1).

does anyone know how to send a notification (as i think i figured out how to make one)?

thanks,

Ewan

my class:

https://gist.github.com/Tebreca/f310b7d921caff04eaddc530521ce824

Upvotes: 1

Views: 219

Answers (1)

hemen
hemen

Reputation: 1490

This will set you for life ;)

PendingIntent pIpanel=" you can do this :

    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
        if (LOG_DEBUG) Log.v(TAG, " : version : <=M ");

        //noinspection deprecation
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                .setContentTitle(context.getString(R.string.notification_title))
                .setContentText(context.getString(R.string.notification_subtext))
                .setSmallIcon(R.drawable.ic_notification)
                .setAutoCancel(true)
                .setLights(Color.CYAN, 500, 1200)
                .setPriority(Notification.PRIORITY_MAX)
                .setContentIntent(pIpanel)
                .setStyle(new NotificationCompat.DecoratedCustomViewStyle());

        notification = builder.build();



    } else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.N | Build.VERSION.SDK_INT == Build.VERSION_CODES.N_MR1) {
        if (LOG_DEBUG) Log.v(TAG, " : version : N| N1 - 24: 25 ");

        //noinspection deprecation
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                .setContentTitle(context.getString(R.string.notification_title))
                .setContentText(context.getString(R.string.notification_subtext))
                .setSmallIcon(R.drawable.ic_notification)
                .setAutoCancel(true)
                .setLights(Color.CYAN, 500, 1200)
                .setPriority(Notification.PRIORITY_MAX)
                .setContentIntent(pIpanel)

                .setStyle(new NotificationCompat.DecoratedCustomViewStyle());

        notification = builder.build();


    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        if (LOG_DEBUG) Log.v(TAG, " : version : >=O ");


        NotificationChannel mChannel = new NotificationChannel
                (NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);

        mChannel.setDescription(NOTIFICATION_CHANNEL_DESCRIPTION);
        mChannel.enableLights(true);
        mChannel.setLightColor(Color.CYAN);
        mChannel.enableVibration(true);
        notificationManager.createNotificationChannel(mChannel);

        NotificationChannelGroup mGroup = new NotificationChannelGroup(NOTIFICATION_GROUP_ID, NOTIFICATION_GROUP_NAME);
        notificationManager.createNotificationChannelGroup(mGroup);

        NotificationCompat.Builder builder = new NotificationCompat.Builder
                (context, NOTIFICATION_CHANNEL_ID)

                .setContentTitle(context.getString(R.string.notification_title))
                .setContentText(context.getString(R.string.notification_subtext))
                .setSmallIcon(R.drawable.ic_notification)
                .setAutoCancel(true)
                .setContentIntent(pIpanel)

                .setStyle(new NotificationCompat.DecoratedCustomViewStyle());

        notification = builder.build();
    }

    if (notificationManager != null) {
        notificationManager.notify(NOTIFICATION_ID, notification);
    }

Upvotes: 1

Related Questions