I am having problems with my Broadcast not being received.
I have tried using a standard broadcast and a localbroadcast and neither will work.
This is the broadcast code:
Intent intent = new Intent();
intent.setAction(WIFI_SKIPPED_INTENT);
context.sendBroadcast(intent);
where WIFI_SKIPPED_INTENT = "com.wefi.wifi.skip"
And this is in my manifest:
<receiver
android:name="com.wefi.receivers.WifiSkipReceiver"
android:exported="true"
android:enabled="true">
<intent-filter>
<action android:name="com.wefi.wifi.skip" />
</intent-filter>
</receiver>
I added log commands before the sending and they are showing but logs in the receiver are not.
This happens on Android 11, Android 10 and Android 8 phones.
Edit:
If we register dynamically fro the receiver within the code then it works great. It fails only when registering through the manifest.
Related
As in title, broadcast receiver get called even no intent filter is specified in android manifest or in code. Even I specify concrete intent action in manifest like:
<receiver
android:icon="#drawable/ic_action_network_wifi_on"
android:name=".receivers.WifiReceiver">
<intent-filter>
<action android:name="android.intent.action.AIRPLANE_MODE"/>
</intent-filter>
</receiver>
The receiver get called when no airplane mode change.
Any ideas appreciated.
Hello I was trying to implement a custom Broadcast receiver for my Geofence app. I just went through the solution given here But I found that he is sending the broadcast from the receiver class which receives the same broadcast. can someone please tell me how this works. I have not worked much on custom broadcast.
He is sending the broadcast from one class and receiving it in another receiver. The line below is where he sends out the broadcast.
Intent intent = new Intent("com.aol.android.geofence.ACTION_RECEIVE_GEOFENCE");
Here is his manifest where he registers a receiver for that broadcast
<receiver android:name="com.aol.android.geofence.GeofenceReceiver"
android:exported="false">
<intent-filter >
<action android:name="com.aol.android.geofence.ACTION_RECEIVE_GEOFENCE"/>
</intent-filter>
</receiver>
you can send one Broadcast in another one with following code:
ntent local = new Intent();
local.setAction("BroadCastPath"); // like android.receiver.MyReceiver
context.sendBroadcast(local);
I am not able to receive the ACTION_TIME_CHANGED intent in my broadcast receiver class when I change the time from the phone. Is there anything in particular that I need to add in android.manifest?
I have already added
in broadcast receiver class:
else if((intent.getAction().equals(Intent.ACTION_TIME_CHANGED)) ||(intent.getAction().equals(Intent.ACTION_DATE_CHANGED ))){
Log.d("ContactsAppReceiver", "ACTION_TIME_CHANGED");
}
And in manifest.xml file. :
<action android:name="android.intent.action.ACTION_TIME_CHANGED"/>
Add to manifest:
<action android:name="android.intent.action.TIME_SET" />
Hi I'm writing a application for android that is started from boot up and i wondered if there was a way of telling the application it was started from the boot up of the device? i need it to do something different if the application was manual started (i.e not when the device was started). i am using a BroadcastReceiver to start the application when the device starts.
You could either make two different broadcast receivers one that has ACTION_BOOT_COMPLETED for the intent filter, and another that has the other intent filter that you would use.
Or create one broadcastreceiver that has two intent filters like:
<receiver android:name=".BatteryReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
<intent-filter>
<action android:name="SOMETHING_ELSE"/>
</intent-filter>
</receiver>
and then in the onReceiver do:
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
// do code for phone just powered on
} else {
// do code for phone is already on
}
EDIT:
The above assumes that you use the BroadcastReceiver under two circumstances, which may not be the case judging from your question.
So if you are starting an Activity (or service), then in the BroadcastReceiver code, you could do:
Intent i = new Intent(context, MyClass.class);
i.putExtra("STARTED_FROM_BOOT", true);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
Then in the activity, you could do:
if (getIntent().hasExtra("STARTED_FROM_BOOT")){
// do your code for when started from boot.
}
Let me know if I need to add anything.
yes, hook a broadcastreceiver with a on boot completed intent in the manifest and when the device boots up that receiver will be fired and you can do whatever you want there
<receiver android:name=".BatteryReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
I'm currently trying to catch states for ACTION_SCO_AUDIO_STATE_CHANGED as specified by:
http://developer.android.com/reference/android/media/AudioManager.html#ACTION_SCO_AUDIO_STATE_CHANGED
I have registered the intent on my manifest but I'm not getting anything when connecting to a bluetooth device. Any particular permission I need or something?
Manifest:
<receiver android:name="com.app.receiver.BluetoothReceiver">
<intent-filter>
<action android:name="android.media.SCO_AUDIO_STATE_CHANGED" />
<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED" />
<action android:name="android.bluetooth.device.action.BOND_STATE_CHANGED" />
</intent-filter>
</receiver>
I can't get any of the calls from BOND_STATE_CHANGED, SCO_AUDIO_STATE_CHANGED or ACL_DISCONNECT_REQUESTED. The other intents I'm receiving them just fine.
Thanks,
-Jona
It's probably a broadcast intent that cannot be received using the Manifest. You'll have to setup a BroadcastReceiver object and register it to receive the broadcast. The Receiver must be active in order to receive the intent.
Some broadcasts intents work like this while others are allowed to be caught via the manifest.
The other possibility is that the receiver requires a permission that you aren't requesting.
This is an important note from the SDK about Context.registerReceiver().
Note: this method cannot be called from a BroadcastReceiver component; that is, from a BroadcastReceiver that is declared in an application's manifest. It is okay, however, to call this method from another BroadcastReceiver that has itself been registered at run time with registerReceiver(BroadcastReceiver, IntentFilter), since the lifetime of such a registered BroadcastReceiver is tied to the object that registered it
<uses-permission android:name="android.permission.BROADCAST_STICKY"