Hello friends
Today i am going to tell"how to show a dialog box in notification bar programmatically".
Let's Start...........
If you don't know how to do that then read this post.
Just drag and drop 2 buttons into virtual mobile and rename buttons as Dialog On and Dialog Off.
static NotificationManager mNotifyManager;
static NotificationCompat.Builder mBuilder;
Button on=(Button) findViewById(R.id.button);
Button off=(Button) findViewById(R.id.button2);
on.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mNotifyManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mBuilder = new NotificationCompat.Builder(MainActivity.this);
mBuilder.setContentTitle("Notification")
.setContentText("Yup it is working")
.setAutoCancel(false).setSmallIcon(R.mipmap.ic_launcher);
mNotifyManager.notify(0, mBuilder.build());
}
});
off.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mNotifyManager.cancel(0);
}
});
Today i am going to tell"how to show a dialog box in notification bar programmatically".
Let's Start...........
Step:1
First you have to open android studio in development mode of app.If you don't know how to do that then read this post.
Step:2
Just drag and drop 2 buttons into virtual mobile and rename buttons as Dialog On and Dialog Off.
Step:3
Just copy and paste following code before OnCreate method....
static NotificationCompat.Builder mBuilder;
Now just copy & paste given code below into OnCreate method....
Button off=(Button) findViewById(R.id.button2);
on.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mNotifyManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mBuilder = new NotificationCompat.Builder(MainActivity.this);
mBuilder.setContentTitle("Notification")
.setContentText("Yup it is working")
.setAutoCancel(false).setSmallIcon(R.mipmap.ic_launcher);
mNotifyManager.notify(0, mBuilder.build());
}
});
off.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mNotifyManager.cancel(0);
}
});
Step:4
Now Just connect your android mobile to pc through USB cable.Now turn on debugging mode in mobile and click on Run button into Android studio.
that's it.
For any query please comment below.
Comments
Post a Comment