96SEO 2026-02-19 19:58 15
物联网环境为了解决不同厂商、不同设备、不同网络情况下使用顺畅同时也考虑到节约成本缩小应用体积的好处我们需要一个服务应用一直存在系统中保活它以提供服务给其他客户端调用。

!--允许查看所有未启动的应用--uses-permission
android:nameandroid.permission.QUERY_ALL_PACKAGEStools:ignoreQueryAllPackagesPermission
android:nameandroid.permission.RECEIVE_BOOT_COMPLETED
android:nameandroid.permission.FOREGROUND_SERVICE/开机自启动Service相关代码
android.content.BroadcastReceiver
android.intent.action.BOOT_COMPLETEDoverride
{GlobalScope.launch(Dispatchers.Main)
com.xxx.xxx.end.DeviceService)if
{context?.startForegroundService(intent)}
{context?.startService(intent)}}}}}import
androidx.core.app.NotificationCompat
com.krd.ricemachine.uits.ShareUtil
kotlinx.coroutines.CoroutineScope
createForegroundNotification()//将服务置于启动状态
,NOTIFICATION_ID指的是创建的通知的IDstartForeground(NOTIFICATION_ID,
{CoroutineScope(Dispatchers.Main).launch
{//delay(1000L)//阻塞时间//receiverRegist()RfidUHF.initUHF()ShareUtil.putString(AES_key,
intent?.getStringExtra(key))}//
IntentFilter()filter.addAction(deviceCall)registerReceiver(deviceBroadcastReceiver,
createForegroundNotification():
getSystemService(NOTIFICATION_SERVICE)
NotificationManager.IMPORTANCE_HIGHval
NotificationChannel(notificationChannelId,
importance)notificationChannel.description
description//LED灯notificationChannel.enableLights(true)notificationChannel.lightColor
Color.RED//震动notificationChannel.vibrationPattern
1000)notificationChannel.enableVibration(true)notificationManager?.createNotificationChannel(notificationChannel)}val
NotificationCompat.Builder(this,
notificationChannelId)//通知小图标builder.setSmallIcon(R.mipmap.ic_launcher)//通知标题builder.setContentTitle(AndroidServer)//通知内容builder.setContentText(AndroidServer服务正在运行中)//设定通知显示的时间builder.setWhen(System.currentTimeMillis())//设定启动的内容val
PendingIntent.getActivity(this,1,activityIntent,PendingIntent.FLAG_IMMUTABLE)
/*FLAG_UPDATE_CURRENT*/builder.setContentIntent(pendingIntent)//创建通知并返回return
{//unregisterReceiver(deviceBroadcastReceiver)super.onDestroy()//
不再允许后台进程直接通过startService方式去启动服务改为startForegroundService方式启动。
Context.startForegroundService()
com.xxx.xxx.end/.DeviceService}3、Android
后台应用想启动服务调用调用startForegroundService()后
切记调用startForeground()这个时候会有一个Notification常驻也就是上面说的1。
android.permission.FOREGROUND_SERVICE4、Android
11以上启动服务不能只是这样简单的调用//context?.startService(Intent(context,
java.lang.IllegalStateException:
cmpcom.xxx.xxx/.service.WebService
android.app.ContextImpl.startServiceCommon(ContextImpl.java:1715)at
android.app.ContextImpl.startService(ContextImpl.java:1670)at
android.content.ContextWrapper.startService(ContextWrapper.java:720)at
android.content.ContextWrapper.startService(ContextWrapper.java:720)at
com.xxx.xxx.receiver.BootBroadcastReceiver$onReceive$1.invokeSuspend(BootBroadcastReceiver.kt:26)at
kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)at
kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)at
kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)at
kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749)at
kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)at
kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)Suppressed:
kotlinx.coroutines.DiagnosticCoroutineContextException:
[StandaloneCoroutine{Cancelling}e0016fc,
的需要添加android:exported“true”更多情况情况着这篇文章
queries//你要交互的service的包名package
广播通信的前提1.应用APP要启动过一次2、要有至少有一个activity
这就是为什么我们需要服务的意思首先需要开机自启动服务这会我们可以在启动的服务中动态注册广播测试静态注册也可以。
对了广播的静态注册效果随着版本的升高效果大打折扣为了防止小人作弊系统把君子和小人都设防了。
若是用户手动从后台杀掉应用程序那么广播无法再次启动服务哈哈哈哈哈哈那就想办法让用户无法删除服务吧
作为专业的SEO优化服务提供商,我们致力于通过科学、系统的搜索引擎优化策略,帮助企业在百度、Google等搜索引擎中获得更高的排名和流量。我们的服务涵盖网站结构优化、内容优化、技术SEO和链接建设等多个维度。
| 服务项目 | 基础套餐 | 标准套餐 | 高级定制 |
|---|---|---|---|
| 关键词优化数量 | 10-20个核心词 | 30-50个核心词+长尾词 | 80-150个全方位覆盖 |
| 内容优化 | 基础页面优化 | 全站内容优化+每月5篇原创 | 个性化内容策略+每月15篇原创 |
| 技术SEO | 基本技术检查 | 全面技术优化+移动适配 | 深度技术重构+性能优化 |
| 外链建设 | 每月5-10条 | 每月20-30条高质量外链 | 每月50+条多渠道外链 |
| 数据报告 | 月度基础报告 | 双周详细报告+分析 | 每周深度报告+策略调整 |
| 效果保障 | 3-6个月见效 | 2-4个月见效 | 1-3个月快速见效 |
我们的SEO优化服务遵循科学严谨的流程,确保每一步都基于数据分析和行业最佳实践:
全面检测网站技术问题、内容质量、竞争对手情况,制定个性化优化方案。
基于用户搜索意图和商业目标,制定全面的关键词矩阵和布局策略。
解决网站技术问题,优化网站结构,提升页面速度和移动端体验。
创作高质量原创内容,优化现有页面,建立内容更新机制。
获取高质量外部链接,建立品牌在线影响力,提升网站权威度。
持续监控排名、流量和转化数据,根据效果调整优化策略。
基于我们服务的客户数据统计,平均优化效果如下:
我们坚信,真正的SEO优化不仅仅是追求排名,而是通过提供优质内容、优化用户体验、建立网站权威,最终实现可持续的业务增长。我们的目标是与客户建立长期合作关系,共同成长。
Demand feedback