public class SendNotification extends Activity {
private NotificationManager nm;
private Button btnSend;
private Button btnCancel;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setupViews();
}
private void setupViews() {
btnSend = (Button) findViewById(R.id.send);
btnCancel = (Button) findViewById(R.id.cancel);
String service = Context.NOTIFICATION_SERVICE;
nm = (NotificationManager) getSystemService(service); // get system service
final Context context = SendNotification.this;
btnSend.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Notification n = new Notification();
n.icon = R.drawable.icon;
n.tickerText = "Notification";
n.when = System.currentTimeMillis();
//n.flags=Notification.FLAG_ONGOING_EVENT;
Intent intent = new Intent(context, SendNotification.class);
PendingIntent pi = PendingIntent.getActivity(context, 0, intent, 0);
n.setLatestEventInfo(context, "title","content", pi);
nm.notify(1, n);
}
});
btnCancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
nm.cancel(1);
}
});
}
}
状态栏发送通知
最新推荐文章于 2021-03-04 13:53:15 发布