Giter Club home page Giter Club logo

godot-local-notification's Introduction

Local/Push notification plugin for Godot engine

This is a module for Godot Game Engine which add local and remote notification feature for iOS and Android.

Installation

  1. At first you need NativeLib-CLI or NativeLib Addon.

  2. Make nativelib -i local-notification in your project directory if you are using CLI. Find LOCAL-NOTIFICATION in plugins list and press "Install" button if you are using GUI Addon.

  3. Enable Custom Build for using in Android.

Usage

Add wrapper scripts/localnotification.gd into autoloading list in your project. So you can use it everywhere in your code.

API

show(message: String, title: String, interval: float, tag: int, repeating_interval: int = 0)

Show notification with title and message after delay of interval seconds with tag. You can override notification by it's tag before it was fired. If you defined repeating_interval the notification will be fired in a loop until you cancelled it.

show_daily(message: String, title: String, hour: int, minute: int, tag: int = 1)

Show notification daily at specific hour and minute (in 24 hour format). You can overide the notification with new time, or cancel it with tag and register a new one.

Need help: Currently just support ios, need help on Android

cancel(tag: int)

Cancel previously created notification.

cancel_all()

Cancel all pending notifications (implemented for iOS only).

init()

Request permission for notifications (iOS only).

is_inited() -> bool

Check if notification permission was requested from user (iOS only).

is_enabled() -> bool

Check if notification permission was granted by user (iOS only).

register_remote_notification()

Request system token for push notifications.

get_device_token() -> String

Returns system token for push notification.

get_notification_data() -> Dictionary

Returns custom data from activated notification (Android only).

get_deeplink_action() -> String

Returns action from deeplink, if exists. (Android only).

get_deeplink_uri() -> String

Returns deeplink URI, if exists (Android only).

Customising notifications for Android

The default notification color is defined in android/build/res/values/notification-color.xml. You can change it at your desire. The color string format is #RRGGBB.

In order to change default notification icon you should make this new files:

android/build/res/mipmap/notification_icon.png            Size 192x192
android/build/res/mipmap-hdpi-v4/notification_icon.png    Size 72x72
android/build/res/mipmap-mdpi-v4/notification_icon.png    Size 48x48
android/build/res/mipmap-xhdpi-v4/notification_icon.png   Size 96x96
android/build/res/mipmap-xxhdpi-v4/notification_icon.png  Size 144x144
android/build/res/mipmap-xxxhdpi-v4/notification_icon.png Size 192x192

Notification icons should be b/w with alpha channel. They will be tinted with color which we discuss above.

Use push notifications for iOS

  1. check if notifications is_inited, it means that application requested permissions from user.
  2. call init if app didn’t requested it yet.
  3. catch signal enabled or check method is_enabled. It will return false if user didn’t grant you permission.
  4. get device token (get_device_token) for push notifications or catch signal device_token_received
  5. send your device token to the server side.

That’s all. Sending notifications processed by your server, receiving notifications processed by OS.

Troubleshooting

If the notification doesn't appear, make sure you're not trying to display it while your game is in the foreground. In iOS, apps can only show notifications if they are in the background. This implies that you must use interval > 0.

godot-local-notification's People

Contributors

drmoriarty avatar florentflament avatar kyoz avatar ultramarinebicycle avatar virgil175 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

godot-local-notification's Issues

Note for iOS users

A note worth adding to the documentation, IMO:
If the notification doesn't appear, make sure you're not trying to display it while your game is in the foreground. In iOS, apps can only show notifications if they are in the background. This implies that you must use interval>0.

How to use it?

Could you tell me how to use it? I don't know where is "Globals" object. Your example doesn't work for me as my Godot don't know what is Globals.
Also, I prefer using C# but it doesn't matter. I wanna this code start working any way.

Android trouble?

What seems to be the problem on Android since it works like a charm !
You need POST_NOTIFICATIONS set as custom permission..
or is it just with the daily?

Opening a scene by clicking on a notification.

I think this is necessary for a notification plugin. I know how to open Activities in Android by clicking on a notification but don't know how that will work with Godot. If I can get some help in understanding this, I'll be happy to add this functionality.

Can't get device token in Android

I'm trying to use get_device_token() to get (what I think is) the registration token for sending push notifications via Firebase. I've installed the plugin, enabled the localnotification autoload, enabled custom build for Android exports, and enabled the Local Notification plugin for Android exports. When I try to print the device token, I get an empty string on Android. I see 'LocalNotification plugin inited' in my output before I try to print the device token, so that makes me think that the plugin should be working correctly.

I'm trying to get the token because I am following this guide on implementing push notifications for Android via a webserver: https://firebase.google.com/docs/cloud-messaging/send-message
The first code example uses a registration token that I think is acquired from the client application. I think this is the same token that I would get using get_device_token(), which I need to identify Android devices on my server.

