int icon = R.drawable.icon4;
CharSequence tickerText = "Hello"; // ticker-text
long when = System.currentTimeMillis();
Context context = getApplicationContext();
CharSequence contentTitle = "Hello";
CharSequence contentText = "Hello";
Intent notificationIntent = new Intent(this, Example.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
This won't work for me.
How could I create a notification that is clickable and goes to my app, but does not go away when clicked?
Here is code
Here if you want notifications that don't go away when clicked in Android? so set
If you are using Android 5.0 > it became a lot easier, functionallity changed, but you can use the same code.
Make sure you are in an application context, if not you may need to pass the context and change your sourcecode as follows
You can see the full-source-code at: https://github.com/googlesamples/android-BasicNotifications/blob/master/Application/src/main/java/com/example/android/basicnotifications/MainActivity.java#L73
To work in
android.os.Build.VERSION.SDK_INT<16
keep in mind to do some changesOr you can Download direct tutorial from here : http://www.demoadda.com/demo/android/how-to-create-local-notification-notification-manager-demo-with-example-android-source-code_26
You should read the whole things not just a part, buddy. Please re-read carefully step-by-step.