Android Question How to detect Screen On / Screen Off by intent?

susu

Well-Known Member
Licensed User
Longtime User
Hi,
I can detect screen on/off by using PhoneEvents but to check it for long run, I need to use service and must to display notification icon. So I want to detect it by intent with this.

Manifest code:
B4X:
AddPermission(android.permission.READ_PHONE_STATE)
AddReceiverText(service1, 
<intent-filter>
        <action android:name="android.intent.action.SCREEN_OFF"/>
        <action android:name="android.intent.action.SCREEN_ON"/>
 </intent-filter>
)

service1 code:
B4X:
Sub Service_Start (StartingIntent As Intent)
    If StartingIntent.Action = "android.intent.action.SCREEN_ON" Then
        Log("Screen On")
    End If

    If StartingIntent.Action = "android.intent.action.SCREEN_OFF" Then
        Log("Screen Off")
    End If
End Sub

However, it didn't work. :D So I need your suggestions. Thank you.
 

susu

Well-Known Member
Licensed User
Longtime User
But I'm using an app that can detect screen on/off without using service. How can they do that?
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
If it use a service why I don't see notification icon? (Tested it on Android 5.1.1).
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
The process is running all the time.
I kill this app from recent list, even clean RAM but it still running.

it doesn't have any problem monitoring the user present intent
Could you please give me a hint? I just know only one way by using Service.
 
Upvote 0
Top