当我的应用处于活动状态时,我可以收到消息 google-cloud-messaging 数据有效负载,但当应用未激活时,我不会收到消息。
我的设备是android,当应用程序处于活动状态时,发送通知或数据消息。它奏效了。
但当应用程序不活动时,发送数据消息,它不起作用。
有没有办法使用数据有效负载消息激活意图并在我的应用程序不活动时收到消息?
根据演示版有我的代码:
public class AgooGcmListenerService extends GcmListenerService{
public final static String TAG = "AgooGcmListenerService";
private AgooFactory agooFactory;
@Override
public void onMessageSent(String msgId) {
super.onMessageSent(msgId);
}
@Override
public void onSendError(String msgId, String error) {
ALog.e(TAG, "onSendError,msgId=" + msgId + ",error=" + error);
super.onSendError(msgId, error);
}
@Override
public void onDeletedMessages() {
super.onDeletedMessages();
}
@Override
public void onMessageReceived(String from, Bundle data) {
String message = data.getString("message");
ALog.d(TAG, "From: " + from);
ALog.d(TAG, "Message: " + data.toString());
if(TextUtils.isEmpty(message)){
return;
}
byte[] msg = message.getBytes();
Context mContext = getApplicationContext();
agooFactory = new AgooFactory();
agooFactory.init(mContext, null, null);
agooFactory.msgRecevie(msg,
AgooConstants.MESSAGE_SYSTEM_SOURCE_GCM);
Intent intent = new Intent();
intent.setAction("org.agoo.android.intent.action.PING_V4");
intent.setClassName(mContext.getPackageName(),ProxyFactroy.getChannelService(mContext));
intent.putExtra("source", "accs-bundle");
mContext.startService(intent);
}
}
有我的配置:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_ADDED" />
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_CHANGED" />
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_INSTALL" />
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_REPLACED" />
<uses-permission android:name="android.permission.RESTART_PACKAGES" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<service
android:name="org.android.agoo.thirdPush.AgooGcmListenerService"
android:process=":channel"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<!-- [START gcm_receiver] -->
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:process=":channel"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.taobao.taobao" />
</intent-filter>
</receiver>
<service
android:name="org.android.agoo.thirdPush.AgooInstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
</intent-filter>
</service>