- Home /
Question by
aleali-sina · Jan 27, 2019 at 01:08 PM ·
androidnotification
How to Create notification channel in android
Hi,
If you wanna using FCM (firebase cloud messaging), first you must create a channel with the ID you want to send from FCM service to a game, before sending any notification with this key.
What is the easiest way to create an android notification channel?
Comment
Answer by aleali-sina · Jan 27, 2019 at 01:09 PM
I use this code:
private void CreateChannel(string id, string name, string desc, int importance = 3)//3:default importance level
{
var SDK_INT = 0;
using (var version = new AndroidJavaClass("android.os.Build$VERSION"))
{
SDK_INT = version.GetStatic<int>("SDK_INT");
}
if (SDK_INT >= 26)
{
using (var NotificationChannel = new AndroidJavaObject("android.app.NotificationChannel", id, name, importance))
using (var unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
using (var context = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity"))
using (var notificationManager = context.Call<AndroidJavaObject>("getSystemService", "notification"))
{
NotificationChannel.Call("setDescription", desc);
notificationManager.Call("createNotificationChannel", NotificationChannel);
}
}
}
Your answer
Follow this Question
Related Questions
problem with checking application states on android and windows 0 Answers
How to put a permanent notification on phone? 0 Answers
Finding out if a user entered the game from notification (iOS/Android) 2 Answers
Local notification doesn't open the app android 0 Answers
Opening android notification setting menu from my app? 0 Answers