可能是由以下原因引起的:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.google.android.finsky.permission.BIND_GET_INSTALL_REFERRER_SERVICE" />
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// 创建通知渠道
NotificationChannel channel = new NotificationChannel("channel_id", "channel_name", NotificationManager.IMPORTANCE_DEFAULT);
channel.setDescription("channel_description");
// 将通知分配给渠道
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
// 创建通知
Notification notification = new NotificationCompat.Builder(this, "channel_id")
.setContentTitle("Notification Title")
.setContentText("Notification Content")
.setSmallIcon(R.drawable.notification_icon)
.build();
// 启动前台服务
startForeground(1, notification);
推荐的腾讯云相关产品:腾讯云移动推送(https://cloud.tencent.com/product/umeng_push)
以上是关于安卓平台前台应用不显示Firebase推送通知的可能原因和解决方法。请根据具体情况逐一排查,并进行相应的调整和配置。
领取专属 10元无门槛券
手把手带您无忧上云