So I've been trying to register Intent.ACTION_DREAMING_STARTED
inside my AndroidManifest
without success.
<application>
...
<receiver android:name=".broadcastReceivers.DreamingReceiver">
<intent-filter>
<action android:name="android.intent.action.DREAMING_STOPPED"/>
<action android:name="android.intent.action.DREAMING_STARTED"/>
</intent-filter>
</receiver>
...
</application>
Here's the definition of the receiver.
public class DreamingReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Log.d("DreamingReceiver", "Intent: " + intent.getAction());
}
}
When daydream actually starts, there's just no log from that BroadcastReceiver.
However, when I define the receiver in my Activity
's onCreate
method like so:
this.receiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
Log.d("Activity Dreaming", "Intent: " + intent.getAction());
}
};
IntentFilter filter = new IntentFilter(Intent.ACTION_DREAMING_STARTED);
filter.addAction(Intent.ACTION_DREAMING_STOPPED);
this.registerReceiver(this.receiver, filter);
I do receive the log whenever my device is entering/leaving daydream.
Is there a reason why the BroadcastReceiver
that I defined in my AndroidManifest doesn't catch the Intent ?
Apparently, this doesn't need any permission according the the Intent
reference
FYI, running on Android KitKat 4.4
Unfortunately the actions DREAMING_STARTED
and DREAMING_STOPPED
are marked with the flag FLAG_RECEIVER_REGISTERED_ONLY
as you can see here:
private final Intent mDreamingStartedIntent = new Intent(Intent.ACTION_DREAMING_STARTED)
.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
private final Intent mDreamingStoppedIntent = new Intent(Intent.ACTION_DREAMING_STOPPED)
.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
Quoting developer.android.com:
public static final int FLAG_RECEIVER_REGISTERED_ONLY
If set, when sending a broadcast only registered receivers will be called -- no BroadcastReceiver components will be launched.
So you can't receive these intent with a BroadcastReceiver
declared in the AndroidManifest.xml
. Your only option is to register dynamically the BroadcastReceiver
.
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