daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Jan 24th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Initialize a new BroadcastReceiver instance
  2. private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver()
  3. {
  4.     @Override
  5.     public void onReceive(Context context, Intent intent)
  6.     {            
  7.         // Get the battery scale----
  8.         int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE,-1);
  9.         // get the battery level----
  10.         int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL,-1);
  11.         // Calculate the battery charged percentage
  12.         float percentage = level/ (float) scale;
  13.         //Battery Percentage
  14.         int mProgressStatus = (int)((percentage)*100);
  15.     }
  16. }
  17.    
  18. // Initialize a new IntentFilter instance
  19. IntentFilter iFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
  20. // Register the broadcast receiver
  21. mContext.registerReceiver(mBroadcastReceiver,iFilter);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top