" Jai Saraswati Maa"
Hi ... Dear All ..Today I am uploading a superb example of Creating Notification with Action and after click it will disappear.
Please check.
I am using Android Studio 1.5.1
Minimun SDK API 19
Target SDK API 23
Please Like us & put your valuable suggestions in comment box.
**** Nothing in layout xml file its blank
A. Output will be like
a.
b.
B. Java Code
Hi ... Dear All ..Today I am uploading a superb example of Creating Notification with Action and after click it will disappear.
Please check.
I am using Android Studio 1.5.1
Minimun SDK API 19
Target SDK API 23
Please Like us & put your valuable suggestions in comment box.
**** Nothing in layout xml file its blank
A. Output will be like
a.
b.
B. Java Code
package com.exam.ravi.notificationex1; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.NotificationCompat; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.View; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);
Intent intent = new Intent(Intent.ACTION_DIAL); PendingIntent pendingIntent = PendingIntent.getActivity(this,1,intent,0); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle("Lunch is ready! "); builder.setContentText("Call Him...It's getting cold..."); builder.setContentIntent(pendingIntent); builder .addAction(android.R.drawable.ic_menu_call, "Call", pendingIntent); builder.setSmallIcon(android.R.drawable.ic_menu_call); builder.setAutoCancel(true); Notification notification = builder.build(); NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(1,notification); } }
No comments:
Post a Comment