Tag Archives: unregisterReceiver

Get Battery Percentage in Android – Different Methods

By | September 25, 2017

We will see the different ways to get the battery percentage in Android. Method 1 Register a Broadcast Receiver [java] IntentFilter iFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); // Register the broadcast receiver registerReceiver(mBroadcastReceiver, iFilter); [/java] Receive like this [java] private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // get the battery level int… Read More »

Local broadcast events with LocalBroadcastManager in Android

By | March 1, 2016

LocalBroadcastManager is Helper to register for and send broadcasts of Intents to local objects within your process. This is has a number of advantages over sending global broadcasts with sendBroadcast(Intent): You know that the data you are broadcasting won’t leave your app, so don’t need to worry about leaking private data. It is not possible for other applications… Read More »

Adding Notifications, Reading Notifications, Getting number of notifications in Android M.

By | February 20, 2016

This demo will show how to 1. Create and add a new Notification, 2. How many notifications are active in the current Application? 3. Delegate method for Notification Deletion. For Adding a Notification we can use the following snippet. [java] // Create a Notification and notify the system. final Notification.Builder builder = new Notification.Builder(getActivity()) .setSmallIcon(R.mipmap.ic_notification) .setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.sample_notification_content)) .setAutoCancel(true)… Read More »