我正在更新我的Android应用程序,从7开始使用8.1。它不是大众市场,它是管理设备的主要警告应用,所以它需要继续使用。我的前台服务有一个“持久”通知,但是现在在8+中有一个滑块来静音我的应用程序通知。
我可以看到android系统通知和其他应用程序删除了这个滑块并显示消息:“这个应用程序的通知不能关闭”。如何复制此模式?
我已经阅读了通知、服务和通道文档。我已经使用IMPORTANCE_DEFAULT创建了一个通道,使用setOngoing(true),并使用持久通知在服务上调用startForeground():
下面是和channel create给您的要点:
public s
我现在正在测试Android 11中的foreground service中打开的摄像头,并且我对新的Android 11限制有问题:。
伪码:
//Service1 is started by JobScheduler.
class Service1 extends Service {
...
startForeground(ID_OF_SERVICE1_NOTIFICATION, getService1Notification())
...
//Run another foreground service with open camera
Inten
我正在创建一个应用程序,它可以向用户发送通知,即使应用程序是从进程中或在后台被杀死的。实际上,在带有SDK >= 26的安卓版本中,我使用的是前台服务。为了显示通知,我有一个服务(DatasNotification),它启动一个asyncTask (HttpRequest)来发出http请求,条件末尾的异步任务启动一个显示通知的新服务。当我的应用程序进入后台时,我收到一个系统通知:我的应用程序正在耗尽电池。在我的分析过程中,我理解这个系统通知是由DatasNotification服务生成的。
这是我的DatasNotification代码:
@Override
public void o
完整的错误还包含:
android.app.RemoteServiceException: Bad notification for startForeground:
我读过其他类似的文章,尝试了他们的建议,并阅读了他们的链接,但仍有少数用户报告了这个错误。
概述
活动由外部应用程序启动。此活动启动自定义语音识别服务。It 不使用使用startForeground:
this.startService(intent);
然后,该活动调用finish();
服务启动自定义语音识别类,并在构造函数中将上下文传递给它。在“检测到语音开始”时,我显示以下通知:
String n
我使用的是我在android 8上编写的一个没有问题的应用程序。这个应用程序使用后台服务读取GPS坐标,处理它们并执行一些逻辑操作。我试图将它移到android 10上,并相应地更改了gradle设置,但在调用"startForeground“之后,我就会崩溃(在设备星系startForeground上测试)--这是服务onCreate代码:
public class ScanService extends Service {
@Override
public void onCreate() {
List<UserLocationManager&
我已经启动了一项服务,如下所示:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(intent);
} else {
context.startService(intent);
}
但是当我想要停止这个服务时,我遇到了一个错误,它是:
android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground
android.app.RemoteServiceException: Bad notification for startForeground: java.util.ConcurrentModificationException
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2204)
at android.os.Handler.dispatchMessage(Handler.java:108)
at android.os.Looper.loop(Looper.java:166)
at an
即使我使用这些api的通道,我也有一个前台服务,它似乎无法发送api> 26 (oreo)上正在进行的通知。在下面的api上,通知正确显示。下面是发送通知的代码:
private void notification(String content) {
Random random = new Random();
int id = random.nextInt(1000)+1;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
NotificationChannel chan =
只要我使用Android仿真程序来测试它,我的代码就能正常工作,但是一旦我构建了它并尝试在我的手机上使用它,我就会得到以下错误:
An uncaught Exception occurred on "main" thread.
Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=channel_01 pri=0 contentView=null vibrate=nul
对于2.3.X版本的android设备,我有一个bug报告:
android.app.RemoteServiceException: startForeground: java.lang.IllegalArgumentException的错误通知
我的方法是..。
final static int myID = 6785674;
public void putServiceToForeground() {
if (notif == null) {
NotificationCompat.Builder mBuilder =
new Not
我在android 8,9上遇到了android 8,9的麻烦。在所有android版本上显示通知的最佳方式是什么?
调试日志
android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=null pri=0 contentView=null vibrate=null sound=null tick defaults=0x0 f
我正在构建一个android应用程序,在那里我需要从背景开始一个活动。我正在使用一个扩展服务的ForegroundStarter来完成这个任务。我有一个活动Adscreen.class,我需要从前台服务中运行它。除了Android10之外,活动Adscreen.class在所有安卓版本上都能正常工作(从背景开始)。
ForeGroundStarter.class
public class ForeGroundStarter extends Service {
@Nullable
@Override
public IBinder onBind(Intent intent)
从堆栈溢出和许多博客中可以看出,前台服务在API>25中从来不会在没有通知的情况下运行。但是,我仍然不明白,这是通知义务,而应用程序运行在屏幕上或可见。就像。当用户站在应用程序中时,不需要通知。所以,在应用程序运行时,是否可以删除通知?服务类中的?
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
......
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Notification.B
我正在和服务公司一起开发音乐播放器。С经常关注通知和按钮.
现在我有按钮在通知栏播放,下一个,前一个..。如果媒体在播放,我想显示暂停按钮;如果不播放,则显示按钮.
错误是,当我在通知.addction中添加If条件时,它显示的是红线..
我做了代码它显示错误..。
服务代码是..。
Foreground.java (类名).
public class ForegroundService extends Service {
private static final String LOG_TAG = "ForegroundService";
public
在我的应用程序中,当应用程序在后台运行时,我使用前台服务来显示通知。我以以下方式创建了一个通知通道:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = getString(R.string.app_name);
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel(Transac