通知不会仅显示振动工作

时间:2019-07-23 14:15:10

标签: android kotlin

我在覆盖onCreat之外使通知变得有趣 当我测试该应用程序时,我收到了通知,但没有显示,我的手机只会震动 当我在单个项目中尝试相同的代码只是为了检查通知的乐趣时,它可以正常工作 当我尝试将通知的乐趣转移到onCreat乐趣和相同问题

我尝试将乐趣置于替代乐趣的内部或外部,但无效

   fun notifyMe(){

           notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

           val intent = Intent(this@MapsActivity, LauncherActivity::class.java)
           val pendingIntent = PendingIntent.getActivity(this@MapsActivity,0,intent,PendingIntent.FLAG_UPDATE_CURRENT)



           if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
               notificationChannel = NotificationChannel(channelId,description,NotificationManager.IMPORTANCE_HIGH)
               notificationChannel.enableLights(true)
               notificationChannel.enableVibration(true)
               notificationChannel.lightColor = Color.GREEN
               notificationManager.createNotificationChannel(notificationChannel)

               buildder = Notification.Builder(this@MapsActivity,channelId)
                   .setContentTitle("NEAR")
                   .setContentText("YOU ARE NEAR ")
                   .setSmallIcon(R.drawable.ic_launcher_round)
                   .setLargeIcon(BitmapFactory.decodeResource(this@MapsActivity.resources,R.drawable.ic_launcher))
                   .setContentIntent(pendingIntent)


           }else{
               buildder = Notification.Builder(this@MapsActivity)
                   .setContentTitle("Distinatios")
                   .setContentText("YOU ARE near ")
                   .setSmallIcon(R.drawable.ic_launcher_round)
                   .setLargeIcon(BitmapFactory.decodeResource(this@MapsActivity.resources,R.drawable.ic_launcher))
                   .setContentIntent(pendingIntent)
           }
           notificationManager.notify(1234,buildder.build())
       }

我希望得到简单的通知 现在我只收到通知的震动

1 个答案:

答案 0 :(得分:0)

您可以使用NotificationCompact.Builder来简化此操作,并使其处理以使您的通知与不同的OS版本兼容。在我的应用程序中,我还将setPriority(NotificationCompat.PRIORITY_HIGH)包括在构建器调用中。如果这些方法不起作用,我将尝试注释掉.setLargeIcon(...)只是为了确保解析图像不是问题。

希望有帮助!