【发布时间】:2020-10-05 04:28:45
【问题描述】:
此代码不会生成推送。
// intent used to click on notification
Intent intent = new Intent(this, AdminMainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
// 自定义通知视图 RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_push); contentView.setImageViewResource(R.id.image, R.mipmap.ic_launcher); contentView.setTextViewText(R.id.title, "mSchooling"); contentView.setTextViewText(R.id.text, message); // 通知代码 最终字符串 CHANNEL_ID = "channel_02"; NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, getString(R.string.app_name), NotificationManager.IMPORTANCE_DEFAULT); mNotificationManager.createNotificationChannel(mChannel); } NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.mipmap.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) .setColor(颜色.RED) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setContentTitle("mSchooling") .setContent(内容视图) .setContentIntent(pendingIntent); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { builder.setChannelId(CHANNEL_ID); // 频道 ID } builder.setAutoCancel(true); mNotificationManager.notify(1, builder.build());
【问题讨论】:
-
你能显示错误日志吗?
-
我没有收到任何错误,代码也在调试,但没有生成推送。
-
您在哪里生成通知?后台服务?接收者?如果您是从后台启动,请尝试检查后台线程是否启动
-
通知来自 FCM,当我调试代码时,逐行运行但推送未到来。
-
我正在检查 android 10
标签: android