Android notification example code | Nougat no deprecation

Android notification pendingintent example working in Marshmallow

Android simple notification show in notification icon. Open your application or any activity page which included in your app can be open when notification is clicked by user. Many are facing notification is not working. Here is the most simple working android notification example source code. You can send notification in any choice here in example notification is send when button is clicked. You can set system tray icon as well as notification icon notification title and small message to inform user in which purpose notification is send. Get more latest android code in NextGenEarn Attraction Android.

import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

protectedvoidonCreate(BundlesavedInstanceState) {

Button open = (Button) findViewById(;
Button sendNotif = (Button) findViewById(;
open.setOnClickListener(new View.OnClickListener() {

publicvoidonClick(Viewview) {
Intent intent = newIntent(MainActivity.this,Settings.class);

sendNotif.setOnClickListener(new View.OnClickListener() {
publicvoidonClick(Viewv) {

publicvoidcreateNotification() {

Intent intent = newIntent(this, MainActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);
Notification noti = newNotification.Builder(this)

.setContentTitle("New mail from " + "")
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, noti);

Add a Comment

Your email address will not be published. Required fields are marked *