If you mean a change in battery status on the emulator, follow these steps: Connect to the emulator via telnet and change the state and capacity
> telnet localhost 5554 Android Console: type 'help' for a list of commands OK power ac off OK power discharging OK power capacity 21 OK exit >
Well, you can do what he says on the page mentioned by Ted, and then use a handler to show the toast. This is the code you need to add to your activity.
private Handler handler = new Handler; private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver() { @Override public void onReceive(final Context context, Intent intent) { int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0); int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100); Log.i(TAG, "level: " + level + "; scale: " + scale); int percent = (level*100)/scale; final String text = String.valueOf(percent) + "%"; handler.post( new Runnable() { public void run() { Toast.makeText(context, text, Toast.LENGTH_SHORT).show(); } }); } };
source share