我有一个业余时间开发的应用程序(here),我尝试尽可能多地处理崩溃(我讨厌看到崩溃报告!)。
最近的一次崩溃似乎很新,是这个:
android.app.RemoteServiceException:
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1768)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loop (Looper.java:164)
at android.app.ActivityThread.main (ActivityThread.java:6494)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:807)
这就是我所看到的......
它似乎只发生在 Android 8.1 上。由于该应用程序必须非常受欢迎,我非常确定它仍然只会出现在 Android 8.1 上。
在网上搜索,我能找到类似的崩溃,但在所有这些崩溃中,他们都有更多的线索。
所以我试着记忆一下我最近做了哪些改变。唯一的变化是将支持库迁移到 Android-X。其余的变化非常小,我不认为它们是造成这种情况的原因。
因为我没有任何进一步的线索,所以我决定报告 Android-X 部分 here (如果需要,那里有更多信息),因为我不认为这是因为我试图解决问题,而且它看起来非常具体。
后来我集成了 Firebase Crashlytics,并在每个这样的日志上方得到了这个微小的额外线索:
Fatal Exception: android.app.RemoteServiceException
Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=channel_id__app_monitor pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x40 color=0x00000000 category=service vis=SECRET)
这很奇怪,因为我确实正确打开了服务,否则它根本无法工作,特别奇怪的是,这只发生在 Android 8.1 上,而不是在具有相同要求的 8.0 上如何启动前台服务。
这个有问题的通知是关于我用来全局监控应用程序相关事件的前台服务(仅来自 Android O,它有 BroadcastReceivers 的限制)。它在 2 个案例上得到更新:
当我对这两个进行测试时,它们在 Android 8.0 和 8.1 上都运行良好。
这是创建/更新通知的代码:
@JvmStatic
fun getUpdatedAppMonitorNotification(context: Context): Notification {
val builder = Builder(context, context.getString(R.string.channel_id__app_monitor)).setSmallIcon(R.drawable.ic_stat_app_icon)//
.setPriority(Notification.PRIORITY_DEFAULT).setCategory(Notification.CATEGORY_SERVICE)
builder.setVisibility(NotificationCompat.VISIBILITY_SECRET)
builder.setShowWhen(false)
if (!PreferenceUtil.getBooleanPref(context, R.string.pref__avoid_showing_app_monitor_notification_dialog, false))
builder.setContentTitle(context.getString(R.string.app_monitor__notification_title))
if (VERSION.SDK_INT < VERSION_CODES.P) {
val mainIntent = Intent(context, MainActivity::class.java)
.putExtra(MainActivity.EXTRA_OPENED_FROM_NOTIFICATION, true)
builder.setContentIntent(PendingIntent.getActivity(context, 0, mainIntent, PendingIntent.FLAG_UPDATE_CURRENT))
} else {
val intent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName)
.putExtra(Settings.EXTRA_CHANNEL_ID, context.getString(R.string.channel_id__app_monitor))
val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
builder.setContentIntent(pendingIntent)
}
return builder.build()
}
以及我在服务中使用的代码:
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
NotificationId.initNotificationsChannels(this)
val notification = getUpdatedAppMonitorNotification(this)
startForeground(NotificationId.APP_MONITOR, notification)
...
return super.onStartCommand(intent, flags, startId)
}
这是我从其他地方调用的代码,用于更新通知:
@JvmStatic
fun updateAppMonitorNotification(context: Context) {
if (VERSION.SDK_INT < VERSION_CODES.O)
return
val notification = AppMonitorService.getUpdatedAppMonitorNotification(context)
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(NotificationId.APP_MONITOR, notification)
}
为什么会发生?是关于 Android X 的吗?还是通知 build 有问题?
为什么它只出现在 Android 8.1 上?
最佳答案
好吧,我仍然不知道为什么会发生这种情况,但我找到了一个解决方法,就是让服务完成其通知的所有更新,只需通过 安全地调用它context.startForegroundService 函数。
到目前为止,通过使用它,我仍然没有看到任何此类崩溃。
关于android - 为什么我在创建/更新通知时会收到 RemoteServiceException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51222082/
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
出于纯粹的兴趣,我很好奇如何按顺序创建PI,而不是在过程结果之后生成数字,而是让数字在过程本身生成时显示。如果是这种情况,那么数字可以自行产生,我可以对以前看到的数字实现垃圾收集,从而创建一个无限系列。结果只是在Pi系列之后每秒生成一个数字。这是我通过互联网筛选的结果:这是流行的计算机友好算法,类机器算法:defarccot(x,unity)xpow=unity/xn=1sign=1sum=0loopdoterm=xpow/nbreakifterm==0sum+=sign*(xpow/n)xpow/=x*xn+=2sign=-signendsumenddefcalc_pi(digits
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru
我有一个模型:classItem项目有一个属性“商店”基于存储的值,我希望Item对象对特定方法具有不同的行为。Rails中是否有针对此的通用设计模式?如果方法中没有大的if-else语句,这是如何干净利落地完成的? 最佳答案 通常通过Single-TableInheritance. 关于ruby-on-rails-Rails-子类化模型的设计模式是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co
我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta
为什么4.1%2返回0.0999999999999996?但是4.2%2==0.2。 最佳答案 参见此处:WhatEveryProgrammerShouldKnowAboutFloating-PointArithmetic实数是无限的。计算机使用的位数有限(今天是32位、64位)。因此计算机进行的浮点运算不能代表所有的实数。0.1是这些数字之一。请注意,这不是与Ruby相关的问题,而是与所有编程语言相关的问题,因为它来自计算机表示实数的方式。 关于ruby-为什么4.1%2使用Ruby返
我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在