Android Question Is it possible to prevent the screen turning off when pressing the power button?

eurojam

Well-Known Member
Licensed User
Longtime User
I have created a service with a broadcastreceiver on the intent android.intent.action.SCREEN_OFF. After receiving the intent I want to restart the screen with the intent android.intent.action.SCREEN_ON. This produces a permission error:
java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.SCREEN_ON from pid=10631, uid=10079

are there other possibilities?

my code looks like this:
B4X:
#Region  Service Attributes
    #StartAtBoot: False
   
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim Broadcast As BroadCastReceiver
   
End Sub

Sub Service_Create
  Broadcast.Initialize("BroadcastReceiver")
 
End Sub

Sub Service_Start (StartingIntent As Intent)
   Broadcast.addAction("android.intent.action.SCREEN_OFF")
   Broadcast.SetPriority(2147483647)
   Broadcast.registerReceiver( "")
End Sub

Sub Service_Destroy

End Sub
Sub BroadcastReceiver_OnReceive (Action As String, i As Object)
  Dim i2 As Intent = i
  Log(i2.Action)
  Dim i3 As Intent
  i3.Initialize("android.intent.action.SCREEN_ON","")
  Dim p As Phone
  p.SendBroadcastIntent(i3)
End Sub

thanks in advance
stefan
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…