0

I can receive message google-cloud-messaging data payload when my app is active, but when the app is not active I do not receive messages.

My device is android, when app is alive,send notification or data message. It worked.
but when app is not alive, sent data message, it doesn't work.

Is there any way to use the data payload message to activate the intent and receive the message when my app is not alive?

there is my code, according to the demo:

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);
    }
}

there is my config:

<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> 
Hamad
  • 5,096
  • 13
  • 37
  • 65
rockgu
  • 1
  • 1
  • Please show your code. What have you tried, what worked, and what didn't work? You may find the [how to ask](http://stackoverflow.com/help/how-to-ask) help section helpful for ways to improve your question :) – Niels Abildgaard Jan 19 '16 at 11:14
  • Need more information: is device ios or android? Maybe http://stackoverflow.com/a/34712161/517134 helps you – Yusuf K. Jan 19 '16 at 12:10
  • Possible duplicate of [GCM Notifications not receiving when app is in background mode in iOS](http://stackoverflow.com/questions/34704736/gcm-notifications-not-receiving-when-app-is-in-background-mode-in-ios) – Yusuf K. Jan 19 '16 at 12:11
  • my device is android,when app is not alive,send notification message,it worked,but sent data message,it not worked. – rockgu Jan 20 '16 at 02:14
  • According to documentation "a client app receives data messages in `onMessageReceived()`" and "data payload can be retrieved in the Intent used to launch your activity". With these two said, I think receiving data message can only occur when you launch your app or when it is active. – gerardnimo Jan 20 '16 at 02:51
  • It is not possible, see http://stackoverflow.com/questions/20838415/gcm-push-notification-works-after-app-force-stop ... – Baris Akar Jan 20 '16 at 10:16

0 Answers0