Tag: 通知

通知操作不会触发PendingIntent

我想创建一个显示下载进度的通知(它现在被模拟),并允许用户取消下载。 我使用通知生成器并添加“取消下载”操作。 该操作将显示,但不会单击发送PendingIntent。 我确认PendingIntent正在通过设置contentIntent来工作。 广播接收者能够获得内容点击的消息,但不能点击该动作。 下载服务 val cancelIntent = Intent(applicationContext, NotificationBroadcastReceiver::class.java).apply { action = "xxx.xxx.xxx.CANCEL_DOWNLOAD" putExtra("notification_id", NOT_ID_PROGRESS) } val pendingIntent = PendingIntent.getBroadcast(applicationContext, 1, cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT) pendingIntent.send() val notificationBuilder = NotificationCompat.Builder(applicationContext, "updates").apply { setContentTitle("Title") setContentText("Text") setSmallIcon(R.drawable.ic_logo_full_black) setOnlyAlertOnce(true) setContentIntent(pendingIntent) addAction(NotificationCompat.Action.Builder(R.drawable.ic_delete, "Cancel", pendingIntent).build()) } startForeground(NOT_ID_PROGRESS, notificationBuilder.build()) Thread({ for (i in 0..100) { notificationBuilder.setProgress(100, i, false) notificationManager?.notify(NOT_ID_PROGRESS, notificationBuilder.build()) Thread.sleep(100L) […]

setSmallIcon(图标:图标)和NotificationCompat

目前我有这样的WET代码造成的事实,NotificationCompat不支持setSmallIcon图标,而不是一个资源ID: val notification = if (Build.VERSION.SDK_INT < 23) { NotificationCompat.Builder(this) .setLargeIcon(bitmap) .setSmallIcon(R.drawable.ic_launcher) .setContentText(intentDescriber!!.userFacingIntentDescription) .setContentTitle(label) .setContentIntent(contentIntent) .setAutoCancel(true) .build() } else { Notification.Builder(this) .setSmallIcon(Icon.createWithBitmap(bitmap)) .setLargeIcon(bitmap) .setContentText(intentDescriber!!.userFacingIntentDescription) .setContentTitle(label) .setContentIntent(contentIntent) .setAutoCancel(true) .build() } 有没有办法让这个更好(干?) – 问题是,两个建设者类是不同的..

如何显示通知抽屉àla Snapchat中不存在的应用内通知

所以这个想法是向用户提供某种类型的通知(不一定是标准的Android通知,可以是图书馆或自定义),就像Snapchat一样。 也就是说,它显示在应用程序,然后消失,而不会出现在状态栏或通知抽屉。 是否有任何知道如何通过股票通知或通过图书馆做到这一点? 或者这是我自己必须发展的东西?

Android通知不显示在API 26上

我最近更新了我的应用程序到API 26,通知不再工作,甚至没有改变代码。 val notification = NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_notification) .setContentTitle("Title") .setContentText("Text") .build() (getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).notify(1, notification) 为什么它不工作? 是不是有一些改变,我不知道的API?

奥利奥模拟器上没有显示通知

我一直试图在奥利奥模拟器上显示一个简单的通知。 奇怪的是,我什么都看不到。 让我们消除明显的答案:我试图检查应用程序的通知,我尝试了通知和NotificationCompat路径。 我尝试了有或没有频道,我尝试过或没有团体。 代码是基本的(是的,我使用Kotlin,但很容易理解): class MainActivity : Activity() { var id = 0 override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val button:View = findViewById(R.id.button) button.setOnClickListener(this::onAddNotification) } private fun onAddNotification(v: View) { id++ val builder = Notification.Builder(this).setSmallIcon(R.drawable.ic_notifications_none) .setContentTitle("Content #$id").setContentText("Content text for $id") val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager notificationManager.notify(id, builder.build()) } } 毋庸置疑,它是在奥利奥前完美的代码。 另一方面,Gmail和Google地图会在该模拟器上显示通知。 任何我可能已经忘记了? […]

点击通知动作的触发功能

我正在写一个应用程序在Kotlin应该显示一个通知与一个行动按钮。 我有一堂课。 我们称之为NotificationClass 这个类通过fun createNotification()为我创建通知 这一切工作正常。 但是我想为通知添加一个按钮,点击的时候会触发一个名为notificationActionClicked() NotificationClass函数。 有什么办法可以做到这一点? (通知类不是一个安卓服务,它只是一个实用程序类。)

如何使用Kotlin从Android中的IntentService发送通知

我是新的android开发,我想发送一个通知从IntentService当设备进入任何特定的地理围栏由用户设置。 我写了下面的代码发送通知。 class GeofenceIntentService : IntentService("GeofenceIntentService") { var notId: Int = 15452 override fun onHandleIntent(intent: Intent?) { var geofencingEvent = GeofencingEvent.fromIntent(intent) if(geofencingEvent.hasError()) { Log.e("JK–>>","geofencingError –>> "+geofencingEvent.hasError()) return } var geofenceTransition = geofencingEvent.geofenceTransition if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER) { var pendingIntent = PendingIntent.getService(applicationContext,0,Intent(applicationContext,MainActivity::class.java),PendingIntent.FLAG_UPDATE_CURRENT) var notification = NotificationCompat.Builder(applicationContext).setAutoCancel(true).setContentTitle("Entered In Geofence!").setContentText("Click here for return to app!!").setContentIntent(pendingIntent).build() var notiManager: NotificationManager […]