我使用此代码在我的应用中显示通知。因为我运行API 16,因为通知颜色很深,似乎通知面板中没有任何显示。我该怎么办?
private void setupNotification(String s) {
Intent notificationIntent_Restore = new Intent(this,Adult1Activity.class);
notificationIntent_Restore.putExtra(EXTRA_NOTE,NOTE_RESTORE);
PendingIntent restoreIntent = PendingIntent.getActivity(this,
0, notificationIntent_Restore, PendingIntent.FLAG_UPDATE_CURRENT);
final Intent notificationIntent_Close = new Intent(this, Adult1Activity.class);
notificationIntent_Close.putExtra(EXTRA_NOTE, NOTE_CLOSE);
PendingIntent closeIntent = PendingIntent.getActivity(this,
1, notificationIntent_Close, PendingIntent.FLAG_UPDATE_CURRENT);
if (Build.VERSION.SDK_INT < 16) {
Notification n = new Notification.Builder(this)
.setContentTitle("Stand Up!")
.setContentText(s)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentIntent(restoreIntent)
.setAutoCancel(true)
.setColor(getResources().getColor(R.color.white_color))
.getNotification();
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, n);
} else {
notification = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Stand Up!")
.setContentText(s)
.setAutoCancel(true)
.setColor(getResources().getColor(R.color.black_color))
.addAction(new NotificationCompat.Action(R.drawable.ic_note_restore, "Restore", restoreIntent))
.addAction(new NotificationCompat.Action(R.drawable.ic_note_close, "Close", closeIntent))
.setContentIntent(restoreIntent)
.build();
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// notificationManager.notify();
}
startForeground(notification_id, notification);
}
这是应用程序日志:
D/dalvikvm: Late-enabling CheckJNI
I/ActivityThread: Pub standup.maxsoft.com.standup.google_measurement_service: com.google.android.gms.measurement.AppMeasurementContentProvider
I/dalvikvm: Could not find method android.app.Notification$Builder.setLocalOnly, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza
01-09 16:42:07.805 9191-9191/standup.maxsoft.com.standup W/dalvikvm: VFY: unable to resolve virtual method 256: Landroid/app/Notification$Builder;.setLocalOnly (Z)Landroid/app/Notification$Builder;
01-09 16:42:07.805 9191-9191/standup.maxsoft.com.standup D/dalvikvm: VFY: replacing opcode 0x6e at 0x00c8
01-09 16:42:07.805 9191-9191/standup.maxsoft.com.standup I/dalvikvm: DexOpt: access denied from Lcom/google/android/gms/common/GooglePlayServicesUtil; to field Landroid/app/Notification;.extras
01-09 16:42:07.805 9191-9191/standup.maxsoft.com.standup W/dalvikvm: VFY: unable to resolve instance field 18
01-09 16:42:07.805 9191-9191/standup.maxsoft.com.standup D/dalvikvm: VFY: replacing opcode 0x54 at 0x00e7
01-09 16:42:07.825 9191-9191/standup.maxsoft.com.standup E/dalvikvm: Could not find class 'android.os.UserManager', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zzap
01-09 16:42:07.825 9191-9191/standup.maxsoft.com.standup W/dalvikvm: VFY: unable to resolve check-cast 287 (Landroid/os/UserManager;) in Lcom/google/android/gms/common/GooglePlayServicesUtil;
01-09 16:42:07.825 9191-9191/standup.maxsoft.com.standup D/dalvikvm: VFY: replacing opcode 0x1f at 0x000c
01-09 16:42:07.825 9191-9191/standup.maxsoft.com.standup E/dalvikvm: Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zzb
01-09 16:42:07.825 9191-9191/standup.maxsoft.com.standup W/dalvikvm: VFY: unable to resolve check-cast 27 (Landroid/app/AppOpsManager;) in Lcom/google/android/gms/common/GooglePlayServicesUtil;
01-09 16:42:07.825 9191-9191/standup.maxsoft.com.standup D/dalvikvm: VFY: replacing opcode 0x1f at 0x000e
01-09 16:42:07.825 9191-9191/standup.maxsoft.com.standup I/dalvikvm: Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zzh
01-09 16:42:07.825 9191-9191/standup.maxsoft.com.standup W/dalvikvm: VFY: unable to resolve virtual method 563: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
01-09 16:42:07.825 9191-9191/standup.maxsoft.com.standup D/dalvikvm: VFY: replacing opcode 0x6e at 0x000b
01-09 16:42:07.865 9191-9194/standup.maxsoft.com.standup D/dalvikvm: GC_CONCURRENT freed 215K, 11% free 7253K/8071K, paused 12ms+2ms, total 31ms
01-09 16:42:07.865 9191-9191/standup.maxsoft.com.standup D/dalvikvm: WAIT_FOR_CONCURRENT_GC blocked 11ms
01-09 16:42:07.880 9191-9225/standup.maxsoft.com.standup I/GMPM: App measurement is starting up
01-09 16:42:07.885 9191-9225/standup.maxsoft.com.standup E/GMPM: getGoogleAppId failed with status: 10
01-09 16:42:07.890 9191-9225/standup.maxsoft.com.standup E/GMPM: Uploading is not possible. App measurement disabled
01-09 16:42:07.895 9191-9191/standup.maxsoft.com.standup I/dalvikvm: Could not find method android.view.Window.setStatusBarColor, referenced from method standup.maxsoft.com.standup.help.HelpActivity.changeStatusBarColor
01-09 16:42:07.895 9191-9191/standup.maxsoft.com.standup W/dalvikvm: VFY: unable to resolve virtual method 19558: Landroid/view/Window;.setStatusBarColor (I)V
01-09 16:42:07.895 9191-9191/standup.maxsoft.com.standup D/dalvikvm: VFY: replacing opcode 0x6e at 0x0010
01-09 16:42:08.210 9191-9191/standup.maxsoft.com.standup W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
01-09 16:42:08.210 9191-9191/standup.maxsoft.com.standup I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
01-09 16:42:08.210 9191-9191/standup.maxsoft.com.standup W/dalvikvm: VFY: unable to resolve interface method 19539: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
01-09 16:42:08.210 9191-9191/standup.maxsoft.com.standup D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
01-09 16:42:08.210 9191-9191/standup.maxsoft.com.standup I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
01-09 16:42:08.210 9191-9191/standup.maxsoft.com.standup W/dalvikvm: VFY: unable to resolve interface method 19543: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
01-09 16:42:08.210 9191-9191/standup.maxsoft.com.standup D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
01-09 16:42:08.235 9191-9194/standup.maxsoft.com.standup D/dalvikvm: GC_CONCURRENT freed 326K, 12% free 7372K/8327K, paused 2ms+2ms, total 30ms
01-09 16:42:08.385 9191-9191/standup.maxsoft.com.standup I/dalvikvm: Could not find method android.view.ViewGroup.onRtlPropertiesChanged, referenced from method android.support.v7.widget.Toolbar.onRtlPropertiesChanged
01-09 16:42:08.385 9191-9191/standup.maxsoft.com.standup W/dalvikvm: VFY: unable to resolve virtual method 19429: Landroid/view/ViewGroup;.onRtlPropertiesChanged (I)V
01-09 16:42:08.385 9191-9191/standup.maxsoft.com.standup D/dalvikvm: VFY: replacing opcode 0x6f at 0x0007
01-09 16:42:08.405 9191-9191/standup.maxsoft.com.standup I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations
01-09 16:42:08.405 9191-9191/standup.maxsoft.com.standup W/dalvikvm: VFY: unable to resolve virtual method 641: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
01-09 16:42:08.405 9191-9191/standup.maxsoft.com.standup D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
01-09 16:42:08.405 9191-9191/standup.maxsoft.com.standup I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
01-09 16:42:08.405 9191-9191/standup.maxsoft.com.standup W/dalvikvm: VFY: unable to resolve virtual method 663: Landroid/content/res/TypedArray;.getType (I)I
01-09 16:42:08.405 9191-9191/standup.maxsoft.com.standup D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
01-09 16:42:08.465 9191-9191/standup.maxsoft.com.standup D/dalvikvm: GC_FOR_ALLOC freed 74K, 11% free 7420K/8327K, paused 40ms, total 40ms
01-09 16:42:08.515 9191-9191/standup.maxsoft.com.standup D/dalvikvm: GC_FOR_ALLOC freed 6K, 12% free 7620K/8583K, paused 28ms, total 28ms
01-09 16:42:08.515 9191-9191/standup.maxsoft.com.standup I/dalvikvm-heap: Grow heap (frag case) to 8.251MB for 232944-byte allocation
01-09 16:42:08.570 9191-9191/standup.maxsoft.com.standup D/dalvikvm: GC_FOR_ALLOC freed <1K, 12% free 7847K/8839K, paused 45ms, total 45ms
01-09 16:42:08.660 9191-9191/standup.maxsoft.com.standup D/libEGL: loaded /system/lib/egl/libEGL_mali.so
01-09 16:42:08.665 9191-9191/standup.maxsoft.com.standup D/libEGL: loaded /system/lib/egl/libGLESv1_CM_mali.so
01-09 16:42:08.670 9191-9191/standup.maxsoft.com.standup D/libEGL: loaded /system/lib/egl/libGLESv2_mali.so
01-09 16:42:08.720 9191-9191/standup.maxsoft.com.standup D/OpenGLRenderer: Enabling debug mode 0
01-09 16:42:08.730 9191-9191/standup.maxsoft.com.standup I/dalvikvm: Could not find method android.support.v7.widget.LinearLayoutCompat.drawableHotspotChanged, referenced from method android.support.design.internal.ForegroundLinearLayout.drawableHotspotChanged
01-09 16:42:08.730 9191-9191/standup.maxsoft.com.standup W/dalvikvm: VFY: unable to resolve virtual method 16196: Landroid/support/v7/widget/LinearLayoutCompat;.drawableHotspotChanged (FF)V
01-09 16:42:08.730 9191-9191/standup.maxsoft.com.standup D/dalvikvm: VFY: replacing opcode 0x6f at 0x0000
01-09 16:42:08.750 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.750 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.750 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.750 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.750 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.750 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.750 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.750 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.760 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.760 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.760 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.760 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.760 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.760 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.760 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.760 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.780 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.780 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.780 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.780 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.780 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.780 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.780 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.780 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.780 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.780 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.785 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.785 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.785 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.785 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.785 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.785 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.800 9191-9194/standup.maxsoft.com.standup D/dalvikvm: GC_CONCURRENT freed 98K, 9% free 8181K/8903K, paused 18ms+14ms, total 65ms
01-09 16:42:08.810 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.810 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.810 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.810 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.810 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.810 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.810 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:08.810 9191-9191/standup.maxsoft.com.standup W/ResourceType: Skipping entry 0x108038e in package table 0 because it is not complex!
01-09 16:42:12.975 9191-9191/standup.maxsoft.com.standup I/dalvikvm: Could not find method android.app.Notification$Builder.setColor, referenced from method standup.maxsoft.com.standup.home.TimerService.setupNotification
01-09 16:42:12.975 9191-9191/standup.maxsoft.com.standup W/dalvikvm: VFY: unable to resolve virtual method 242: Landroid/app/Notification$Builder;.setColor (I)Landroid/app/Notification$Builder;
01-09 16:42:12.975 9191-9191/standup.maxsoft.com.standup D/dalvikvm: VFY: replacing opcode 0x6e at 0x0056
01-09 16:42:13.265 9191-9191/standup.maxsoft.com.standup E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
01-09 16:42:13.265 9191-9191/standup.maxsoft.com.standup E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
01-09 16:42:33.510 9191-9194/standup.maxsoft.com.standup D/dalvikvm: GC_CONCURRENT freed 318K, 11% free 8307K/9287K, paused 23ms+4ms, total 60ms
01-09 16:43:04.520 9191-9194/standup.maxsoft.com.standup D/dalvikvm: GC_CONCURRENT freed 474K, 13% free 8276K/9415K, paused 2ms+3ms, total 30ms
01-09 16:43:31.615 9191-9194/standup.maxsoft.com.standup D/dalvikvm: GC_CONCURRENT freed 384K, 13% free 8277K/9415K, paused 21ms+3ms, total 67ms
01-09 16:43:58.650 9191-9194/standup.maxsoft.com.standup D/dalvikvm: GC_CONCURRENT freed 385K, 13% free 8277K/9415K, paused 8ms+3ms, total 54ms
01-09 16:44:25.655 9191-9194/standup.maxsoft.com.standup D/dalvikvm: GC_CONCURRENT freed 385K, 13% free 8277K/9415K, paused 2ms+2ms, total 22ms
91919191/standup.maxsoft.com.stW/IInputConnectionWrapper: getSelectedText on inactive InputConnection
W/IInputConnectionWrapper: setComposingText on inactive InputConnection
W/IInputConnectionWrapper: getExtractedText on inactive InputConnection
D/dalvikvm: GC_CONCURRENT freed 387K, 13% free 8278K/9415K, paused 37ms+1ms, total 76ms
E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
W/IInputConnectionWrapper: getSelectedText on inactive InputConnection
W/IInputConnectionWrapper: setComposingText on inactive InputConnection
W/IInputConnectionWrapper: getExtractedText on inactive InputConnection
这是通知图片(这是三星-GTN8000与Android版本4.1.2):
而不是:
答案 0 :(得分:0)
我认为最好遵循官方status bar icon guidelines并将图标颜色更改为白色。
答案 1 :(得分:0)
我相信您的问题可以通过设置背景颜色来解决。 所以这可以克服。
希望这个答案有效: Changing Notification RemoteViews Background Color
编辑:
为您提供工作代码,以便在任何版本的Android设备中显示通知文本。
背景背景特定于Kitkat和OS以下的操作系统。尝试使用它并提供反馈。
private void buildNotifications() {
Intent notificationIntent_Restore = new Intent(this,Adult1Activity.class);
notificationIntent_Restore.putExtra(EXTRA_NOTE,NOTE_RESTORE);
PendingIntent restoreIntent = PendingIntent.getActivity(this,
0, notificationIntent_Restore, PendingIntent.FLAG_UPDATE_CURRENT);
android.support.v4.app.NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(R.mipmap.ic_launcher)
.setContentIntent(clickIntent)
.setContentTitle("Stand Up!")
.setContentText(s)
.setWhen(System.currentTimeMillis())
.addAction(R.drawable.ic_skip_previous_white_36dp,
"",
retrievePlaybackAction(PREVIOUS_ACTION))
.addAction(playButtonResId, "",
retrievePlaybackAction(TOGGLEPAUSE_ACTION))
.addAction(R.drawable.ic_skip_next_white_36dp,
"",
retrievePlaybackAction(NEXT_ACTION));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
builder.setShowWhen(false);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder.setVisibility(Notification.VISIBILITY_PUBLIC);
NotificationCompat.MediaStyle style = new NotificationCompat.MediaStyle()
.setShowActionsInCompactView(0, 1, 2, 3);
builder.setStyle(style);
}
builder.setColor(Color.parseColor("#403f4d"));
Notification n = builder.build();
startForeground(notificationId, n);
}