Postingan

Menampilkan postingan dengan label BroadCast Code

BroadCast Battery Charging Status

//onCreate 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 status = intent.getIntExtra(BatteryManager.EXTRA_STATUS,-1); String statusString = ""; if(status == BatteryManager.BATTERY_STATUS_UNKNOWN){ statusString = "UNKNOWN"; }else if(status == BatteryManager.BATTERY_STATUS_CHARGING){ statusString = "CHARGING"; }else if(status == BatteryManager.BATTERY_STATUS_DISCHARGING){ statusString = "DISCHARGING"; }else if (status == BatteryManager.BATTERY_STATUS_NOT_CHARGING){ statusString = "NOT CHARGING"; }else if (status == BatteryManager.BATTERY_STATUS_FULL){ statusString = "FULL"; } textview1.setText("Batter...

BroadCast Battery Healt

//onCreate 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 health = intent.getIntExtra(BatteryManager.EXTRA_HEALTH,0); String healthString = ""; // Determine the battery health from return integer value if(health == BatteryManager.BATTERY_HEALTH_COLD){    healthString = "COLD"; }else if (health == BatteryManager.BATTERY_HEALTH_DEAD){    healthString = "DEAD"; }else if (health == BatteryManager.BATTERY_HEALTH_GOOD){    healthString = "GOOD"; }else if (health == BatteryManager.BATTERY_HEALTH_OVERHEAT){    healthString = "OVER HEAT"; }else if (health == BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE){    healthString = ...

BroadCast Battery Temperature

//OnCreate 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) { float temperature = (float)(intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE,0))/10; textview1.setText("Battery Temperature " + temperature +" "+ (char) 0x00B0 +"C"); } };

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); } };

BroadCast Battery Charging state

//onCreate 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 status = intent.getIntExtra(BatteryManager.EXTRA_STATUS,-1); boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL; if(isCharging){ textview1.setText("Charging : Yes."); int chargePlug = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED,-1); boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB; if(usbCharge){ textview1.setText(textview1.getText()+" USB Charging"); } boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC; if(acCharge){ textview1.setText(textview1.getText()+" AC Charging"); ...

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