Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: intent.putExtra in a Service Class to get notifications

This is my showNotification method in the Service class:

private void showNotification() {

Notification notification = new Notification(R.drawable.icon,
"New Notification", System.currentTimeMillis());

Intent i = new Intent(this, myActivity.class);
i.putExtra("notification", "MyNotif");
i.putExtra("notifiedby", "NotedBy");
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, 0);
notification.setLatestEventInfo(this, "NotedBy", "MyNotif", contentIntent);
nm.notify(111, notification);
}

so after clicking on the Notification from the status bar, i will end up in myActivity.

The problem is these lines always gives false in the myActivity.

this.getIntent().hasExtra("notification")
this.getIntent().hasExtra("notifiedby")

Doesn't putExtra() work with PendingIntent??

like image 842
Archie.bpgc Avatar asked Oct 10 '12 13:10

Archie.bpgc


1 Answers

Try this code instead:

String notification = getIntent().getStringExtra("notification");
String notifiedby = getIntent().getStringExtra("notifiedby");
like image 177
Anup Cowkur Avatar answered Oct 26 '22 00:10

Anup Cowkur