関数を使用したいのは次のとおりです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、ユーザーが通知をタップしたときに提供する必要があると思いますか? これは my 内に設定するのが普通Serviceですか? ユーザーをメインに戻すことはできませんActivityか?