Shell code for notifications. Updated credit information.
This commit is contained in:
parent
b48673d776
commit
0d74c776ef
20 changed files with 1897 additions and 0 deletions
Binary file not shown.
Binary file not shown.
10
MoCha/Assets/SimpleAndroidNotifications.meta
Normal file
10
MoCha/Assets/SimpleAndroidNotifications.meta
Normal file
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2df7842d377a9a84abfb17bc840cbab4
|
||||
folderAsset: yes
|
||||
timeCreated: 1525117456
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
1568
MoCha/Assets/SimpleAndroidNotifications/DemoScene.unity
Normal file
1568
MoCha/Assets/SimpleAndroidNotifications/DemoScene.unity
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 04bafa369dbac00478feecb96bf71f90
|
||||
timeCreated: 1504018996
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
BIN
MoCha/Assets/SimpleAndroidNotifications/Manual.pdf
Normal file
BIN
MoCha/Assets/SimpleAndroidNotifications/Manual.pdf
Normal file
Binary file not shown.
8
MoCha/Assets/SimpleAndroidNotifications/Manual.pdf.meta
Normal file
8
MoCha/Assets/SimpleAndroidNotifications/Manual.pdf.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 25883581d81d38b44b43224baa0c1bbe
|
||||
timeCreated: 1473442595
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,53 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.SimpleAndroidNotifications
|
||||
{
|
||||
public class NotificationExample : MonoBehaviour
|
||||
{
|
||||
public void Rate()
|
||||
{
|
||||
Application.OpenURL("http://u3d.as/y6r");
|
||||
}
|
||||
|
||||
public void OpenWiki()
|
||||
{
|
||||
Application.OpenURL("https://github.com/hippogamesunity/SimpleAndroidNotificationsPublic/wiki");
|
||||
}
|
||||
|
||||
public void ScheduleSimple()
|
||||
{
|
||||
NotificationManager.Send(TimeSpan.FromSeconds(5), "Simple notification", "Customize icon and color", new Color(1, 0.3f, 0.15f));
|
||||
}
|
||||
|
||||
public void ScheduleNormal()
|
||||
{
|
||||
NotificationManager.SendWithAppIcon(TimeSpan.FromSeconds(5), "Notification", "Notification with app icon", new Color(0, 0.6f, 1), NotificationIcon.Message);
|
||||
}
|
||||
|
||||
public void ScheduleCustom()
|
||||
{
|
||||
var notificationParams = new NotificationParams
|
||||
{
|
||||
Id = UnityEngine.Random.Range(0, int.MaxValue),
|
||||
Delay = TimeSpan.FromSeconds(5),
|
||||
Title = "Custom notification",
|
||||
Message = "Message",
|
||||
Ticker = "Ticker",
|
||||
Sound = true,
|
||||
Vibrate = true,
|
||||
Light = true,
|
||||
SmallIcon = NotificationIcon.Heart,
|
||||
SmallIconColor = new Color(0, 0.5f, 0),
|
||||
LargeIcon = "app_icon"
|
||||
};
|
||||
|
||||
NotificationManager.SendCustom(notificationParams);
|
||||
}
|
||||
|
||||
public void CancelAll()
|
||||
{
|
||||
NotificationManager.CancelAll();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3a71b5771fef6424bb435eb90ac4c555
|
||||
timeCreated: 1470125386
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
12
MoCha/Assets/SimpleAndroidNotifications/NotificationIcon.cs
Normal file
12
MoCha/Assets/SimpleAndroidNotifications/NotificationIcon.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
namespace Assets.SimpleAndroidNotifications
|
||||
{
|
||||
public enum NotificationIcon
|
||||
{
|
||||
Bell,
|
||||
Clock,
|
||||
Event,
|
||||
Heart,
|
||||
Message,
|
||||
Star
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 243b640bb54d927499ad71bfe4b8137e
|
||||
timeCreated: 1473424878
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
123
MoCha/Assets/SimpleAndroidNotifications/NotificationManager.cs
Normal file
123
MoCha/Assets/SimpleAndroidNotifications/NotificationManager.cs
Normal file
|
@ -0,0 +1,123 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
|
||||
using System.Linq;
|
||||
|
||||
#endif
|
||||
|
||||
namespace Assets.SimpleAndroidNotifications
|
||||
{
|
||||
public static class NotificationManager
|
||||
{
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
|
||||
private const string FullClassName = "com.hippogames.simpleandroidnotifications.Controller";
|
||||
private const string MainActivityClassName = "com.unity3d.player.UnityPlayerActivity";
|
||||
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Schedule simple notification without app icon.
|
||||
/// </summary>
|
||||
/// <param name="smallIcon">List of build-in small icons: notification_icon_bell (default), notification_icon_clock, notification_icon_heart, notification_icon_message, notification_icon_nut, notification_icon_star, notification_icon_warning.</param>
|
||||
public static int Send(TimeSpan delay, string title, string message, Color smallIconColor, NotificationIcon smallIcon = 0)
|
||||
{
|
||||
return SendCustom(new NotificationParams
|
||||
{
|
||||
Id = UnityEngine.Random.Range(0, int.MaxValue),
|
||||
Delay = delay,
|
||||
Title = title,
|
||||
Message = message,
|
||||
Ticker = message,
|
||||
Sound = true,
|
||||
Vibrate = true,
|
||||
Light = true,
|
||||
SmallIcon = smallIcon,
|
||||
SmallIconColor = smallIconColor,
|
||||
LargeIcon = ""
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Schedule notification with app icon.
|
||||
/// </summary>
|
||||
/// <param name="smallIcon">List of build-in small icons: notification_icon_bell (default), notification_icon_clock, notification_icon_heart, notification_icon_message, notification_icon_nut, notification_icon_star, notification_icon_warning.</param>
|
||||
public static int SendWithAppIcon(TimeSpan delay, string title, string message, Color smallIconColor, NotificationIcon smallIcon = 0)
|
||||
{
|
||||
return SendCustom(new NotificationParams
|
||||
{
|
||||
Id = UnityEngine.Random.Range(0, int.MaxValue),
|
||||
Delay = delay,
|
||||
Title = title,
|
||||
Message = message,
|
||||
Ticker = message,
|
||||
Sound = true,
|
||||
Vibrate = true,
|
||||
Light = true,
|
||||
SmallIcon = smallIcon,
|
||||
SmallIconColor = smallIconColor,
|
||||
LargeIcon = "app_icon"
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Schedule customizable notification.
|
||||
/// </summary>
|
||||
public static int SendCustom(NotificationParams notificationParams)
|
||||
{
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
|
||||
var p = notificationParams;
|
||||
var delay = (long) p.Delay.TotalMilliseconds;
|
||||
|
||||
new AndroidJavaClass(FullClassName).CallStatic("SetNotification", p.Id, delay, p.Title, p.Message, p.Ticker,
|
||||
p.Sound ? 1 : 0, p.Vibrate ? 1 : 0, p.Light ? 1 : 0, p.LargeIcon, GetSmallIconName(p.SmallIcon), ColotToInt(p.SmallIconColor), MainActivityClassName);
|
||||
|
||||
#else
|
||||
|
||||
Debug.LogWarning("Simple Android Notifications are not supported for current platform. Build and play this scene on android device!");
|
||||
|
||||
#endif
|
||||
|
||||
return notificationParams.Id;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cancel notification by id.
|
||||
/// </summary>
|
||||
public static void Cancel(int id)
|
||||
{
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
|
||||
new AndroidJavaClass(FullClassName).CallStatic("CancelScheduledNotification", id);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cancel all notifications.
|
||||
/// </summary>
|
||||
public static void CancelAll()
|
||||
{
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
|
||||
new AndroidJavaClass(FullClassName).CallStatic("CancelAllScheduledNotifications");
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
private static int ColotToInt(Color color)
|
||||
{
|
||||
var smallIconColor = (Color32) color;
|
||||
|
||||
return smallIconColor.r * 65536 + smallIconColor.g * 256 + smallIconColor.b;
|
||||
}
|
||||
|
||||
private static string GetSmallIconName(NotificationIcon icon)
|
||||
{
|
||||
return "anp_" + icon.ToString().ToLower();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0126c966198c04149a015ab2e2993d7c
|
||||
timeCreated: 1470125384
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,26 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.SimpleAndroidNotifications
|
||||
{
|
||||
public class NotificationParams
|
||||
{
|
||||
/// <summary>
|
||||
/// Use random id for each new notification.
|
||||
/// </summary>
|
||||
public int Id;
|
||||
public TimeSpan Delay;
|
||||
public string Title;
|
||||
public string Message;
|
||||
public string Ticker;
|
||||
public bool Sound = true;
|
||||
public bool Vibrate = true;
|
||||
public bool Light = true;
|
||||
public NotificationIcon SmallIcon;
|
||||
public Color SmallIconColor;
|
||||
/// <summary>
|
||||
/// Use "" for simple notification. Use "app_icon" to use the app icon. Use custom value but first place image to "simple-android-notifications.aar/res/". To modify "aar" file just rename it to "zip" and back.
|
||||
/// </summary>
|
||||
public string LargeIcon;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 21f9537b0dde1ff499b93870d79d2169
|
||||
timeCreated: 1470161197
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
9
MoCha/Assets/SimpleAndroidNotifications/Plugins.meta
Normal file
9
MoCha/Assets/SimpleAndroidNotifications/Plugins.meta
Normal file
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1ae4658634a06794699458349d94b91a
|
||||
folderAsset: yes
|
||||
timeCreated: 1470052745
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 05659514faf5c00438b20237116fb96d
|
||||
folderAsset: yes
|
||||
timeCreated: 1470052745
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
|
@ -0,0 +1,23 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 452bdd37e0400c94491ff114e437eba0
|
||||
timeCreated: 1470202238
|
||||
licenseType: Store
|
||||
PluginImporter:
|
||||
serializedVersion: 1
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
isPreloaded: 0
|
||||
platformData:
|
||||
Android:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
Any:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
Editor:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
Reference in a new issue