Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.JTGD.nofitcation_channel_controller;
- import android.app.NotificationChannel;
- import android.app.NotificationManager;
- import android.content.Context;
- import android.os.Build;
- import android.util.Log;
- public class NotificationChannelCreator {
- //Creates an instance of the class
- private static final NotificationChannelCreator ourInstance = new NotificationChannelCreator();
- //Returns the instance of the class
- public static NotificationChannelCreator getInstance() {
- return ourInstance;
- }
- //Constructor, no code necessary here
- private NotificationChannelCreator() {
- }
- //Defines our channel IDs. This is what we will enter in our Firebase console
- //to send a message to a specific notification channel.
- public static final String CHANNEL_1_ID = "breaking_news";
- public static final String CHANNEL_2_ID = "daily_deals";
- //We will call this function from Unity when we open our application.
- //This will create the notification channels so we can send messages to them.
- private void createNotificationChannels(Context curContext){
- //Notification channels only work in Android Oreo or greater,
- //this checks to ensure the device is running Android Oreo or greater
- if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
- //Creates a log message. We use the 'Unity' tag so we can see it
- //along side other Unity Debug messages in our device logs.
- Log.i("Unity", "Creating Notification Channels");
- //Setting up the first notification channel.
- NotificationChannel channel1 = new NotificationChannel(
- CHANNEL_1_ID,
- "Breaking News",
- NotificationManager.IMPORTANCE_HIGH
- );
- channel1.setDescription("Get the latest news from this app!");
- //Setting up the second notification channel.
- NotificationChannel channel2 = new NotificationChannel(
- CHANNEL_2_ID,
- "Deals of the Day",
- NotificationManager.IMPORTANCE_HIGH
- );
- channel2.setDescription("See the latest deals as soon as they are announced!");
- //Get the notification manager of the application's context (from Unity)
- NotificationManager nManager = curContext.getSystemService(NotificationManager.class);
- //Create the two notification channels
- nManager.createNotificationChannel(channel1);
- nManager.createNotificationChannel(channel2);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement