如何在Android Oreo及更高版本的通知栏中显示带有图片的Android通知?

我想显示这样的通知(在Android 7.0 API24上):

如何在Android Oreo及更高版本的通知栏中显示带有图片的Android通知?

但是我得到的结果只是托盘图标不完整。(Android 8.1.0 API27):

如何在Android Oreo及更高版本的通知栏中显示带有图片的Android通知?

代码:

Uri defaultsoundUri= RingtoneManager.getDefaulturi(RingtoneManager.TYPE_NOTIFICATION);

        String channelID="channelID";
        String channelName = "channelName";

        Notificationmanager notificationmanager = (Notificationmanager) getSystemService(NOTIFICATION_SERVICE);
        NotificationCompat.Builder notificationBuilder;

        Intent notifyIntent = new Intent(this,Mainactivity.class);

        notifyIntent.setflags(Intent.flaG_actIVITY_CLEAR_TOP |
                Intent.flaG_actIVITY_SINGLE_TOP);

        PendingIntent notifyPendingIntent = PendingIntent.getactivity(this,notifyIntent,PendingIntent.flaG_UPDATE_CURRENT);
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
// Android 8.1.0 API27
            NotificationChannel notificationChannel = new NotificationChannel(channelID,channelName,notificationmanager.IMPORTANCE_HIGH);
notificationmanager.createNotificationChannel(notificationChannel);

            notificationBuilder = new NotificationCompat.Builder(getapplicationContext(),channelID);

            notificationBuilder
                    .setSmallIcon(R.drawable.ic_add_post)
                    .setContentTitle("some title")
                    .setContentText("some message")
                    .setautoCancel(true)
                    .setsound(defaultsoundUri)
                    .setVibrate(new long[]{1000,1000})
                    .setLights(Color.BLUE,1,1)
                    .setShowWhen(true)
                    .setContentIntent(notifyPendingIntent);
            notificationmanager.notify("do_not1",0 /* ID of notification */,notificationBuilder.build());
        } else {

            notificationBuilder = new NotificationCompat.Builder(getapplicationContext());

            notificationBuilder
                    .setSmallIcon(R.drawable.ic_add_post)
                    .setContentTitle("some title")
                    .setContentText("some message")
                    .setautoCancel(true)
                    .setsound(defaultsoundUri)
                    .setVibrate(new long[]{1000,1)
                    .setPriority(Notificationmanager.IMPORTANCE_HIGH)
                    .setContentIntent(notifyPendingIntent);
            notificationmanager.notify("do_not1",notificationBuilder.build());
        }

我不知道为什么它在较低的api上不起作用,但是在较高的api上却不起作用!

NotificationChannel似乎有问题,但无法找到原因。

如何通过OREO api显示如上图所示的通知的完整内容?

idarkness 回答:如何在Android Oreo及更高版本的通知栏中显示带有图片的Android通知?

我在您的代码中看不到任何可疑的内容,但是有机会Android删除了此功能(对重要通知进行了先睹为快)-对此一无所知-或定制OEM生产商考虑到此重新设计了UI偷偷偷看

本文链接:https://www.f2er.com/3167930.html

大家都在问