Android 16环境开发的一些记录
前台服务新增属性
提示:
AndroidRuntime: java.lang.RuntimeException: Unable to create service .service.testService: android.app.MissingForegroundServiceTypeException: Starting FGS without a type callerApp=ProcessRecord{97b222b
原因:在启动前台服务testService(startForeground())时,未声明服务类型,导致崩溃。
解决方法:
foregroundServiceType的类型和testService的功能相关。
<serviceandroid:name=".UsbService"android:foregroundServiceType="connectedDevice|dataSync" <!-- 与USB功能相关 -->...>
</service>