简体   繁体   中英

Android Things FCM

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM