1.

Is it possible to remove and add intent filters from activity based on user preference?

Answer»

For checking the status of BatteryLow and sending information to the user,  we can create a BroadCast Receiver who will send a triggers battery LOW notification that you see on your mobile screen.

A Broadcast Receiver is an Android component which ALLOWS you to register for system or application events. Once Event occur it will Broadcast message to the user.

There are two steps to create a Broadcast Receiver:

  • Create a SUBCLASS of Android’s BroadcastReceiver.
  • Implement the onReceive() method: in our case ,for generate  battery low notification, the receiver is registered to Intent.ACTION_BATTERY_LOW event. As soon as the battery level falls below the defined level, this onReceive() method is called.
<receiver android:name=".SampleBroadcastReceiver"> <intent-filter>         <action android:name=" android.intent.action.BATTERY_LOW "/>     </intent-filter> </receiver>
  • At LAST, we will call our Broadcast Receiver using Implicit Intent.
Intent intent = NEW Intent(this, Reciver.class); sendBroadcast(intent);


Discussion

No Comment Found

Related InterviewSolutions