小编New*_*per的帖子

Android:Firebase 云消息传递不发送通知以构建 .apk

当我通过 USB 电缆将手机连接到 Android Studio 时,推送通知正在工作,但是当我生成构建.apk并将其安装在手机上时,应用程序没有收到任何推送通知。

我是 android 新手,第一次尝试推送通知。

输入代码 Manifest.xml

<service
            android:name=".MyFirebaseInstanceIDService">
            android:stopWithTask="false">
            <intent-filter>

                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
Run Code Online (Sandbox Code Playgroud)

类扩展代码FirebaseMessagingService

public class MyFirebaseInstanceIDService extends FirebaseMessagingService {
    @Override
    public void onNewToken(String s) {
        Log.e("NEW_TOKEN", s);
    }

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {

        Map<String, String> params = remoteMessage.getData();
        JSONObject object = new JSONObject(params);
        Log.e("JSON_OBJECT", object.toString());

        String NOTIFICATION_CHANNEL_ID = "Nilesh_channel";

        long pattern[] = {0, 1000, 500, 1000};

        NotificationManager mNotificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel …
Run Code Online (Sandbox Code Playgroud)

java android firebase firebase-cloud-messaging

5
推荐指数
1
解决办法
3316
查看次数