BatteryBroadCast.java:
package com.ram.batteybroadcast;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
public class BatteryBroadCast extends BroadcastReceiver {
@Override
public void onReceive(Context c, Intent intent) {
int bStatus = intent.getIntExtra("level", 0);
Toast.makeText(c, "Battery Status :" + bStatus, Toast.LENGTH_LONG)
.show();
}
}
MainActivity.java:
package com.ram.batteybroadcast;
import android.app.Activity;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
registerReceiver(new BatteryBroadCast(), new IntentFilter(
Intent.ACTION_BATTERY_CHANGED));
}
}
I also maintain a blog for tutorials I completely appreciate
ReplyDeleteyour style of presentation should be very use full for not only beginners but also to experts
Hey it was really a nice article i was really impressed by reading this article on Android Online Training, In Hyderabad 123trainings also provide the best Android Online Training with an experienced faculty.
ReplyDelete