4

I've tried to use FCM with Android Things. I've imported the google json, make the changes in Manifest, subscribe the app to a Topic, but I did not receive a push message. The only thing I get is the Pushtoken from the server.

So does anyone successful create an Android Things FCM project?

Thanks!

Here some code snippets:

Manifest

    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />

<application>
            <uses-library android:name="com.google.android.things" />

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

MainActivity

FirebaseMessaging.getInstance().subscribeToTopic("RaspberryPi3");

Message Receiver

public class cls_firebase_message extends FirebaseMessagingService {
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        glo.frm_main.i_handler.sendEmptyMessage(1);
        Log.d("RP3", "From: " + remoteMessage.getFrom());
    }
}
KENdi
  • 7,576
  • 2
  • 16
  • 31
Phil
  • 61
  • 4
  • did you turn your device on an off to obtain the permissions? – Blundell Nov 10 '17 at 09:19
  • Can you verify your device is connected to the Internet? It may be useful to check the device's date and see if it matches. – Nick Felker Nov 10 '17 at 18:24
  • I'm connected to the internet, beacuase I get a TokenID. I have rebooted the device sereral times, and the Date/time is correct. I get a logcat Message like this: Service connection failed: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null} so i think the google play version is too old, how can i cahnge that? – Phil Nov 10 '17 at 19:30
  • i receive data messages every time the androidthing app is in foreground. If the appis in background, nothing coming, even by data-only messages :( – anatoli Nov 16 '17 at 11:00

2 Answers2

1

I got it: I've tried to send the Push over the Firebase Console, which sends a notification, which is not supported.

I have send it over a PHP script which only sends a message and not a notification and now it works.

Koustuv Ganguly
  • 897
  • 7
  • 21
Phil
  • 61
  • 4
0

It depends on what sort of message you are sending using the FCM console. What you are looking to send is probably a data message but you probably are sending a notification message.

Data messages can be created by expanding a data payload window on message creation in the FCM console and putting in some key/value pairs.

Keith Leow
  • 56
  • 5