我有一个Service我想使用的startForeground()功能:
public void putServiceToForeground() {
if (notif == null) {
notif = new NotificationCompat.Builder(this)
.setContentTitle("Location Updates Service")
.setContentText("Getting Location Updates")
.setSmallIcon(R.drawable.ic_launcher)
.setTicker(getText(R.string.location_service_starting))
.build();
}
startForeground(notificationID, notif);
}
public void removeServiceFromForeground() {
if (notif != null && mNotificationManager != null) {
notif.tickerText = getText(R.string.location_service_stopping);
mNotificationManager.notify(notificationID, notif);
}
stopForeground(true);
}
我在我onConnected()的.onDisconnected()Service
在较新Android的版本中,一切都很好,我没有收到任何错误,但在 2.3.4 中我收到了错误:
FATAL EXCEPTION: main
android.app.RemoteServiceException: Bad notification for startForeground:
java.lang.IllegalArgumentException: contentIntent required: pkg=com.mycomp.app id=678567400
notification=Notification(vibrate=null,sound=null,defaults=0x0,flags=0x40)
在阅读了关于此的 SO 之后,我假设我需要contentIntent在用户点击通知时提供一个 for?这在我的范围内设置是否正常Service?我不能将用户返回到我的 mainActivity吗?