如何让android oreo中的前台服务通知崩溃?

时间:2018-04-04 08:20:33

标签: android android-notifications

我有一个运行前台服务的应用程序并且是持久的。如何让通知崩溃,如下面的屏幕截图所示? (Messenger,Clipper +等)

enter image description here

 @Override
    public int onStartCommand(Intent intent, int flags, int startId) {

        Intent adminScreenIntent = new Intent(this, AdminHomeActivity.class);

        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, adminScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        Bitmap icon = BitmapFactory.decodeResource(getResources(),
                R.drawable.ic_launcher);

        String notificationChannelId = "supercoolstuff-service-notification-id";
        String notificationChannelName = "supercoolstuff channel";

        NotificationManager notificationManager = (NotificationManager)
                getSystemService(NOTIFICATION_SERVICE);

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
            notificationManager.createNotificationChannel(new NotificationChannel(notificationChannelId, notificationChannelName, NotificationManager.IMPORTANCE_LOW));
        }

        Notification notification = new NotificationCompat.Builder(NetCountableService.this, notificationChannelId)
                .setSmallIcon(R.drawable.ic_small_notification)
                .setLargeIcon(icon)
                .setStyle(new NotificationCompat.BigTextStyle()
                        .setBigContentTitle(String.format("%s %s", getString(R.string.app_name), getString(R.string.monitoring)))
                        .setSummaryText(getString(R.string.slogan)))
                .setContentTitle(String.format("%s %s", getString(R.string.app_name), getString(R.string.monitoring)))
                .setContentText(getString(R.string.slogan))
                .setContentIntent(pendingIntent)
                .setVisibility(Notification.VISIBILITY_SECRET)
                .setPriority(NotificationCompat.PRIORITY_LOW)
                .setChannelId(notificationChannelId)
                .setOngoing(true)
                .build();

        startForeground(Constants.FOREGROUND_SERVICE, notification);

0 个答案:

没有答案