安卓开发:通知栏通知的实现

在目前版本中用于实现通知的一个实例。

IDE版本:Android studio 2.2 beta
安卓版本:
       虚拟机  nexus5 5.1.0
  三星 galaxy  5.1.0


安卓开发:通知栏通知的实现



函数 DisOnNotification
功能 显示一则通知示例到通知栏上
返回值无

void DisOnNotification()
{
//获得通知栏管理器
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
//实例化一个通知,使用app的启动图标作为logo,通知名称为提醒
Notification notification = new Notification(R.mipmap.ic_launcher, "提醒", System.currentTimeMillis());
//这里的FirstpageActivity是我自定的页面名,按照需求修改
// Intent descIntent = new Intent(this, FirstpageActivity.class);

Intent intent = new Intent("com.rj.notitfications.SECACTIVITY");
PendingIntent pendingIntent = PendingIntent.getActivity(FirstpageActivity.this, 1, intent, 0);

//-----配置通知栏界面
Notification.Builder builder = new Notification.Builder(FirstpageActivity.this);
builder.setAutoCancel(false);
builder.setTicker("Text");
builder.setContentTitle(getString(R.string.NotiContentTitle));
builder.setContentText("Set time is 130AM");
builder.setSmallIcon(R.mipmap.ic_launcher);
builder.setContentIntent(pendingIntent);
builder.setOngoing(true);
builder.setSubText("已经坚持了0"); //API level 16
// builder.setNumber(100);
builder.build();

//-----点击通知栏通知后通知自动消失
notification.flags|=Notification.FLAG_AUTO_CANCEL;
//用刚才配置的Builder通知栏通知赋值
notification= builder.getNotification();
manager.notify(11, notification);

// notification.defaults |= Notification.DEFAULT_SOUND;//默认声音提示
//发送通知,
// manager.notify(0, notification);
}




【新版本中似乎没有drawable而改为了mipmap存储图像】
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值