启动前台通知方法
Start foreground notification method
我想问是否有人可以给我一个使用 NotificationCompat.Builder
和前台服务的例子。有人可以这样做吗?
public void onStartCommand (Intent intent, int flags, int startId) {
NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder ( this)
.setContentTitle("somthing");
mNotificationManager.notify (mNotificationId,mNotifyBuilder.build());
}
当我在前台使用它时它拒绝,那么我如何将它们一起使用?
引用Android docs:
At a minimum, all notifications consist of a base layout, including:
- The notification's icon. The icon symbolizes the originating app. It may also potentially indicate notification type if the app
generates more than one type.
- A notification title and additional text.
- A timestamp.
在您的代码中,您只设置了标题。在调用 build()
.
之前,您需要使用 NotificationCompat.Builder
实例的 setSmallIcon()
、setLargeIcon()
、setContentText()
和 setWhen()
方法
我想问是否有人可以给我一个使用 NotificationCompat.Builder
和前台服务的例子。有人可以这样做吗?
public void onStartCommand (Intent intent, int flags, int startId) {
NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder ( this)
.setContentTitle("somthing");
mNotificationManager.notify (mNotificationId,mNotifyBuilder.build());
}
当我在前台使用它时它拒绝,那么我如何将它们一起使用?
引用Android docs:
At a minimum, all notifications consist of a base layout, including:
- The notification's icon. The icon symbolizes the originating app. It may also potentially indicate notification type if the app generates more than one type.
- A notification title and additional text.
- A timestamp.
在您的代码中,您只设置了标题。在调用 build()
.
NotificationCompat.Builder
实例的 setSmallIcon()
、setLargeIcon()
、setContentText()
和 setWhen()
方法