PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → Broadcast Receiver and CallWlProcedure
Broadcast Receiver and CallWlProcedure
Débuté par Ruben Sanchez Peña, 27 sep. 2016 20:07 - 6 réponses
Posté le 27 septembre 2016 - 20:07
Hi. In the thread http://27130.foren.mysnip.de/read.php… i can found the info for implement a BroadcastReceiver to fire an alarm and execute a code for it.

How i must write the code i want execute when the alarm fire?

I tried to use CallWlProcedure to execute a app global procedure, but the app crash it an activity is not running or the app is not running in background.

Anybody can share a working code sample where i could see how it must work?

Thank you

Rubén
Posté le 27 septembre 2016 - 20:58
Hi Ruben

I would think (not tested) that in order to implement that, yo wouldneed to use a persistant trhead so that your app is ALWAYS there in the background, ready to receive the alarm

Best regards
Posté le 27 septembre 2016 - 22:41
Hi Fabrice, thank you for your info. Persistent Thread was my first try. But then i must execute the app when de device start or open the app to launch the thread. For some extraneous reason if my app start with device and i have a persistent thread running then when i tap the app to open it, then it doesn't open and in the log i can see the app is blocked (not the exact words).

With Broadcast Receiver i can program an alarm and wake the device to execute a code. Noting is running in background and nothing must be executed when the device start to run.


My issue is when the alarm is fired and i must call to WM code from Java.

My current only is execute again the app to execute my code when the app is loaded, but i'm sure must exist a better mode.

Rubén
Posté le 28 septembre 2016 - 10:30
Hi,

What is the purpose of your application, you probably need to open it to set the alarms or times it needs to do the actions ?

What WM version are you on ? In v19/20 I have tried to do the same and call CallWlProcedure to execute my own WLanguage procedure to do some other stuff, but that did not work, the procedure was never found.

But I have tested, but its been a while so I don't know fur sure anymore that if you use the full qualified JAVA name (like you had to use also to define your broadcastreceiver), and also the name you will find in the classes generated by WM for your function that you want to call, it did work in that little test.

So you need something like this:

CallWlProcedure("GWDCPCOL_Java.MyFunctionName")

Where GWDCPCOL_Java is the name for the global procedures called COL_JAVA that you see in you WM editor project.

Hope you get it working
Danny
Posté le 28 septembre 2016 - 20:19
Hi Danny. Im using WM21.

I use your fantastic code for Broadcast Recever and now i need call a WM procedure from the Java code.

I have a global procedure to execute a query in a internet page, parse the text and advise to user if a word is present in the page text. I can run the procedure from a button in a Activity window and it works fine. But, if i call it from Java with CallWlProcedure then the app hang.

I will try including the global procedures file name, but i think i tried it without luck.

Thank you

Rubén
Posté le 29 septembre 2016 - 16:26
Hi again. I tried to add the global procedures file name to my called procedure without luck.

I tried too to call from Java source code to the static Class and Procedure generated by WM without luck too.

any idea more?

Thank you


Rubén
Posté le 05 octobre 2016 - 13:13
Hi again. After various tries with Broadcast receiver and WM21 i must forgive this option and try again the Persistent Thread option.

After rewrite the code i haven't Android errors of "app blocked" when i try to open the app while the Persistent Thread are runing and i have the "start running with Android" option checked.

Thank you for your help.

Rubén