1

我使用以下代码在前台启动服务时显示通知。

PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
        new Intent(this, MainActivity.class), 0);

NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
    .setSmallIcon(R.drawable.statusbar_icon)
    .setContentTitle("App is running")
    .setStyle(new NotificationCompat.BigTextStyle())
    .setPriority(Integer.MAX_VALUE)
    .setDefaults(Notification.DEFAULT_ALL);

mBuilder.setContentIntent(contentIntent);

startForeground(R.string.service_running, mBuilder.build());

该通知显示在除 LG-E450 和三星设备之外的所有设备的通知栏中。不仅是这个,我的应用程序的任何通知都没有显示在栏中。

4

2 回答 2

1

The documentation states that detail text is required and can be set via NotificationCompat.Builder#setContentText(CharSequence) (although my GS3 will display a notification without detail text)

于 2014-01-29T18:33:41.220 回答
0

在应用程序设置中“显示通知”已关闭,因此应该打开

于 2015-05-11T05:53:54.977 回答