Hello everyone,
I want to get the battery level of the Android device and show it on the interface. I wrote the following function to do this. When I run this function on the Android side, the battery information is updated live. However, the C++ side calls this function only once and never again and the charge information is not updated.
public static BroadcastReceiver batteryReceiver = new BroadcastReceiver(){
@Override
public void onReceive(Context context , Intent intent){
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL,-1);
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE,-1);
BatteryLevel = (int) ((level / (float) scale) * 100);
}
};
public static int getBatteryLevel(){
return BatteryLevel;
}
How can I make this function be called continuously?