Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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());
    }
}
like image 916
Phil Avatar asked Apr 27 '26 22:04

Phil


1 Answers

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.

like image 145
Phil Avatar answered Apr 29 '26 11:04

Phil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!