显示自定义的notification时,报android.app.RemoteServiceException: Bad notification posted from package...
自定义的notification中都是常规控件,imagebutton imageview textview 布局是linearlayout;所以排除
控件导致错误的可能;只是在设定notification的时候不知道还有些什么关键问题要考虑
请大家帮指导一下,不胜感激。。
关键代码如下:
- private void showNotification() {
-
- Intent intent =new Intent(this,MainActivity.class);
- intent.setAction(Intent.ACTION_MAIN);
- intent.addCategory(Intent.CATEGORY_LAUNCHER);
- //设置图标、滚动文本、时间戳、点击跳转
- PendingIntent pIntent = PendingIntent.getActivity(this, 0,
- intent,PendingIntent.FLAG_CANCEL_CURRENT);
- RemoteViews contentView = new RemoteViews(this.getPackageName(),
- R.layout.extension);
-
- Log.v(TAG, "RemoteView is ready");
-
- Notification notification = new Notification.Builder(this)
- .setOngoing(true)
- .setSmallIcon(R.drawable.ic_launcher)
- .setTicker("Enjoy your life!")
- .setContent(contentView)
- .setContentIntent(pIntent)
- .build();
- Log.v(TAG, "notification is ready");
- //显示提示
- mNM.notify(NOTIFICATION,notification);
-
-
- }
复制代码
|