2017-07-31 108 views
0

我试图通过FCM传递“徽章”数字。 我知道onMessageReceived()时,只被调用: [有效载荷只包含“数据”,没有消息]Firebase onMessageReceived()未通过pyfcm调用

我使用“com.google.firebase:火力的消息:11.0.2” 和pyfcm在服务器端发送我的通知。

result = push_service.notify_multiple_devices(
    registration_ids=ids, data_message={'badge': '5'} 
) 
>> all success. 

我的服务:

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

我已阅读this,但我不关闭应用程序(只需按HOME) 但:

public class MyFCMService extends FirebaseMessagingService { 
    private static final String TAG = "MyFCMService"; 
    public MyFCMService() { 
    } 

    @Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 
    Log.d(TAG, remoteMessage.getData().toString()); 
    super.onMessageReceived(remoteMessage); 
    } 
} 

我在manifest.xml文件服务仍然,logcat(详细)不显示任何内容。 有什么可能的原因吗?

+0

您应该首先使用FCM控制台确认您的Android代码。如果它工作正常后,你可以检查你的后端。 –

+0

我可以从FCM作曲家那里得到这些消息。 – Wesely

回答

0

我找到了原因而拷贝我的清单文件代码...

应该

<application> 
    ... 
    <service 
     android:name=".libs.fcm.MyFCMService"> 
     <intent-filter> 
      <action android:name="com.google.firebase.MESSAGING_EVENT"/> 
     </intent-filter> 
    </service> 
</application> 

<service 
    android:name=".libs.fcm.MyFCMService"> 
    <intent-filter> 
     <action android:name="com.google.firebase.MESSAGING_EVENT"/> 
    </intent-filter> 
</service> 
<application> 
    ... 
</application> 

结果:

D/MyFCMService: {badge=5} 

和徽章号码可以更新e通过ShortcutBadger通过通知 与datapayload包含徽章。

pyfcm: 
result = push_service.notify_multiple_devices(registration_ids=registration_ids, data_message=data_message, click_action=click_action, message_title=message_title,message_body=message_body, message_icon=message_icon) 


Android Service 
@Override 
public void handleIntent(Intent intent) { 
    if(intent.hasExtra("badge")) 
} 
相关问题