【发布时间】:2016-05-13 09:37:22
【问题描述】:
我有一个广播接收器,它在应用程序打开并在后台检测到即将到来的通知,但是当最近的应用程序被清除时,接收器不工作,请给我建议。
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Explicitly specify that GcmIntentService will handle the intent.
ComponentName comp = new ComponentName(context.getPackageName(),
GcmIntentService.class.getName());
JSONObject json = new JSONObject();
try {
json.putOpt("userid", StorePreference.GetSharedPreferenceDetails(context, "memberid"));
json.putOpt("rid",StorePreference.GetSharedPreferenceDetails(context, "partnerid"));
json.putOpt("message", "Received");
BoundService.getInstance().onlinestatus(json);
} catch (Exception e) {
e.printStackTrace();
}
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}
清单声明:
<receiver
android:name="com.twogether.receivers.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name = "com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.google.android.gcm.demo.app" />
</intent-filter>
</receiver>
【问题讨论】:
-
发布您的清单。只想检查你如何定义接收者
-
这是什么版本的 GCM?您应该使用 GcmListenerService 而不是 BroadcastReceiver
-
@krishna 我已经添加了清单
-
@TimCastelijns 我需要在后台检测 gcm 通知...
标签: java android google-cloud-messaging broadcastreceiver