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

来源:互联网 发布:js弹窗代码 编辑:程序博客网 时间:2024/05/20 10:52

通知栏异常,但可以正常使用,主要报错的机型是 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);

异常截图:


0 0
原创粉丝点击