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!!