地理围栏通知无法在Android Oreo中使用(意图服务)

时间:2018-09-04 09:01:25

标签: android notifications android-geofence

我正在通过意图使用Geofence触发服务,因此下面的代码适用于oreo以下的版本,但是我遇到的问题是Geofence被完美触发但通知的oreo版本不管用。我还在电话中启用了通知功能,并将优先级设置为“高”。请向我建议解决方案。

这是GeofenceTransitionservice.java

的代码

 private void sendNotification(String msg) {
        // Intent to start the Maps Activity
        Intent notificationIntent = MapsActivity.makeNotificationIntent(getApplicationContext(),
                msg
        );
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        stackBuilder.addParentStack(MapsActivity.class);
        stackBuilder.addNextIntent(notificationIntent);
        PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        // Creating and sending Notification
        NotificationManager notificatioMng =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificatioMng.notify(
                GEOFENCE_NOTIFICATION_ID,
                createNotification(msg, notificationPendingIntent));

    }

    // Create notification
    private Notification createNotification(String msg, PendingIntent notificationPendingIntent) {

        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "my_channel_id_01");
        notificationBuilder
                .setSmallIcon(R.drawable.logo)
                .setContentTitle(msg)
                .setContentText("Notification")
                .setContentIntent(notificationPendingIntent)
                .setPriority(NotificationCompat.PRIORITY_HIGH)
                .setWhen(System.currentTimeMillis())
                .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND)
                .setAutoCancel(true);
        return notificationBuilder.build();
    }

0 个答案:

没有答案