首页 > 移动平台 > 详细

android自定义通知栏遇到的问题

时间:2016-04-12 00:24:19      阅读:312      评论:0      收藏:0      [点我收藏+]

自定义通知栏的布局时,为了复制了一个layout.xml文件,引用,但一直报错

android.app.RemoteServiceException: Bad notification posted from
 package com.example.notification: Couldn‘t expand RemoteViews 
for: StatusBarNotification(pkg=com.example.notification id=2 
tag=null score=0 notn=Notification(pri=0 contentView=com.example.notification/0x7f030001 vibrate=null 
sound=null defaults=0x0 flags=0x10 kind=[null]) 
user=UserHandle{0})

 

技术分享

技术分享

         // 获得通知管理器
		NotificationManager nfManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

		Notification myNotification = new Notification();
		// 提醒快讯
		myNotification.tickerText = "android:你好";
		// 设置通知时间
		myNotification.when = System.currentTimeMillis();
		// 设置图标
		myNotification.icon = R.drawable.ic_launcher;
		// 设置通知点击的动作
		Intent intent = new Intent(this, MainActivity.class);
		// 一个未来(预先)的动作,,用于点击或清除通知时的动作,
		PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
				intent, 0);
		myNotification.contentIntent = pendingIntent;
		
		//设置远程视图
		RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_layout);
		
		myNotification.contentView = remoteViews;
		myNotification.flags = Notification.FLAG_AUTO_CANCEL;
		nfManager.notify(2,myNotification);

找了很久发现原因是:设置远程布局时,布局文件里面的按钮设置了静态的点击事件

    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="showNotify"
        android:text="通知"/>

删除这个android:onClick="showNotify" 就可以运行了。

 

android自定义通知栏遇到的问题

原文:http://www.cnblogs.com/zysun/p/5380744.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!