Android 8.1 पर अपडेट के बाद startForeground त्रुटि: कैसे ठीक करें?
सभी को नमस्ते! मैं Kotlin में एक ऐप विकसित कर रहा हूँ जो स्थान ट्रैकिंग के लिए एक background service का उपयोग करता है। डिवाइस को Android 8.1 (Oreo) में अपडेट करने के बाद, मेरी service काम करना बंद कर दी और `Context.startForegroundService() did not then call Service.startForeground()` त्रुटि के साथ क्रैश हो गई। यहाँ मेरी service का कोड है:
```kotlin
class LocationService : Service() {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
val notification = NotificationCompat.Builder(this, "channel_id")
.setContentTitle("सर्विस सक्रिय")
.setContentText("स्थान ट्रैकिंग")
.setSmallIcon(R.drawable.ic_location)
.build()
startForeground(1, notification)
return START_STICKY
}
override fun onBind(intent: Intent?): IBinder? = null
}
```
और मैं इसे इस प्रकार शुरू करता हूँ:
```kotlin
val intent = Intent(this, LocationService::class.java)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundServi