我想在 APK
中启动服务。
我尝试使用如下:
<application android:icon="@drawable/icon" android:label="@string/app_name">
<service android:name =".TestServcie">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</service>
</application>
有什么想法吗?
谢谢
最佳答案
你可以编写一个BroadcastReceiver 并在接收到Intent 后运行Service。例如在设备启动或您需要的其他 Intent 之后。
<receiver android:name=".StartupReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<category android:name="android.intent.category.HOME"/>
</intent-filter>
</receiver>
关于android - 我可以在没有 Activity 或接收器的情况下启动服务吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4468006/