Android Question PowerManager isPowerSaveMode() function

Nestor Castro Jr

Member
Licensed User
I saw this example before post this thread but it do not work for me. I want to know if battery saver mode is on or off, and do not want to avoid my app to be stopped from S.O.
I work with GPS and when the Battery Saver Mode is on, the GPS do not work properly
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
I saw this example before post this thread but it do not work for me. I want to know if battery saver mode is on or off, and do not want to avoid my app to be stopped from S.O.
I work with GPS and when the Battery Saver Mode is on, the GPS do not work properly
I did not explain myself. I said take this code as an example to fit your purpose.
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
This code will not resolve my problem. I need to check if Battery saver is on to alert user about disable this function to work fine in my app
I think you don't read. I said that the code MUST BE CHANGED. And just one example to get you on the right track.


Hello,

I found in Adroid SDK documentation one function to check if the Power Save Mode is On or Off.
https://developer.android.com/reference/android/os/PowerManager.html#isPowerSaveMode()

How can I call this function on B4A?


B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Activity.LoadLayout("Layout")
   
    Dim JavaObject1 As JavaObject
    JavaObject1.InitializeContext
    Dim risultato As Boolean = JavaObject1.RunMethod("isPowerSaveMode", Null)
    If risultato = True Then
        Log("PoweSaveMode is TRUE")
    Else
        Log("PoweSaveMode is False")
    End If

End Sub

#If JAVA
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;
import android.provider.Settings;
import android.net.Uri;
import anywheresoftware.b4a.BA;

public boolean isPowerSaveMode(){
Context context = this;
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
return pm.isPowerSaveMode();
}

#End If
 
Last edited:
Upvote 0

Nestor Castro Jr

Member
Licensed User
I think you don't read. I said that the code MUST BE CHANGED. And just one example to get you on the right track.





B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Activity.LoadLayout("Layout")
  
    Dim JavaObject1 As JavaObject
    JavaObject1.InitializeContext
    Dim risultato As Boolean = JavaObject1.RunMethod("isPowerSaveMode", Null)
    If risultato = True Then
        Log("PoweSaveMode is TRUE")
    Else
        Log("PoweSaveMode is False")
    End If

End Sub

#If JAVA
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;
import android.provider.Settings;
import android.net.Uri;
import anywheresoftware.b4a.BA;

public boolean isPowerSaveMode(){
Context context = this;
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
return pm.isPowerSaveMode();
}

#End If
Hello, I'm sorry. I really did not understand what do you mean in your first post.
Your example was useful. It works very smoothly.
Thanks
 
Upvote 0
Top