gpt4 book ai didi

android - 自定义通知未在 Android 中显示

转载 作者:行者123 更新时间:2023-11-29 17:49:41 26 4
gpt4 key购买 nike

您好,我在我的 Android 应用程序中显示自定义通知。但问题是自定义通知未显示。我看到了很多主题,但没有找到与我的问题相关的任何答案。

我找不到问题出在哪里。你能看看这个吗?

PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

// display the notification
NotificationManager mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);

RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification);
contentView.setImageViewResource(R.id.notificationIcon, Util.notificationBitmap);
contentView.setTextViewText(R.id.notificationTitle, Util.notificationTitle);
contentView.setTextViewText(R.id.notificationContent, notificationMessage);

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_stat_logo)
.setContentTitle(Util.notificationTitle)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(notificationMessage))
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_SOUND)
.setContentText(notificationMessage);

mBuilder.setContent(contentView);
// build notification
mBuilder.setContentIntent(pendingIntent);
mNotificationManager.notify((int)SystemClock.currentThreadTimeMillis(), mBuilder.build());

自定义通知.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageView
android:id="@+id/notificationIcon"
android:layout_width="wrap_content"
android:layout_height="match_parent"
/>

<TextView
android:id="@+id/notificationTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/notificationIcon"
android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
android:id="@+id/notificationContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/notificationTitle"
android:layout_toRightOf="@id/notificationIcon"
android:textAppearance="?android:attr/textAppearanceSmall" />

</RelativeLayout>

提前致谢。

最佳答案

更改您的布局以使用 LinearLayout。有同样的问题,这是一个很好的解决方法。

关于android - 自定义通知未在 Android 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23847168/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com