Firebase 云消息传递没有声音

时间:2020-12-20 11:04:58

标签: android firebase push-notification firebase-cloud-messaging android-notifications

我正在使用 Firebase 云消息传递向我的设备发送通知。

通知已发送,但没有声音或振动。声音已在 Firebase 控制台上启用。

这是我的应用程序 java 文件的代码:

public class App extends Application {
    public static final String CHANNEL_1_ID = "channel1";
    public static final String CHANNEL_2_ID = "channel2";

    public void onCreate() {
        super.onCreate();

        createNotificationChannels();

        int color = getResources().getColor(R.color.notificationLIVE);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setColor(color);
    }

    private void createNotificationChannels() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel channel1 = new NotificationChannel(
                    CHANNEL_1_ID,
                    "test1",
                    NotificationManager.IMPORTANCE_HIGH
            );


            NotificationChannel channel2 = new NotificationChannel(
                    CHANNEL_2_ID,
                    "test2",
                    NotificationManager.IMPORTANCE_HIGH
            );


            NotificationManager manager = getSystemService(NotificationManager.class);
            manager.createNotificationChannel(channel1);
            manager.createNotificationChannel(channel2);
        }
    }
}

我想我需要在我的项目中添加一些代码?我不知道。

0 个答案:

没有答案