Record the local notifications for the Android version of Unity Games in the form of plugins. This is the main reference. Make a slight change. Related files are shared with code on GitHub.
Implementation steps
1.Inside the Windows system, double-click Cdz_build.bat. A alarmreceiver.jar is generated in the current directory.
2.Copy the Alarmreceiver.jar into the assets\plugins\android\libs\ directory of the Unity project.
3.Generate a local notification:
Androidjavaobject nativeobj = new Androidjavaobject ("Com.macaronics.notification.AlarmReceiver"); Nativeobj.callstatic ("Startalarm", New Object[5]{title,title, MSG, Secondsfromnow, triggertimeint});
the meaning of the parameter:Title: Caption of the notification msg: content of the notification Secondsfromnow: the time distance from the notification is now the number of seconds Triggertimeint: a random number
Cancel all local notifications:
Androidjavaobject Playeractivitycontext = null;using (var actclass = new Androidjavaclass (" Com.unity3d.player.UnityPlayer ")) {Playeractivitycontext = Actclass.getstatic<androidjavaobject> (" CurrentActivity ");} using (Androidjavaclass Javaclass = new Androidjavaclass ("Com.macaronics.notification.AlarmReceiver")) { Javaclass.callstatic ("Clearnotification", Playeractivitycontext);}
Reference: Unity 3D + Local Notification for AndroidAndroid Alarmmanager Set up multiple timed events only last valid problem solvedPendingintentnotification.builderhow exactly to use Notification.builder
Document Information
- Original URL: http://blog.csdn.net/cdztop/article/details/39699675
- Last modified: October 01, 2014 14:47
Unity Android Local Notification