您好,我正在我的 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());
custom_notification.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>
提前致谢。