BroadCast Battery Voltage

//InCreate

IntentFilter iFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
getApplicationContext().registerReceiver(mBroadcastReceiver,iFilter);


private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(getApplicationContext(), "Received", Toast.LENGTH_SHORT).show();
int voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE,0);
double volt =  voltage * 0.0
java.text.DecimalFormat newFormat = new java.text.DecimalFormat("#.#");
double oneDecimalVolt =  Double.valueOf(newFormat.format(volt));
textview1.setText("Battery Voltage");
textview1.setText(textview1.getText() +"
Millivolts : " + voltage);
textview1.setText(textview1.getText() + "
Volt : " + oneDecimalVolt);
}
};

Komentar

Cara pembuatan Apps paling Populer

Create Stopwatch App in Android using Sketchware

TextInputLayout in Sketchware

How to find and​ highlight a word in a text field in Sketchware?

A Flash Light App in Sketchware

How to enable download in webview in Sketchware apps?

Intent - Open File By Type

Code for implementing Notifications in Sketchware

How to share an image from Drawable folder?

ActionBar back button

Animation Transtition Animation