No library on current platform error from godot (Windows)

Hello.
i love your notification plugin.
it took me minutes to set up for the 1st time
and it working out of the box in both Android and iOS platform!

i have small issue with it,
im using Windows and once i run godot, i have this issue:
image

also, when i run the project inside Windows, i get this error:
image

normally, those errors does not do anything since the notification does not support windows,
but is it possible for the errors NOT to show when im on windows?
can i modify the script somehow? or wait for the patch?

Feature request : a why to change notification sound

i loved this plugin so much
cuz i wanted to make an app that help me to remember when to start working (3 alarms with one click)
and I made that app with this plugin
but the problem is that i want to change the sound of the notification
cuz it just the same as any other app
is there any why to add this Feature to this amazing plugin ?

Invalid plugin config file

the title says it all:
image
it just keeps sending me this after I (I suppose I did it as it has to be done) installed the nativeLib and the LocalNotif addon.

using Godot 3.5.2 stable release + Windows

Can't get cancel for android notifications to work.

So for some reason I can't get the cancel function to work on android. Let's say I have to schedule 6 notifications, starting at 30 seconds and then incrementing by 1.5 seconds. That means the first notification should show up after 30 seconds, the second notifications should show up after 31.5 seconds and so on until all of them are scheduled. The flow goes like this:

  • Provide message as first argument to the show function.
  • Provide title as second argument to the show function.
  • Provide wait time as the third argument to the show function.
  • Provide the tag as the fourth argument to the show function but first convert wait time from float to int.
  • Push the tag to an array so it's possible to cancel all the notifications later.
  • When it's time to cancel, iterate of the array with the tags and call cancel with the tag as argument.

And from my understanding of the docs, cancelling should work as long as the tag parameter in the cancel function is the same as the one used when scheduling. But it's not working at all. And even the time when they show up is wrong. In my example they should start showing up after 30 seconds, but it takes a minute before they do.

Here's the code when scheduling

for text in next_knot_texts:
		waiting_time += wait_time
		LocalNotification.show(text, "She", waiting_time, int(waiting_time))
		notifications.append(int(waiting_time))

Here's the code when cancelling

func cancel_notificaitons():
	for tag in notifications:
		LocalNotification.cancel(tag)

No library set for this platform

Hi I am using windows 10, godot 3.2.3 stable and I have installed local notification from nativelib, (localnotification was added automatically to autoload) and then on export setting I checked use custom build and checked local notification on tab plugins.

When te app starts I put this: localnotification.show("Hi","hi x2",5,1)
and is not working, on logcat I got this:

12-30 23:16:36.779 19477 19627 E godot   : **ERROR**: No library set for this platform
12-30 23:16:36.779 19477 19627 E godot   :    At: modules/gdnative/gdnative.cpp:290:initialize() - No library set for this platform
12-30 23:16:37.346 19477 19627 E godot   : **ERROR**: Condition "err" is true. Returned: err
12-30 23:16:37.346 19477 19627 E godot   :    At: modules/gdscript/gdscript.cpp:829:load_source_code() - Condition "err" is true. Returned: err
12-30 23:16:37.346 19477 19627 E godot   : **ERROR**: Cannot load source code from file 'res://scripts/localnotification.gd'.
12-30 23:16:37.346 19477 19627 E godot   :    At: modules/gdscript/gdscript.cpp:2286:load() - Condition "err != OK" is true. Returned: RES()
12-30 23:16:37.346 19477 19627 E godot   : **ERROR**: Failed loading resource: res://scripts/localnotification.gd. Make sure resources have been imported by opening the project in the editor at least once.
12-30 23:16:37.346 19477 19627 E godot   :    At: core/io/resource_loader.cpp:279:_load() - Condition "found" is true. Returned: RES()
12-30 23:16:37.346 19477 19627 E godot   : **ERROR**: Can't autoload: res://scripts/localnotification.gd
12-30 23:16:37.346 19477 19627 E godot   :    At: main/main.cpp:1757:start() - Condition "res.is_null()" is true. Continuing.

Also I would like to know if with this type of notification I can send a notification at a certain time?

Workability with Godot 3.5 or 3.51

Did anyone tested the plugin with Godot 3.5 or higher? It worked well with 3.3 ish but not with higher releases (>= 3.5).

The app crashes and close.

Notifications after reboot

Is there any way to restore notifications set after a reboot? since after the reboot all notifications are deleted

Feature request: provisional notifications for iOS

Hi,
It would be very helpful to take advantage of iOS' provisional notification authorization. This allows skipping the permission pop-up for low-priority local notifications.

To request provisional authorization, add the provisional option when requesting permission to send notifications.

