现在的位置: 首页 > 综合 > 正文

通知栏异常 android.app.RemoteServiceException:Bad notifcation for Foreground :java.lang.ClassCastExceptio

2016年05月06日 ⁄ 综合 ⁄ 共 466字 ⁄ 字号 评论关闭

通知栏异常,但可以正常使用,主要报错的机型是 SAMAUNG Galaxy SII/SIII/ SAMSUNG  GT-i9220  M470BSA。

这个异常属于API异常,意思是你的通知栏需要一个PendingIntent  ,这个PendingIntent 指向一个Intent可以做界面跳转,发送广播,开启Service之类的。

有些情况下我们没有在通知栏做跳转到界面之类的操作,可能只是开启手电筒,开启移动网络,蓝牙等操作,这种情况就不需要给Notification设置PendingIntent  大部分的机型是可以的,只有上述提到的机型会异常,我们只需要给设置一个Intent为空的PendingIntent就可以了。

代码:

PendingIntent mPendingIntent = PendingIntent.getActivity(context, 0,
				new Intent(), PendingIntent.FLAG_CANCEL_CURRENT);
		mBuilder.setContentIntent(mPendingIntent);

异常截图:

抱歉!评论已关闭.