空图像显示在我的通知栏中

时间:2017-09-07 13:44:30

标签: android image notifications

我正在使用Android应用通知。我能够完美地获得通知但无法在通知上显示图像。通知如下所示。 enter image description here

这是我的Build.gradle文件

 compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.ex.myfile"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "2.5"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true

我按照下面的尺寸

24×24(mdpi)

36×36(hdpi)

48×48(xhdpi)

72×72(xxhdpi)

96×96(xxxhdpi)

和我的代码是

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder;
        notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.notification_icon)
                .setContentTitle(getString(R.string.app_name))
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);

        if (jsonobj.has("streamURL")) {
            notificationBuilder.setContentText(jsonobj.getString("userName") + " is LiveNow");
        } else if ((jsonobj.has("title") && (jsonobj.has("message")))) {
            notificationBuilder.setContentText(allFilesDataModel.getFileTitle() + " " + allFilesDataModel.getMessage());
        } else {
            notificationBuilder.setContentText("new Video was Uploaded To YouTube");
        }

        // notificationBuilder.setContentText("" + allFilesDataModel.getFileApprovedOrDenied());
        NotificationManager notificationManager = (NotificationManager)
                getSystemService(Context.NOTIFICATION_SERVICE);

        notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
        NOTIFICATION_ID++;
    }

1 个答案:

答案 0 :(得分:0)

请检查this。您需要为API> = 21使用两个不同的图标。

setSmallIcon()中,您需要为API> = 21

传递正确的图标