我的应用程序生成通知,但我为该通知设置的图标未显示。相反,我得到一个白色的广场。
我曾尝试调整图标的png(尺寸为720x720,66x66,44x44,22x22)。奇怪的是,当使用更小的尺寸时,白色方块更小。
我搜索了这个问题,以及生成通知的正确方式,并且从我读过的代码应该是正确的。可悲的是,事情并不像他们应该做的那样。
我的手机是Android 5.1.1的Nexus 5。问题也出现在模拟器上,Android 5.0.1版本的三星Galaxy S4以及Android 5.0.1版本的摩托罗拉Moto G(我都借用过,现在还没有)
通知代码如下,两个截图。如果您需要更多信息,请随时索取。
@SuppressLint("NewApi") private void sendNotification(String msg, String title, String link, Bundle bundle) {
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class);
resultIntent.putExtras(bundle);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
Notification notification;
Uri sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notificationsound);
notification = new Notification.Builder(this)
.setSmallIcon(R.drawable.lg_logo)
.setContentTitle(title)
.setStyle(new Notification.BigTextStyle().bigText(msg))
.setAutoCancel(true)
.setContentText(msg)
.setContentIntent(contentIntent)
.setSound(sound)
.build();
notificationManager.notify(0, notification);
}
发布于 2018-04-20 18:10:17
我真的建议遵循Google的设计指南:
以下是您可以如何实现它的方法:
如果您使用Gradle / Android Studio构建应用程序,请使用build.gradle:
defaultConfig {
targetSdkVersion 20
}
否则(Eclipse等)使用AndroidManifest.xml:
<uses-sdk android:minSdkVersion="..." android:targetSdkVersion="20" />
https://stackoverflow.com/questions/-100003951
复制相似问题