PhoneWakeState.KeepAlive(True) funktioniert nicht / does not work

Amalkotey

Active Member
Licensed User
Longtime User
Hallo,

mit dem nachfolgenden Code möchte ih verhindern, das der Bildschirm bzw. das Handy im Ruhemodus geht. Leider funktioniert das nicht. Der bildschirm geht aus und bleibt nicht an. Was ist verkehrt an meiner Routine? Danke für euere Hilfe im Voraus.


In english:

Hello,

with the following code would prevent ih, which goes to the screen or the phone in standby mode. Unfortunately, this does not work. The screen goes out and not to remain. What is wrong with my routine? Thanks for your help in advance.

Cu
Amalkotey

B4X:
Sub imgWidget_Click
   Dim pws As PhoneWakeState

   Status = (Status + 1) Mod imgFiles.Length
   rv.SetImage("imgWidget", LoadBitmap(File.DirAssets, imgFiles(Status)))

   If Status = 1 Then
      pws.KeepAlive(True)     ' display stays on
   Else
      pws.ReleaseKeepAlive    ' display stays off
   End If

   rv.UpdateWidget            ' Update widget
End Sub
 

Amalkotey

Active Member
Licensed User
Longtime User
Once your process is killed the wake lock is released. You can call Service.StartForeground to prevent it from being killed.

Is this true for widgets? Must be the regular call, so I have to implement a timer?
 
Upvote 0

Amalkotey

Active Member
Licensed User
Longtime User
Error

Hello Erel,

Thanks for your help. I 've now changed my code below. It seems that it works. will test in life today. I give the Ergenis dnn known tomorrow.

B4X:
Sub Process_Globals
   Dim Notifikation As Notification

   Dim rv As RemoteViews
   Dim imgFiles() As String

   imgFiles = Array As String("bulboff.png", "bulbon.png")
   Dim Status As Int

   Dim Ti As Timer
   Ti.Initialize("UpdateTimer", 5000)
   Ti.Enabled = False
End Sub

Sub Service_Create
   ' Calculating the size of widgets based on the desired column
   ' (number of cells * 74) - 2) (1 * 74) - 2 = 72db
   rv = ConfigureHomeWidget("Widget", "rv", 30, "ScreenOn Widget")
   Notifikation.Initialize
   Notifikation.Sound = False
   Notifikation.Vibrate = False
End Sub

Sub Service_Start (StartingIntent As Intent)
   If rv.HandleWidgetEvents(StartingIntent) Then
      Return
   End If
End Sub

Sub rv_Disabled
   StopService("")
End Sub

Sub imgWidget_Click
   Dim pws As PhoneWakeState

   Status = (Status + 1) Mod imgFiles.Length
   rv.SetImage("imgWidget", LoadBitmap(File.DirAssets, imgFiles(Status)))

   If Status = 1 Then
      pws.KeepAlive(True)     ' display stays on
      Ti.Enabled = True
   Else
      pws.ReleaseKeepAlive    ' display stays off
      Ti.Enabled = False
   End If

   rv.UpdateWidget            ' Update widget
End Sub

Sub UpdateTimer_Tick
   Try
      Service.StartForeground(1, Notifikation)
   Catch
      imgWidget_Click
   End try
End Sub
 
Upvote 0
Top