Java 使用PendingEvent.getService的startForeground的错误通知?
我不时会收到一份:Java 使用PendingEvent.getService的startForeground的错误通知?,java,android,android-notifications,Java,Android,Android Notifications,我不时会收到一份: android.app.RemoteServiceException: Bad notification for startForeground: java.lang.NullPointerException 但仅限于安卓4.3。在Android Kitkat或棒棒糖上,它可以按预期工作。仅当我像这样使用PendingEvent.getService时,此问题才会持续: Intent rewindIntent = new Intent(AudioPlayerService.
android.app.RemoteServiceException: Bad notification for startForeground:
java.lang.NullPointerException
但仅限于安卓4.3。在Android Kitkat或棒棒糖上,它可以按预期工作。仅当我像这样使用PendingEvent.getService时,此问题才会持续:
Intent rewindIntent = new Intent(AudioPlayerService.this, AudioPlayerService.class);
PendingIntent rewindPI = PendingIntent.getService(
AudioPlayerService.this, 0, rewindIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.addAction(R.drawable.ic_fast_rewind_grey600_36dp, null, rewindPI);
但是当我用
Intent i = new Intent("pause");
PendingIntent pauseActionPI = PendingIntent.getBroadcast(
getApplicationContext(), 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
builder.addAction(R.drawable.av_pause_dark, "Pause", pauseActionPI);
它适用于所有版本的android。为什么会这样?我做错了什么
您可以查看完整的源代码和以前的工作版本使用构建器设置图标,并再次检查 所需通知内容
A Notification object must contain the following:
- A small icon, set by setSmallIcon()
- A title, set by setContentTitle()
- Detail text, set by setContentText()
使用生成器设置图标,并再次检查图标 所需通知内容
A Notification object must contain the following:
- A small icon, set by setSmallIcon()
- A title, set by setContentTitle()
- Detail text, set by setContentText()
好吧,在看起来像永远之后,我找到了解决办法。问题是,如果你设置一个动作
Notification.Action action = new Notification.Action(R.drawable.av_pause_dark, null, pendingIntent);
它将在Android版本4.3上崩溃,但在其他版本上可以正常工作
关键是,您必须定义显示的文本。如果你不想有文本(像我一样),你必须将其设置为
Notification.Action action = new Notification.Action(R.drawable.av_pause_dark, "", pendingIntent);
所以诀窍是设置
”
而不是null
好吧,看起来像是永远,我找到了解决方案。问题是,如果你设置一个动作
Notification.Action action = new Notification.Action(R.drawable.av_pause_dark, null, pendingIntent);
它将在Android版本4.3上崩溃,但在其他版本上可以正常工作
关键是,您必须定义显示的文本。如果你不想有文本(像我一样),你必须将其设置为
Notification.Action action = new Notification.Action(R.drawable.av_pause_dark, "", pendingIntent);
所以诀窍是设置
”
而不是null
我使用构建器来实现这一点。此外,这种崩溃从未在我自己的设备上发生过,只是对于某些设备(如Galaxy s3),我使用构建器来实现这一点。此外,此崩溃从未在我自己的设备上发生过,只是对于某些设备(如Galaxy s3),请输入文本,如果没有其他内容,请输入文本,如果没有其他内容,请输入可访问性。