Help With Notifications-System

Monkey Targets Forums/Android/Help With Notifications-System

Duke87(Posted 2015) [#1]
Hi Guys,

I could need some help.

I'd like to have a function for sending a notification to the Android System. (Similar to WhatsApp Notifies, when something new Happend).
My App shall send at least once a day a notify. And best would be, if the User can enter the App by Clicking on the Notification.

I have never coded with native Code in Monkey. Does anybody here has some experiances for something like that?

Well within the AVD-Emulator i Found "ApiDemos/src/com/example/android/apis/app/IncomingMessage.java" this could fit my needs.
Just start the AVD -> start a virtual device. goto Apps, start API Demos, search App, click on it then search for Notification and start IncomingMessage. Thats how it should look like in Monkey.

Thank You.

Stephan D


sygem(Posted 2015) [#2]
Something like this?


Duke87(Posted 2015) [#3]
Just watched your source, will test it tomorrow and tell you how it works. But as i think i understand the source, it could fit my needs :). Thank you very much for sharing anyway


sygem(Posted 2015) [#4]
No problem - it's still a work-in-progress module, not tested in a real app. Let me know how you get on, and if there are any improvements I could make to the API.


Duke87(Posted 2015) [#5]
On my Andoird Emulator the: Schedule part doesn't work :(
[Code]
Local localn:LocalNotification = New LocalNotification()
localn.SetBody("Take a Picture") ' Will appear in the notification
localn.AddExtra("monkey rules", "data") ' optional, can be retrieved later
localn.SetID(0) ' a unique id - use this to cancel notifications
localn.ScheduleAfter(60) ' number of seconds to wait before firing
[/Code]
Maybe it's just an emulator issue, my Akku is empty, so i can't test it on my Phone right now, maybe in 2 hours.
If it should Schedule my Console prints:
E/dalvikvm( 1212): Could not find class 'com.sygem.monkey.notify.AlarmNotification', referenced from method de.dukegames.noty.NativeLocalNotification.NativeScheduleAfter

This works perfectly.
[Code]
Local localn:LocalNotification = New LocalNotification()
localn.SetBody("App has been suspended") ' Will appear in the notification
localn.Schedule()
[/Code]

Another question:
Is it possible to set a notification at a special time, like 8:00 am ?
if not, i will think of a function that will calculate the difference between OnSuspend to a specific time and schedule it.

Edit:
Just found:
#ANDROID_MANIFEST_APPLICATION+="<receiver android:name=~qcom.sygem.monkey.notify.AlarmNotification~q />"
within your localnotification.monkey. shall i change it to my App name?

Edit2:
I've changed, but doesn't run either.
Maybe, if it helps here my whole App:
[Codebox]
Import mojo
Import brl
Import notify

#GLFW_WINDOW_TITLE="Notify"
#GLFW_WINDOW_WIDTH=1900
#GLFW_WINDOW_HEIGHT=1080
#GLFW_WINDOW_FULLSCREEN=False

#rem
##### ANDROID PREPROCESSOR DIRECTIVES ####
#end
#ANDROID_APP_LABEL="Notificator"
#ANDROID_APP_PACKAGE="de.dukegames.noty"
#ANDROID_SCREEN_ORIENTATION="portrait" '"user", "portrait", "landscape"
#ANDROID_GAMEPAD_ENABLED=False
#ANDROID_VERSION_CODE="1"
#ANDROID_VERSION_NAME="0.1"
#ANDROID_KEY_STORE="../../release-key.keystore"
#ANDROID_KEY_ALIAS="release-key-alias"
#ANDROID_KEY_STORE_PASSWORD="password"
#ANDROID_KEY_ALIAS_PASSWORD="password"
#ANDROID_SIGN_APP=False
#ANDROID_NATIVE_GL_ENABLED=False

#OPENGL_GLES20_ENABLED=False
#OPENGL_GLES20_ENABLED=false
#OPENGL_DEPTH_BUFFER_ENABLED=false

#MOJO_AUTO_SUSPEND_ENABLED=True
#MOJO_IMAGE_FILTERING_ENABLED=false

#TEXT_FILES="*.txt|*.xml|*.json"
#IMAGE_FILES="*.png|*.jpg|*.gif|*.bmp"
#SOUND_FILES="*.wav|*.ogg|*.mp3|*.m4a"
#MUSIC_FILES="*.wav|*.ogg|*.mp3|*.m4a"
#BINARY_FILES="*.bin|*.dat|*.map"

'########################## HAUPTFUNKTION DER APPLIKATION #########################################
Function Main:Int()
New Game
End Function

Global DW:Float,DH:Float

Class Game Extends App

Method OnCreate:Int()
SetUpdateRate 60

Return True
End Method

Method OnUpdate:Int()
DW = DeviceWidth()
DH = DeviceHeight()

If TouchHit()
'Works fine
'Local localn:LocalNotification = New LocalNotification()
'localn.SetBody("Touch hit") ' Will appear in the notification
'localn.Schedule() ' Will be raised immediately
Endif
End Method


Method OnRender:Int()
Cls
DrawText "NOTIFY",50,50

Return True
End Method

'When app will be suspended
Method OnSuspend:Int()
'Error on Console
'E/dalvikvm( 1287): Could not find class 'com.sygem.monkey.notify.AlarmNotification', referenced from method de.dukegames.noty.NativeLocalNotification.NativeScheduleAfter
Local localn:LocalNotification = New LocalNotification()
localn.SetBody("Take a Picture") ' Will appear in the notification
localn.AddExtra("monkey rules", "data") ' optional, can be retrieved later
localn.SetID(0) ' a unique id - use this to cancel notifications
localn.ScheduleAfter(5) ' number of seconds to wait before firing

'if its uncommented it works ....
'Local localn:LocalNotification = New LocalNotification()
'localn.SetBody("App has been suspended") ' Will appear in the notification
'localn.Schedule()
Return 0
End

Method OnClose:Int()
Local localn:LocalNotification = New LocalNotification()
localn.SetBody("On Close") ' Will appear in the notification
localn.AddExtra("monkey rules", "data") ' optional, can be retrieved later
localn.SetID(0) ' a unique id - use this to cancel notifications
localn.ScheduleAfter(5) ' number of seconds to wait before firing
EndApp()
Return 0
End Method
End Class
[/Codebox]


sygem(Posted 2015) [#6]
Can you make sure that the alarmreceiver.jar is copied into your project? It is in the localn/native/android directory, and should be copied to the 'libs' directory of your build.

You need to keep the manifest line intact - BroadcastReceivers in Java need to be public classes, which for Monkey means they need to be in a separate java file. I have packaged this up into a jar file to keep things simple (I'll add the source for the alarmreceiver at some point).

I tried your test, and it works on my phone.

I have thought about scheduling at a given time. Monkey doesn't have a Date class, so expressing the time would be a little tricky.


Duke87(Posted 2015) [#7]
Thank you, will try it.

At the moment I'm think of the Time Problem:
This will give you the parts of the Date/Time

Edit:
[Code]
Local date:=GetDate()
Print "Day: " + date[2]
Print "Month: " + date[1]
Print "Yeahr: " + date[0]
Print "Hour: " + date[3]
Print "Min: " + date[4]
Print "Sec: " + date[6]

[/Code]

next would be, to write a function that can calculate the difference of two dates in Seconds.


Duke87(Posted 2015) [#8]
and yes, both, the alarmreciever and the android-support-v4.jar are in my libs folder, and it doesn't work


Duke87(Posted 2015) [#9]
Maybe, because i use Android Api3 Build ?
When i use Api 10 it says: BUILD FAILED
C:\Android\android-sdk\tools\ant\build.xml:541: Unable to resolve project target 'android-19'
I'll look up whats the reason, maybe i get it fixed


Duke87(Posted 2015) [#10]
Ok it now works fine here as well. I just had to update my SDK.