android:how to open the app on clicking on push notification - android

I have implemented the push notifications using C2DM code in my project. It is showing push notifications But my problem is how to open the app on clicking on the push notification.
I am doing it like:
Intent intent = new Intent(context, BingoDiaryActivity.class);
intent.putExtra("registration_id", registrationId);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
notification.setLatestEventInfo(context, "Registration", "Successfully registered",
pendingIntent);
notificationManager.notify(0, notification);
But it is not working
Can anyone helps me over this?
Thanks

I can't understand what's wrong with you code, but in my project works this - and clicking on notifier open my app:
n.setLatestEventInfo(context, "text", "text",
PendingIntent.getActivity(
context,
0,
context.getPackageManager().getLaunchIntentForPackage(context.getPackageName())
.putExtra("extra_name", extra),
0));

Related

phonegap local notification

i have implemented a local notification in my android app using phonegap
localnotification plugin.
notification get trigger properly but while clicking on notification
app does not open.
what i want to relaunch a app on clicking of status notification.
Thanks and regards
In AlarmReciever class, in onRecieve event, change the line 79,
final PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
to
final PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context,mainActivity.class), 0);
It starts, new activity

Displaying a notification in android

I am using the following code to show a notification in my android application, but using this, with the notification an activity also shows up (i.e. a black blank screen) I dont want this screen, but just a simple notification and when the user clicks the notification then I want to launch the activity. What should be done to this code?
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notify = new Notification(R.drawable.mcube_logo, "Message Sent", Calendar.getInstance().getTimeInMillis());
Intent intent = new Intent(RecieveAlarm.this, otherActivity.class);
PendingIntent pendingIntent =PendingIntent.getActivity(RecieveAlarm.this, 1, null, PendingIntent.FLAG_CANCEL_CURRENT);
notify.setLatestEventInfo(RecieveAlarm.this, "Title", "Details", pendingIntent);
notificationManager.notify(0, notify);
I suggest you to use:
Notification not = new Notification(idIcon, text, System.currentTimeMillis());
PendingIntent pInt = PendingIntent.getActivity(ctx, 0, new Intent(ctx, the_class_to_call), 0);
not.setLatestEventInfo(ctx, app_name, text, pInt);
and then not.notify....
use AlertDialog, then launch your desired activity on positive button click

Flagging issues in android

I'm trying to get my Notification to not cancel when the user presses "Clear All" So far I have the intent working properly on everything except this:
Intent intent = new Intent(getBaseContext(), MainActivity.class);
intent.addFlags(Notification.FLAG_ONGOING_EVENT);
intent.addFlags(Notification.FLAG_NO_CLEAR);
PendingIntent contentIntent = PendingIntent.getActivity(
getBaseContext(), 0, intent, 0);
The question I have at this point is: Are my flags correct?
Yes, your flags look pretty much correct, although I don't know if you even need the FLAG_NO_CLEAR. I currently have an app which creates an ongoing (non-cancellable) notification - I only use the FLAG_ONGOING_EVENT and it works fine for me. I pretty much just copied it from a tutorial and then added the ongoing event flag.
Here's some sample code:
String text = "notification";
Notification notification = new Notification(R.drawable.icon, text,
System.currentTimeMillis());
//launch the activity if the user selects this notification
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent().setComponent(ComponentName.unflattenFromString("com.example/com.example.MyActivity")), 0);
// set the label and text...
notification.setLatestEventInfo(this, getText(R.string.notification_label),
text, contentIntent);
notification.flags = Notification.FLAG_ONGOING_EVENT;
// Send the notification.
// We use a string id because it is a unique number. We use it later to cancel.
NotificationManager mNM;
mNM.notify(R.string.notification_label, notification);

Android notification click

I am running a service which is popping notification on getting a new task. If I close my app it's running in the background and pop up a notification. What I would like to do is, when I click on that notification, open the app. Can I do that ? How ?
You can do this by adding an intent to your notification:
Intent notificationIntent = new Intent(context, YourAppActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
notification.setLatestEventInfo(context, "headline", "body msg", contentIntent);
notifcationMgr.notify(id, notification);
Just replace YourAppActivity with the activity you want to launch.

Android Notifications

Im trying to start a new activity once i press a notification...the related code is:
NotificationManager notifManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification note = new Notification(R.drawable.android, "New E-mail", System.currentTimeMillis());
PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(this, DatabaseActivity.class), 0);
note.setLatestEventInfo(this, "New E-mail", "You have one unread message.", intent);
notifManager.notify(NOTIF_ID, note);
But the activity just dsnt begin..the notification pops up..but if i click it nothin happens...plz advice!!!
Pardon the obvious question but is DatabaseActivity referenced in your manifest?
May be you can use getApplicationContext() instead of this in the pendingIntent definition.

Categories

Resources