AndroidNativeCore.NotificationManager
Description
This class issue notifications with big text and big image style with load big image from url it's useful for push notifications and create various notification channels.
Adding com.android.support:support-compat libreary
Downloade and install Unity play service resolver unity plugin if you have not add. Create folder Editor add below xml code and save it as androidDependencies.xml and resolve packages by Assets > Play Services Resolver > Android Resolver >force resolve.
Constants | |
---|---|
int |
IMPORTANCE_DEFAULT
Default notification importance: shows everywhere, allowed to makes noise, but does not visually intrude. |
int |
IMPORTANCE_HIGH
Higher notification importance: shows everywhere, allowed to makes noise and peek |
int |
IMPORTANCE_LOW
Low notification importance: shows everywhere, but is not intrusive |
int |
IMPORTANCE_MAX
Highest notification importance: shows everywhere, allowed to makes noise, peek, and use full screen intents. |
int |
IMPORTANCE_MIN
Min notification importance: only shows in the shade, below the fold. |
int |
IMPORTANCE_NONE
A notification with no importance: shows nowhere, is blocked. |
int |
IMPORTANCE_LOW
Low notification importance: shows everywhere, but is not intrusive |
int |
IMPORTANCE_MAX
Highest notification importance: shows everywhere, allowed to makes noise, peek, and use full screen intents. |
int |
IMPORTANCE_MIN
Min notification importance: only shows in the shade, below the fold. |
int |
IMPORTANCE_NONE
A notification with no importance: shows nowhere, is blocked. |
int |
PRIORITY_DEFAULT
Default notification priority. If your application does not prioritize its own notifications, use this value for all notifications. |
int |
PRIORITY_HIGH
Higher priority, for more important notifications or alerts. The UI may choose to show these items larger, or at a different position in notification lists, compared with your app's PRIORITY_DEFAULT items. |
int |
PRIORITY_LOW
Lower priority, for items that are less important. The UI may choose to show these items smaller, or at a different position in the list, compared with your app's PRIORITY_DEFAULT items. |
int |
PRIORITY_MAX
Highest priority, for your application's most important items that require the user's prompt attention or input. |
int |
PRIORITY_MIN
Lowest priority; these items might not be shown to the user except under special circumstances, such as detailed notification logs. |
int |
VISIBILITY_PUBLIC
Show this notification in its entirety on all lockscreens. |
int |
VISIBILITY_PRIVATE
Show this notification on all lockscreens, but conceal sensitive or private information on secure lockscreens. |
int |
VISIBILITY_SECRET
Do not reveal any part of this notification on a secure lockscreen. |
NotificationManager.Builder
Public methods | |
---|---|
NotificationManager.Builder |
Create(NotificationManager notificationManager,
string channelId) This method take NotificationManager and notification channel id as parameters |
NotificationManager.Builder |
setAutoCansel(bool AutoCansel) Auto cansel notification by bool value. |
NotificationManager.Builder |
setIcon(string resourseName) This method set notification icon takes drawable name you put on "Assets/Plugins/Android/res/drawable/" folder as parameter |
NotificationManager.Builder |
setSound(string resourseName) This method set custom notification sound. You need add notification sound at "Assets/Plugins/Android/res/raw/" folder and pass sound name as string without extension. |
NotificationManager.Builder |
setDefautlSound() This method set default sound for notifications. |
NotificationManager.Builder |
setBigImage(Texture2D largeicon) This method set big image to notification passing Texture2D as parameter. |
NotificationManager.Builder |
setBigImage(string url) This method fetch image from server by url and set it as bigimage of notification. This is method is useful for create push notification with image. |
NotificationManager.Builder |
setContentTitle(string title) This method set title to notification. |
NotificationManager.Builder |
setContentText(string text) This method set message to notification as big text style. |
NotificationManager.Builder |
setPriority(int priority) This method set notification priority by taking Priority constents. |
NotificationManager.Builder |
setGroup(string groupName,
bool showGroupSummery) This method show multiple notifications as group by assigning groupName.You can show or hide group summery by bool value. |
void |
notifi(int id) This method build and show notification with given configuration with passing intnotification id. |
NotificationManager.Channel
Description
Android notification channels are introduced form Android api level 28(Oreio). You need to create atleast one notification channel for issue notifications.
Public methods | |
---|---|
int |
importence
It sets notification importance by takeing constents in NotificationManager section. |
int |
lockScreenVisibility
It sets notification visibilty when device in locked mode by takeing constents in NotificationManager section. |
string |
id
It sets channel id |
string |
name
It sets channel name |
string |
description
It sets channel description |
string |
lightColor
It sets notification light color * color code must be in hex value like "#ffff" |
bool |
enableLights
It sets enable or disable lights when notification |
bool |
enableVibration
It sets enable or disable vibration when notification |
bool |
enableBadge
It sets show or hide notification badge at launcher icon. |
long[] |
vibrationPattren
It vibrate device in pattren while notification. |
Example
using AndroidNativeCore;
using UnityEngine;
public class Android:MonoBehaviour{
private NotificationManager notifyManager;
private NotificationManager.Channel channel;
void Start(){
//Create notification channel;
networkManager = new NetworkManager();
notifyManager = new NotificationManager();
channel = new NotificationManager.Channel();
channel.id = "notification_0";
channel.name = "Game Notification";
channel.importance = NotificationManager.IMPORTANCE_MAX;
channel.lockScreenVisibility = NotificationManager.VISIBILITY_PUBLIC;
channel.enableLights = true;
channel.enableVibration = true;
channel.enableBadge = true;
channel.lightColor = "#ffff";
channel.description = "Notifications from Android Native Core Unity3d Plugin";
notifyManager.createChannel(channel);
//Issue notification
notification = new Notification();
if(condition)
NotificationBigImage();
else
NotificationBigUrl();
}
public void NotificationBigImage()
{
NotificationManager.Builder notfi = new NotificationManager.Builder();
notfi.Create(notifyManager,"notification_0")
.setContentTitle("Android Native Core")
.setContentText("this notification with bigImage")
.setAutoCansel(true)
.setIcon("android_native_core")
.setSound("notification_sound")
.setGroup("Samples",true)
.setPriority(NotificationManager.PRIORITY_MAX)
.setGroup("GreatDeals",true)
.setBigImage(NotifiBigIcon)
.notify(1);
}
public void NotificationBigUrl()
{
NotificationManager.Builder notfi = new NotificationManager.Builder();
notfi.Create(notifyManager,"notification_0")
.setContentTitle("Android Native Core")
.setContentText("this notification with bigImage")
.setAutoCansel(true)
.setIcon("android_native_core")
.setSound("notification_sound")
.setGroup("Samples",true)
.setPriority(NotificationManager.PRIORITY_MAX)
.setGroup("GreatDeals",true)
.setBigImage("https://imaging.nikon.com/lineup/dslr/d800/img/sample01/img_01.png")
.notify(2);
}
}