Sub KeepScreenOn(IsEnabled As Boolean)
'Prevents the screen from sleeping when the current Activity is in the foreground
Dim r As Reflector
r.Target = r.GetActivity
r.Target = r.RunMethod("getWindow")
Dim FLAG_KEEP_SCREEN_ON As Int = 128
If IsEnabled Then
r.RunMethod2("addFlags", FLAG_KEEP_SCREEN_ON, "java.lang.int")
Else
r.RunMethod2("clearFlags", FLAG_KEEP_SCREEN_ON, "java.lang.int")
End If
End Sub