0

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.

sjain
  • 23,126
  • 28
  • 107
  • 185
  • have a look on this...http://stackoverflow.com/questions/18923207/call-activity-method-from-broadcast-receiver – GvSharma Sep 12 '14 at 08:51

1 Answers1

0

you probably want to do that:

<receiver
  android:name="com.iddl.main.IncomingBBStream"
  android:label="IncomingBBStream">

  <intent-filter>
     <action android:name="com.iddl.main.BBbroadcast"/>
     <category android:name="android.intent.category.DEFAULT"/>
  </intent-filter>

  <intent-filter>
     <action android:name="android.bluetooth.
             device.action.ACL_DISCONNECTED"/>
     <category android:name="android.intent.category.DEFAULT"/>
  </intent-filter>
</receiver>

each intent filter separate on its own tag and always include the default category.

Budius
  • 39,391
  • 16
  • 102
  • 144
  • Putting the action `"com.iddl.main.BBbroadcast"` inside `intent-filter` is giving warning in android manifest that `Exported receiver does not require permission`. This was the reason that I placed it outside of `intent-filter` tag. – sjain Sep 12 '14 at 08:58
  • it's just a warning. And it's a very silly one. Just do it, compile, run and test to see. ps: You probably want to add `exported="false"` on your receiver. That way outside applications can't send it. – Budius Sep 12 '14 at 09:00