BROADCAST NOT RECIEVED WHEN CALLED BY AN INTENT

Norman Reedus

Total Post:45

Points:315
Posted by  Norman Reedus
 1059  View(s)
Ratings:
Rate this:

I have broadcast which is recieved on system boot as well as by an intent. This broadcast is to set alarm.

Intent intent = new Intent();

intent.setAction("recievers.BroadCastBootRec");

intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);

getActivity().sendBroadcast(intent);

My Broadcast class :

@Override

public void onReceive(Context context, Intent intent) {

    c = context;

    Log.d("HirakDebug", "BroadCast Recieved");

    getDatesFromDatabase();

    getDateDifference();

    setAlarmI();

}

Manifest.xml

<receiver android:name=".recievers.BroadCastBootRec"

        android:label="BootReceiver">

    <intent-filter>

        <action android:name="android.intent.action.BOOT_COMPLETED" />

        <category android:name="android.intent.category.DEFAULT"/>

    </intent-filter>

</receiver>

  1. Hugh Jackman

    Post:52

    Points:366
    Re: Broadcast not recieved when called by an intent

    You have to register two actions and to make things clear. android:name is the Class name of the receiver you had written, not the action. So, for the below receiver your receiver class name will be "BroadCastBootRec"

    <receiver android:name=".recievers.BroadCastBootRec"

        android:label="BootReceiver">

    <intent-filter>

        <action android:name="com.example.BroadCastBootRec" />

        <action android:name="android.intent.action.BOOT_COMPLETED" />

        <category android:name="android.intent.category.DEFAULT"/>

    </intent-filter>

    </receiver>

    Intent intent = new Intent();

    intent.setAction("com.example.BroadCastBootRec");

    intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);

    getActivity().sendBroadcast(intent);

    The android system will inform your receiver when ever an action BOOT_COMPLETED andcom.example.BroadCastBootRec is triggered

    public class BroadCastBootRec extends BroadcastReceiver

      @Override

      public void onReceive(Context context, Intent intent) {

       c = context;

       Log.d("HirakDebug", "BroadCast Recieved");

       getDatesFromDatabase();

       getDateDifference();

       setAlarmI();

    }

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!