即使它建議轉移到火力地堡,這裏是爲那些誰不能升級的解決方案。
- 設置編譯工具26.0.1+
- 確保你沒有更多的程度上清醒廣播而只是正常播出
- 創建延伸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);
}
}
}
希望它有幫助!
GCM罐子非常陳舊,不推薦使用。你現在應該在firebase中使用FCM。該jar沒有爲android的新背景限制進行必要的更改 – tyczj
@ramya是否解決了這個問題?我面臨同一個 –
@ Passionate.C:你是否解決了這個問題? – Debugger