android中的通知栏

时间:2016-02-13 20:47:26

标签: android

我正在制作一个使用通知的应用程序,但是当通知即将出现时,此消息一直出现,直到我转向AVD“不幸的是,系统UI已停止”

Intent viewIntent = new Intent(getBaseContext(), WorkshopActivity.class);
                PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), 0, viewIntent, PendingIntent.FLAG_UPDATE_CURRENT);
                Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getBaseContext())
                        .setSmallIcon(R.drawable.web)
                        .setContentTitle(getResources().getString(R.string.app_name))
                        .setContentText("Scheduled")
                        .setAutoCancel(true)
                        .setSound(defaultSoundUri)
                        .setContentIntent(pendingIntent).setTicker("Compass");
                NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
                notificationBuilder.setStyle(inboxStyle);
                notificationBuilder.setStyle(inboxStyle);
                NotificationManager notificationManager =
                        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                int NOTIFICATION_ID = 100;
                notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());

1 个答案:

答案 0 :(得分:0)

你可以请用这个'替换getBaseContext()吗?或者至少是getApplicationContext(),因为BaseContent有一个非常罕见的&特定用途。

.setContentIntent(pendingIntent).setTicker("Compass");

之后可以构建notificationBuilder,

.setContentIntent(pendingIntent).setTicker("Compass").build();

也许它需要在添加样式之前构建并将其添加到管理器。

最后,

notificationManager.notify(NOTIFICATION_ID, notificationBuilder);