I am creating a class which uses broadcast receiver. I want to receive the broadcast on unlocking of the phone. But there is some issue. Please help me out.
My Manifest.xml is :-
<receiver android:name=".MyReciever">
<intent-filter>
<intent-filter>
<action android:name="android.intent.action.ACTION_USER_PRESENT" />
<action android:name="android.intent.action.ACTION_BOOT_COMPLETED" />
<action android:name="android.intent.action.ACTION_SCREEN_ON" />
</intent-filter>
</intent-filter>
</receiver>
and my Broadcast reciever class :-
public class MyReiever extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("My Reciever","is intent null => " + (intent == null));
Log.d("My Reciever",intent.getAction()+"");
}
}
Though other application and services are receiving broadcast for "Screen_on" and "USer_Present" eg. WifiService.
There are two types of broadcast receivers: Static receivers, which you register in the Android manifest file. Dynamic receivers, which you register using a context.
A broadcast receiver (receiver) is an Android component which allows you to register for system or application events. All registered receivers for an event are notified by the Android runtime once this event happens.
Broadcast in android is the system-wide events that can occur when the device starts, when a message is received on the device or when incoming calls are received, or when a device goes to airplane mode, etc. Broadcast Receivers are used to respond to these system-wide events.
There are two ways to make a broadcast receiver known to the system: One is declare it in the manifest file with this element. The other is to create the receiver dynamically in code and register it with the Context. registerReceiver() method.
Although the Java constants are android.content.intent.ACTION_USER_PRESENT
, android.content.intent.ACTION_BOOT_COMPLETED
, and android.content.intent.ACTION_SCREEN_ON
, the values of those constants are android.intent.action.USER_PRESENT
, android.intent.action.BOOT_COMPLETED
, and android.intent.action.SCREEN_ON
. It is those values which need to appear in your manifest.
Note, however, that a receiver for ACTION_SCREEN_ON
can not be declared in a manifest but must be registered by Java code, see for example this question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With