PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → [WM19] Android Alarmmanager and BroadcastReceiver no not work ?
[WM19] Android Alarmmanager and BroadcastReceiver no not work ?
Iniciado por guest, 19,nov. 2014 14:55 - No hay respuesta
Publicado el 19,noviembre 2014 - 14:55
Hi all,

I am trying to use the Android Alarmmanager to set an Intent to check and if not running start my Windev Mobile application again so that it keeps running even when closed by user or Android system. Only when they logoff the application is actualy closed.

I have created the following Java code:

public static void JKeepAliveAlarm() { try { AlarmManager alarm; Calendar cal; PendingIntent alarmIntent; // Retrieve the current activity Activity tmpActivity = getCurrentActivity(); // Retrieve the current Context Context tmpContext = getApplicationContext(); cal = Calendar.getInstance(); alarm = (AlarmManager)tmpContext.getSystemService(tmpContext.ALARM_SERVICE); Intent myIntent = new Intent(tmpContext,AlarmReceiver.class); alarmIntent = PendingIntent.getBroadcast(tmpContext, 0, myIntent, 0); // Start every 30 seconds alarm.setInexactRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 30*1000, alarmIntent); Toast.makeText(tmpContext, "Keep Alive Alarm SET", Toast.LENGTH_LONG).show(); } catch(Exception e) { e.printStackTrace(); } }
I call this from the project code at startup. The toast is displayed so alarm is running.

The Receiverclass is defined as:

public class AlarmReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { try { Toast.makeText(context, "Alarm - Start", Toast.LENGTH_LONG).show(); // Try to start the app if not allready running // TODO Toast.makeText(context, "Alarm - End", Toast.LENGTH_LONG).show(); } catch(Exception e) { e.printStackTrace(); } } }
If the alarm would trigger I would see the toast on the screen. But nothing is executed, the receiver is not called ??!

I also added the Receiver to the Manifest:

[attachment 1247 ManifestPart.png]

I checked via the adb shell dumpsys alarm > dump.txt the status of the alarms and the alarm is created and is firing its event.

RTC_WAKEUP #0: Alarm{43854bb0 type 0 com.xxxx.yyyy}

type=0 when=+5s605ms repeatInterval=30000 count=1

operation=PendingIntent{432cadd0: PendingIntentRecord{430215c0 com.xxx.yyyy broadcastIntent}}

+1m38s35ms running, 101 wakeups, 101 alarms: com.xxx.yyyy

cmp={com.xxxx.yyyy/com.xxxx.yyyy.AlarmReceiver}

But my receiver is never called ? :confused:

I tried different names in the Manifest, but nothing seems to work.

I also use the alarmManager for updating the application by running an APK file after the program is closed, and this works fine.

I checked several Android sources on the internet and the basic configuration is in place. Being:
Create a class AlarmReceiver
Create a PendingIntent and setup this via the Alarmmanager
Change the Manifest to define the receiver

Does anybody has a working broadcast receiver in Windev Mobile 19 and can tell me what I am doing wrong ? Maybe there is something missing ?

Hope you can help me !
Thanks
Danny