浏览代码

android: be explicit about starting a foreground service

After calling startService we are supposed to have a bit of time before turning
the service into a foreground service, but certain devices seem to be more
spartan and we've seen the following failure:

Caused by java.lang.IllegalStateException: Not allowed to start service Intent { act=JitsiMeetOngoingConferenceService:START cmp=org.jitsi.meet/.sdk.JitsiMeetOngoingConferenceService }: app is in background uid UidRecord{f6778d5 u0a220 CAC  bg:+1m1s417ms idle change:idle procs:1 proclist:15604, seq(0,0,0)}
       at android.app.ContextImpl.startServiceCommon + 1600(ContextImpl.java:1600)
       at android.app.ContextImpl.startService + 1546(ContextImpl.java:1546)
       at android.content.ContextWrapper.startService + 669(ContextWrapper.java:669)
       at org.jitsi.meet.sdk.JitsiMeetOngoingConferenceService.launch + 50(JitsiMeetOngoingConferenceService.java:50)

Be expliocit and call startForegroundService, on supported platforms.
j8
Saúl Ibarra Corretgé 6 年前
父节点
当前提交
b245945c4a
共有 1 个文件被更改,包括 7 次插入1 次删除
  1. 7
    1
      android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetOngoingConferenceService.java

+ 7
- 1
android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetOngoingConferenceService.java 查看文件

@@ -21,6 +21,7 @@ import android.app.Service;
21 21
 import android.content.ComponentName;
22 22
 import android.content.Context;
23 23
 import android.content.Intent;
24
+import android.os.Build;
24 25
 import android.os.IBinder;
25 26
 import android.util.Log;
26 27
 
@@ -47,7 +48,12 @@ public class JitsiMeetOngoingConferenceService extends Service
47 48
         Intent intent = new Intent(context, JitsiMeetOngoingConferenceService.class);
48 49
         intent.setAction(Actions.START);
49 50
 
50
-        ComponentName componentName = context.startService(intent);
51
+        ComponentName componentName;
52
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
53
+            componentName = context.startForegroundService(intent);
54
+        } else {
55
+            componentName = context.startService(intent);
56
+        }
51 57
         if (componentName == null) {
52 58
             Log.w(TAG, "Ongoing conference service not started");
53 59
         }

正在加载...
取消
保存