2017-10-13 180 views
0

我們現在遷移我們的應用程序從Android 25Android的奧利奧 - 推送通知崩潰

compileSdkVersion 26 
buildToolsVersion "26.0.0" 

我已經修改了所有的依賴版本,以及。

我們仍在使用GCM.jar在我們的應用程序。

當我們收到推送通知奧利奧設備,應用程序崩潰。

崩潰日誌:

Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x1000010 app is in background uid UidRecord{13c38ce u0a297 RCVR bg:+3m5s626ms idle procs:1 seq(0,0,0)} 
+1

GCM罐子非常陳舊,不推薦使用。你現在應該在firebase中使用FCM。該jar沒有爲android的新背景限制進行必要的更改 – tyczj

+0

@ramya是否解決了這個問題?我面臨同一個 –

+0

@ Passionate.C:你是否解決了這個問題? – Debugger

回答

2

請使用Goolgle-雲的gradle信息的依賴,以及在你的gradle產出。或者最好的解決方案是轉移到Firebase。 Firebase有許多像GCM一樣的工具。

根據official docs:Firebase雲消息傳遞(FCM)是GCM的新版本。它繼承了可靠和可擴展的GCM基礎架構,以及新功能!如果您要將消息集成到新應用程序中,請從FCM開始。強烈建議GCM用戶升級到FCM,以便從現在和未來的新FCM功能中受益。

遷移到火力地堡,請參閱here

0

即使它建議轉移到火力地堡,這裏是爲那些誰不能升級的解決方案。

  1. 設置編譯工具26.0.1+
  2. 確保你沒有更多的程度上清醒廣播而只是正常播出
  3. 創建延伸JobServiceIntent類和計劃任務吧。

隨着工作服務可能在奧利奧的背景下工作。

這裏是JobServiceIntent類的樣品

package com.voxelbusters.nativeplugins.features.notification.core; 

import android.content.Context; 
import android.content.Intent; 
import android.os.Bundle; 
import android.support.v4.app.JobIntentService; 

import com.google.android.gms.gcm.GoogleCloudMessaging; 
import com.voxelbusters.nativeplugins.defines.CommonDefines; 
import com.voxelbusters.nativeplugins.utilities.Debug; 
import com.voxelbusters.nativeplugins.utilities.JSONUtility; 

import org.json.JSONObject; 

/** 
* Created by ayyappa on 09/02/18. 
*/ 

public class NotificationJobService extends JobIntentService 
{ 
    /** 
    * Unique job ID for this service. 
    */ 
    static final int JOB_ID = 1000; 

    /** 
    * Convenience method for enqueuing work in to this service. 
    */ 
    public static void enqueueWork(Context context, Intent work) { 
     enqueueWork(context, NotificationJobService.class, JOB_ID, work); 
    } 

    @Override 
    protected void onHandleWork(Intent intent) 
    { 

     Bundle extras = intent.getExtras(); 
     GoogleCloudMessaging service = GoogleCloudMessaging.getInstance(this); 

     String messageType = service.getMessageType(intent); 

     Debug.log(CommonDefines.NOTIFICATION_TAG, "GCMIntentService received message type : " + messageType); 

     if (!extras.isEmpty()) 
     { 
      if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) 
      { 
       // Post notification of the received message (extras). 

      } 
     } 
    } 

    @Override 
    public void onDestroy() 
    { 
     super.onDestroy(); 
    } 

} 

現在請enqueWork上如下接收廣播。

package com.voxelbusters.nativeplugins.features.notification.serviceprovider.gcm; 

import android.content.BroadcastReceiver; 
import android.content.ComponentName; 
import android.content.Context; 
import android.content.Intent; 

import com.voxelbusters.nativeplugins.features.notification.core.NotificationDefines; 
import com.voxelbusters.nativeplugins.features.notification.core.NotificationJobService; 

public class GCMBroadcastReceiver extends BroadcastReceiver 
{ 
    @Override 
    public void onReceive(Context context, Intent intent) 
    { 
     if (!NotificationDefines.usesExtenralRemoteNotificationService(context)) 
     { 
      // Explicitly specify that GCMIntentService will handle the intent. 
      ComponentName comp = new ComponentName(context.getPackageName(), GCMIntentService.class.getName()); 
      intent.setComponent(comp); 
      NotificationJobService.enqueueWork(context, intent); 
     } 
    } 
} 

希望它有幫助!