Hello,

Data messages *are succesfully sent* via Advanced REST client, but not 
received anymore when my application is in background (no problem in 
foreground).

But I really don't understand why....

My manifest is: 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android";
    package="com.my.example"
    android:installLocation="auto"
    android:versionCode="52"
    android:versionName="@string/app_version">

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="com.my.MY_SERVICE_PERMISSION" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_CALENDAR" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

    <uses-feature android:name="android.hardware.camera" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:logo="@mipmap/ic_launcher">

        <activity
            android:name=".MainActivity"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:label="@string/app_name">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>

        <service android:name=".MyFcmListenerService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

        <service
            android:name=".MyInstanceIDListenerService">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
            </intent-filter>
        </service>

        <service
            android:name=".RegistrationIntentService"
            android:exported="false" />

    </application>

</manifest>


My gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion '23.0.3'

    defaultConfig {
        applicationId "com.my.example"
        minSdkVersion 19
        targetSdkVersion 23
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 
'proguard-rules.txt'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
}

repositories {
    mavenCentral()
    flatDir {
        dirs 'libs'
    }
    maven { url "https://jitpack.io"; }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:support-v4:24.0.0'
    compile 'com.android.support:support-annotations:24.0.0'
    compile 'org.osmdroid:osmdroid-android:5.2@aar'
    compile 'com.google.code.gson:gson:2.4'
    compile 'com.google.firebase:firebase-messaging:9.2.0'
    compile 'com.google.android.gms:play-services-location:9.2.0'
    compile 'com.google.android.gms:play-services-appindexing:9.2.0'
    compile 'com.android.support:appcompat-v7:24.0.0'
}

apply plugin: 'com.google.gms.google-services'


And My listener:

public class MyFcmListenerService extends FirebaseMessagingService {
    public static final int NOTIFICATION_ID = 1;

    private static final String TAG = "MyFcmListenerService";

    /**
     * Called when message is received.
     *
     * @param fcmMessage FCM message containing message data as key/value pairs.
     *             For Set of keys use data.keySet().
     */
    // [START receive_message]
    @Override
    public void onMessageReceived(RemoteMessage fcmMessage) {

        Map data = fcmMessage.getData();

        Spanned span = null;
        String id;
        String title;
        String message;
        String webSite;
        String image;
        String location;
        String latitude;
        String longitude;
        String startDate;
        String endDate;
        String publishEndDate;
        SharedPreferences sharedPreferences = 
PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        SharedPreferences.Editor editor = sharedPreferences.edit();

        int code = Integer.parseInt((String) data.get("code"));

        Log.i(Constants.APP_TAG, "received FCM message code "  + code);

        switch (code) {
            case 1: // Event
                . . . .
                break;

            default:
                break;
        }
    // [END_EXCLUDE]
    }
    // [END receive_message]


And Strangely, when I receive a message in foreground and generate a custom 
notification with the data, if I swipe the application out of the recent 
app list, the notification is automatically removed from the notification 
center.
It ws not the case when this same application was able to receive data 
message in background.
I guess there is some relationship.

The sent message is:

{
  "to" : "dlThm37OT8w:APA91bFRIcL4o5R2eX1jH0Fd-hAaPu9Wu_. . . 
._MSBzgajJotZ-CR4VTKBRE",
  "data": {
    "id": 19,
    "title": "Title test",
    "msg": "Text of the test",
    "code": 2,
    "infosUrl": "www.myexample.com",
    "eventLocation": "Nowhere",
    "latitude": 44.90022515672,
    "longitude": 5.0196307059377,
    "startDate": "2016/05/14 20:00",
    "endDate": "2016/05/14 22:00",
    "publishEndDate": "",
    "image": ""
  },
  "delay_while_idle" : false,
  "priority" : "high",
  "content_available" : true
}

Do you see anything which could explain my problem?

Regards,

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
To post to this group, send email to android-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/19c5c0d7-4d8c-479a-a8b1-54cdb3d978ba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to