|
Implementation of java classes |
Iniciado por guenther.rathmayr, jun., 27 2019 3:56 PM - Sem resposta |
| |
| | | |
|
| |
Publicado em junho, 27 2019 - 3:56 PM |
Hi all,
I have got the problem, that my app gets in doze mode, also battery optimization feature in android device is switched off. I found the following example that should prevent my app to go to doze mode.
The compiler says "class AlarmBroadCastReceiver" unknown. For me it seems I have declared my java class AlarmBroadcastReceiver on the wrong place? Where do I have to declare a java class in Windev Mobile? Thanks for any advice.
Global procedure intern_SetAlarmWakeup import android.content.Context; import android.app.AlarmManager; import android.content.Intent; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.os.SystemClock;
public class AlarmBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if(intent!=null && context!=null) { callWLProcedure("AlarmManager fired..."); } } public void startAlarm(Context context) { if(PendingIntent.getBroadcast(context, 0, new Intent(context, this.class), PendingIntent.FLAG_NO_CREATE)==null) { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, SystemClock.elapsedRealtime(), 10000, PendingIntent.getBroadcast(context, 0, new Intent(context, AlarmBroadcastReceiver.class), 0)); } } } public static void intern_SetAlarmWakeup() { Context c; PowerManager pm; c = getApplicationContext(); if (c != null) { AlarmManager alarmManager = (AlarmManager)c.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(c, AlarmBroadCastReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, ALARM_REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT); if (Build.VERSION.SDK_INT >= 23) { alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, 30000, pendingIntent); } else if (Build.VERSION.SDK_INT >= 19) { alarmManager.setExact(AlarmManager.RTC_WAKEUP, 30000, pendingIntent); } else { alarmManager.set(AlarmManager.RTC_WAKEUP, 30000, pendingIntent); } } } |
| |
| |
| | | |
|
| | | | |
| | |
|