Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to get battery rate on android devices
Forum Update on Monday, May 27th 2025

How to get battery rate on android devices

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
2 Posts 2 Posters 208 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KaanCL
    wrote on last edited by KaanCL
    #1

    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?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Melody242
      wrote on last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved