AndRoid Notification

本文介绍如何在Android中创建并处理Notification。主要分为两部分:一是通过MainActivity发送通知;二是通过NotificationActivity处理用户点击通知后的响应。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言:

         针对弹出来的Notification 进一步处理


===============

1: 创建一个活动,当用户点击后,启动该活动


public class NotificationActivity  extends Activity {

protected void onCreate(Bundle  instance){

super.onCreate(instance);
setContentView(R.layout.notify_layout);

NotificationManager  manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

manager.cancel(1);

}



}



2:  MainActivity 用来发送该消息


                   NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
  Notification  notify = new Notification(R.drawable.ic_notify, "This is no", System.currentTimeMillis());
  
  Intent intent = new Intent(this,  NotificationActivity.class);
  PendingIntent  pI = PendingIntent.getActivity(this, 0, intent,  PendingIntent.FLAG_CANCEL_CURRENT);
  
  
  notify.setLatestEventInfo(this, "222", "text", pI);
  manager.notify(1, notify);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值