简体   繁体   English

Android - 在启动时启动服务

[英]Android - Starting a Service on Boot

I'm trying to start an Android Service on Boot that entails starting advertisements on boot which can be read by a BLE scanner.我正在尝试在启动时启动 Android 服务,这需要在启动时启动广告,BLE 扫描仪可以读取这些广告。 Do you know how to go about doing so?你知道如何去做吗? Currently, I keep getting "Unfortunately, 'myService' has stopped."目前,我不断收到“不幸的是,'myService' 已停止。” Note: I am using Xamarin for Android development.注意:我使用 Xamarin 进行 Android 开发。

In order to do this you need to register a BroadcastReceiver for the system intent "android.intent.action.BOOT_COMPLETED" on your Android manifest.为此,您需要在 Android 清单上为系统意图“android.intent.action.BOOT_COMPLETED”注册一个 BroadcastReceiver。 However, if your application is installed on the external storage use "android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE".但是,如果您的应用程序安装在外部存储上,请使用“android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE”。 From this BroacastReceiver you can then start your Service.从此 BroacastReceiver 中,您可以启动您的服务。

There's a nice tutorial here that should meet your needs.有一个很好的教程在这里应该满足您的需求。 Also check this other SO question which has a detailed explanation on the subject.还要检查this other SO question,其中有关于该主题的详细解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM