android - 通知未显示 android API 29
问题描述
好的,伙计们,我知道为什么,但在使用 API 29 的手机上没有显示通知。例如,在 Api 21 上,一切正常。是的,我尝试阅读 SO 上的其他帖子,发现没有任何用处,也尝试了这些帖子中的所有建议。
最小 sdk 24,最大 sdk - 29 在 gradle
清单中的接收器:
<receiver android:name=".ui.more_content.receivers.RemindersReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<data android:scheme="package"/>
</intent-filter>
</receiver>
接收器类:
class RemindersReceiver: BroadcastReceiver() {
override fun onReceive(p0: Context?, p1: Intent?) {
// Идентификатор уведомления
if(p1?.action.equals("android.intent.action.PACKAGE_ADDED")||p1?.action.equals("android.intent.action.PACKAGE_REMOVED")
||p1?.action.equals("android.intent.action.PACKAGE_UPDATED")) {
showNotificationWith("qwqwdqwqs", p0)
}
}
private fun showNotificationWith(message: String, context: Context?) {
val channelId = "com.example.notif.channelId"
val channelName = "App status"
val contentTitle = "Title"
val notificationManager =
context?.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val activityIntent = Intent()
val contentIntent: PendingIntent = PendingIntent.getActivity(
context,
0, activityIntent, PendingIntent.FLAG_CANCEL_CURRENT
)
val largeIcon: Bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.info)
val notificationBuilder = NotificationCompat.Builder(context, channelId)
.setSmallIcon(R.drawable.info)
.setContentTitle(contentTitle)
.setContentText("asdasdasdasdas")
.setStyle(
NotificationCompat.BigTextStyle()
.bigText(context.getString(R.string.long_dummy_text))
.setBigContentTitle("Big content title")
.setSummaryText("Summary is this Text")
)
.setLargeIcon(largeIcon)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setColor(Color.RED)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
val importance = NotificationManager.IMPORTANCE_HIGH
val notificationChannel = NotificationChannel(channelId, channelName, importance)
notificationBuilder.setChannelId(channelName)
notificationManager.createNotificationChannel(notificationChannel)
notificationManager.notify(
message.hashCode(), notificationBuilder
.setContentIntent(contentIntent).setAutoCancel(true).build()
)
} else {
notificationManager
.notify(
message.hashCode(), notificationBuilder
.setContentIntent(contentIntent).setAutoCancel(true).build()
)
}
}
}
感谢任何帮助,谢谢转发
解决方案
自 Android 8.0 以来,这些广播还没有传送到清单注册的接收器。
推荐阅读
- android - 如何为 MPAndroidChart LineChart 设置值标签和线之间的填充
- python - 等待响应直到超时
- excel - 在excel VBA中使用发送键打开后如何检查文件是否已经打开?
- java - 无法在 netbeans8-2 上运行 javafx 项目
- sybase - 混乱的 Adaptive Server Enterprise 的定义
- c# - 无法在 chrome 中调试或启动我的 MVC 应用程序
- python - 如何在正则表达式中找到模式?
- c# - 从 wwwroot 下载 html 文件一直显示 Not Found 错误
- r - 为非常大的空间数据集拟合 Poisson GLM 模型
- android - Android 中的 dimens.xml 无法正常工作