let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .sound, .badge, .provisional]) { granted, error in
    
    if let error = error {
        // Handle the error here.
    }
    
    // Provisional authorization granted.
}

Thanks for the diligent work.

Question about the implementation and running in background of the app.

Hi,

I was wondering about something but I can't find an explanation about it on your wiki page,

I was under the impression that to show notifications at all times an app must run in the background, when I searched on how to do this I read I needed to add external code outside of Godot to get this to work. Is this also required when using your add-in? or does this already take care of that?

[ios] Enhancement for ios repeating notification

The current behavior is still working but it lack the interval time to fire first notification, by looking at the implement code i can see that the interval param doesn't do anything.

The real life usage must be same as Android behavior, like, i set interval is 30 and repeating_interval is 86400. It will fire after 30 second and then at that exactly time next days.

But by reading apple's document, i just didn't find a way to make use of miliseconds to implement it. They must use NSDateComponent for this, like:

NSDateComponents* date = [[NSDateComponents alloc] init];
date.hour = 8;
date.minute = 30; 
UNCalendarNotificationTrigger* trigger = [UNCalendarNotificationTrigger
                     triggerWithDateMatchingComponents:date repeats:YES];

I'll think more about this and find a way to implement this.

Get Token not working

Hi on godot 3.2.2 and 3.2.4 on iOS, the module init perfect and I can get the request for notifications but when getting the token is not working (is not printing)

Repeating notification not working.

The repeating notification does not seem to be doing anything or working correctly. I ran
localnotification.show("Hello World", "Just a test", 5, 1, 5) and the notification showed up after 5 seconds but it didn't repeat after 5 seconds, it did, however, repeat a little bit later but I don't know how much later since I was no longer looking at my phone. I'm using android by the way.

repeating_interval seem working wrong

The idea is to show notification for user at exact time every day.

So i use it like:

show("Hello", "Hello", interval_time, 1, 86400)

But it seem what ever repeating_interval i'v set doesn't make any different, it's always looping in one minute (or around 1 minute)

Anyone have any ideas on this?

Questions about notifications

Hello! Thanks for the hard work, your libraries are very helpful.

I have a couple of questions. Sorry for bad English, I hope you can understand me.

  1. Can I receive push notifications using firebase?
    How can i do this?

  2. Also I see in the README
    get_device_token () -> String
    and register_remote_notification () but they don't work and return nothing am I right?

  3. Can I set a specific time for scheduled notifications? Will this work if the application is closed?

compile ios framework

Hi!
is there any guide for the compilation of the ios framework?
couldnt manage to do it in any way.
thanks!

Having an error "no valid small icon"

Hi,
thank you for this plugin, I am trying it now and i have this error at runtime (on Android Api 24):

05-11 13:30:24.726  5075  5075 E AndroidRuntime: java.lang.RuntimeException: Unable to start receiver org.godotengine.godot.LocalNotificationReceiver: java.lang.IllegalArgumentException: Invalid notification (no valid small icon): Notification(pri=0 contentView=null vibrate=default sound=default tick defaults=0xffffffff flags=0x11 color=0x00000000 vis=PRIVATE)
05-11 13:30:24.726  5075  5075 E AndroidRuntime: 	at org.godotengine.godot.LocalNotificationReceiver.onReceive(LocalNotificationReceiver.java:55

What do you think we should do ?

[iOS] no sound for local notification

Finally i'v success use this plugin on iOS, it working perfectly. But doesn't know why the notification doesn't have sound.

I'v read through the docs but there's no info about this. Do i have to config it somewhere else...

Thank you very much ❤️

Gradle build error using androidx

Hi, the last commit (44f630f) is not passing in the gradle build. I'm not an Android expert, so I don't know what "androidx" means.

Also, compiling at 879ee2b is raising this error: #2

Gradle build errors:

:compileDebugJavaWithJavacC:\Users\Usuario\Documents\Godot\godot-3\modules\localnotification\android\src\LocalNotificationReceiver.java:11: error: package androidx.core.app does not exist
import androidx.core.app.NotificationCompat;
                        ^
C:\Users\Usuario\Documents\Godot\godot-3\modules\localnotification\android\src\LocalNotificationReceiver.java:33: error: package NotificationCompat does not exist
                NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
                                  ^
C:\Users\Usuario\Documents\Godot\godot-3\modules\localnotification\android\src\LocalNotificationReceiver.java:33: error: package NotificationCompat does not exist
                NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
                                                                           ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
3 errors
 FAILED

FAILURE: Build failed with an exception.

Quick actions without opening app itself

How do I set up notifications so that there are several quick actions at the bottom (like "Reply" or "Mute" in a messaging app), and how do I make the app respond to notifications without opening up in the foreground?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.