如何解决后台uid UidRecord中的不允许启动服务应用程序?

时间:2019-03-02 08:41:44

标签: android push-notification widget floating

我正在测试该应用程序,并测试Firebase通知,该通知过程在Android 6.0版中工作正常,而在8.0中测试该应用程序时,通知过程不起作用。

错误

    2019-03-02 14:01:50.104 25477-25498/com.progressive_solution.parttimeforce E/AndroidRuntime: FATAL EXCEPTION: pool-2-thread-1
    Process: com.progressive_solution.parttimeforce, PID: 25477
    java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.progressive_solution.parttimeforce/.FloatingWidgetService }: app is in background uid UidRecord{4f2dfcf u0a241 RCVR idle change:idle|uncached procs:1 proclist:25477, seq(0,0,0)}
        at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1600)
        at android.app.ContextImpl.startService(ContextImpl.java:1546)
        at android.content.ContextWrapper.startService(ContextWrapper.java:669)
        at com.progressive_solution.parttimeforce.FirebaseMessagingService.startFloatingWidgetService(FirebaseMessagingService.java:31)
        at com.progressive_solution.parttimeforce.FirebaseMessagingService.onMessageReceived(FirebaseMessagingService.java:26)
        at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(Unknown Source:373)
        at com.google.firebase.iid.zzg.run(Unknown Source:26)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at java.lang.Thread.run(Thread.java:764)
2019-03-02 14:01:50.111 25477-25494/? V/FA: Connecting to remote service

Firebase页面

    package com.progressive_solution.parttimeforce;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import com.google.firebase.messaging.RemoteMessage;

public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService
{
    Context context;
    /*  Permission request code to draw over other apps  */
    private static final int DRAW_OVER_OTHER_APP_PERMISSION_REQUEST_CODE = 1222;

    //THIS METHOD IS CALLED WHEN THE MESSAGE IS RECEIVED FROM THE FCM
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage)
    {
//SEND THE RECEIVED MESSAGE AS THE NOTIFICATION TO THE USERS
        int count = 1;
        context = getApplicationContext();
        SharedPreferences sp = getSharedPreferences("your_prefs",  context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putInt("your_int_key", count);
        editor.commit();

        startFloatingWidgetService();
    }

    private void startFloatingWidgetService()
    {
        startService(new Intent(FirebaseMessagingService.this, FloatingWidgetService.class));

    }
}

在此页面中出错。

我尝试使用startForeground,但显示无效的频道错误。

0 个答案:

没有答案