Android Firebase topic messaging not working -


i have app should listen firebase messaging topics , send messages topic.

here code:

public class messagingservice extends firebasemessagingservice {     private static final string tag = "myfmservice";     @override     public void onmessagereceived(remotemessage remotemessage) {         log.d(tag, "from: " + remotemessage.getfrom());         //...     } } public class mainactivity {     @override     protected void oncreate(bundle savedinstancestate) {         //...         firebaseinstanceid.getinstance().gettoken();         firebasemessaging.getinstance().subscribetotopic("test");         //...         messaging mess = new messaging(this.getapplication());         mess.execute("asdf");     } }  public class messaging extends asynctask { application app;  messaging(application app) {     this.app = app; }  @override protected object doinbackground(object[] objects) {     try {         string rawdata = "{\"to\":\"/topics/test\"," +                 "\"data\": {" +                 "\"message\": \"test message\"}}";         string encodeddata = urlencoder.encode(rawdata, "utf-8");          url u = new url("https://fcm.googleapis.com/fcm/send");         httpurlconnection conn = (httpurlconnection) u.openconnection();         conn.setdooutput(true);         conn.setrequestmethod("post");         conn.setrequestproperty("authorization", "key=" + app.getstring(r.string.api_key));         conn.setrequestproperty("content-type", "application/json");         outputstream os = conn.getoutputstream();         os.write(encodeddata.getbytes());     } catch (ioexception e) {         e.printstacktrace();     }     return null; } } 

this in manifest:

<service     android:name=".messagingservice"     android:exported="false">     <intent-filter>         <action android:name="com.google.firebase.messaging_event" />     </intent-filter> </service> <service     android:name=".myfirebaseinstanceidservice"     android:exported="false">     <intent-filter>         <action android:name="com.google.firebase.instance_id_event" />     </intent-filter> </service> 

the sending works without throwing exceptions, don't receive notifications (also not if send message firebase console.)

where have gone wrong? have messed topic subscription or else?

thanks help.

edit:

i have class:

public class myinstanceidlistenerservice extends firebaseinstanceidservice {  private static final string tag = "myfirebaseiidservice"; private static final string topic = "test";  @override public void ontokenrefresh() {     string token = firebaseinstanceid.getinstance().gettoken();     log.d(tag, "fcm token: " + token);      firebasemessaging.getinstance()             .subscribetotopic(topic); } } 


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -