我尝试使用Fragment中的AppCompat创建通知。 我创造什么都看不见。
代码:
private void createNotification()
{
Context context = getActivity().getApplicationContext();
Intent notificationIntent = new Intent(context, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.ymk_ya_logo)
.setAutoCancel(false)
.setContentTitle("notify")
.setContentText("test");
Notification notification = builder.build();
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(777, notification);
}
答案 0 :(得分:0)
请尝试将最后一位更改为:
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, builder.build());