1

I have a Problem with my Broadcastreceiver and I have no idea what I am doing wrong.

I already read many posts @stackoverflow, but nothing helped.

I am sending a broadcast from my helperclass, the broadcastreceiver is implemented in an activity. I am putting an extra on the Intent at the helperclass before sending it, but the intent @ the activity has null extras. What am I doing wrong?

This is my sourcecode:

//Helperclass

    ...
    public static String BROADCAST_ACTION_DM = "de.je.toctohk.DISPLAYMESSAGE";
    ...
    public void method() {
       String msg = _intent.getStringExtra("message");
       Intent broadcast = new Intent();

       broadcast.setAction(BROADCAST_ACTION_DM);       
       broadcast.putExtra("msg", _chatentryid);

    sendStickyBroadcast(broadcast);      

}

//Activity

   private BroadcastReceiver receiver = new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        String test = getIntent().getStringExtra("msg");
        Toast.makeText(getApplicationContext(), intent.getExtras().getString("msg"), Toast.LENGTH_SHORT).show();



    }
};

protected void onResume() {
    IntentFilter filter = new IntentFilter();
    filter.addAction(GcmIntentService.BROADCAST_ACTION_DM);
    _testintent = registerReceiver(receiver, filter);
    super.onResume();
}

//Manifest

    <activity
        android:name="de.je.toctohk.activities.ChatActivity"
        android:label="@string/title_activity_push" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <action android:name="de.je.toctohk.DISPLAYMESSAGE" /> 
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

What I already tried:

  • normal broadcast

  • only registering the filter in the Activity

  • only registering the filter in the Manifest

  • Sticky broadcast

  • context.getIntent().getExtra…

  • intent.getExtra…

It would be great if somebody could give me some advises.

Thanks a lot!!

counters
  • 23
  • 6
  • what is the type of _chatentryid, i can't see from your code but are you positive it is a string? – Leonard Feehan Jun 24 '14 at 13:26
  • its an id right now. but its not working with a string either – counters Jun 24 '14 at 13:41
  • Unfortunately that is the only thing i can see in the code you have posted that could go wrong. if _chatentryid is an int when you send it from your helper you need to use intent.getExtras().getInt("msg"); also you really should check intent.getExtras() for null before getInt/getString. – Leonard Feehan Jun 24 '14 at 14:49
  • thanks for your answer. I have debugged the sourcecode and unfortunately the Extra Map of the Intent is empty. So howevery i'm going to call the extra it will be empty :( – counters Jun 24 '14 at 14:59

0 Answers0