So in fragment class, I have a AsyncTask
class and there I am calling BroadcastReceiver
at onPostExecute()
method of AsyncTask
-
Android Manifest -
<receiver
android:name="com.iddl.main.IncomingBBStream"
android:label="IncomingBBStream">
<action android:name="com.iddl.main.BBbroadcast" />
<intent-filter>
<action android:name="android.bluetooth.
device.action.ACL_DISCONNECTED" />
</intent-filter>
</receiver>
Fragment Class -
@Override
protected void onPostExecute(Void result)
{
Intent intent = new Intent();
intent.setAction("com.iddl.main.BBbroadcast");
intent.putExtra("uuid", uuid);
getActivity().sendBroadcast(intent);
}
BroadcastReceiver Class -
public class IncomingBBStream extends BroadcastReceiver {
public void onReceive(Context context, Intent intent)
{
Log.i(TAG, "onReceive BroadcastReceiver------");
}
It should at least print the log message but it not doing so.
NOTE:
I have to add intent.setClass(getActivity(), IncomingBBStream.class);
to get it work but that doesn't make sense because I already passed the action "com.iddl.main.BBbroadcast"
that matches with the manifest's receiver name "com.iddl.main.IncomingBBStream"
. So it knows which class to call.