定时启动 timer---pendingIntent使用

new Timer().schedule(new TimerTask(){

  @Override

  public void run(){

    //定时发送一个空消息
    handler.sendEmptyMessage(0x123);
  }}, 0, 200};
}

 

//获取系统服务---白拿一个NotificationManager
        NotificationManager notificationManager = (NotificationManager) 
                super.getSystemService(Activity.NOTIFICATION_SERVICE);
        //用图片,文字,时间, 创造一个notification
        @SuppressWarnings("deprecation")
        Notification notification = new Notification(
                R.drawable.ic_launcher,
                "林森通知你",//通知的时候闪一下的几个字
                System.currentTimeMillis()
                );
        
        //第三个参数Intent,是notification点击后要做的intent----PendingIntent的意义就是包装一个Intent
        PendingIntent pendingIntent = PendingIntent.getActivity
                (this, 0, getIntent(), PendingIntent.FLAG_UPDATE_CURRENT);
        
        //拉下来的时候要显示的字,PendingIntent放出notification---设置通知栏的点击事件
        notification.setLatestEventInfo(this, "重要新闻", "四川又地震了", pendingIntent);
        
        notificationManager.notify("tag", R.drawable.ic_launcher, notification);

 

转载于:https://www.cnblogs.com/linxiaojiang/archive/2013/04/23/3038801.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值