问题描述
我reaaaaally对Java,而是一个经验丰富的C# - codeR
I'm reaaaaally new to Java, but an experienced C#-coder.
我已经创建了我就可以开始/从活动停止服务。我的问题是,我该如何安装这一服务,以便它在我的设备开机启动?
I've created a service which I can start/stop from an activity.My question is, how do I "install" this service so it does start upon boot of my device?
我发现这一点:
Trying在启动时自动在Android
我一直在努力,实现这个是这样的:
I've tried to implemented this like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="james.jamesspackage" android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:icon="@drawable/icon" android:label="@string/app_name"
android:debuggable="true">
<activity android:name=".jamessActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:enabled="true" android:name=".MyService">
<intent-filter>
<action android:name="james.jamesspackage.MyService" />
</intent-filter>
</service>
<receiver android:name="james.jamesspackage.MyBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
</application>
</manifest>
什么是错?我能有一个明显的活动和服务/接收器?
What's wrong? Can I have an activity and a service/receiver in one manifest?
感谢
詹姆斯
推荐答案
看起来像在接收器部分的名称是错误的。这是在AndroidManifest.xml我的应用程序入口是这样的:
Looks like the name in the receiver section is wrong. This is what my application entry in the AndroidManifest.xml looks like:
<application android:icon="@drawable/icon" android:label="@string/app_name">
<receiver android:name=".BootListener"
android:enabled="true"
android:exported="false"
android:label="BootListener">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name=".UpdateService">
</service>
<activity android:name=".Info"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".TravelMapperPreferences"
android:label="Settings">
</activity>
</application>
请注意,该名称是相对于包中的舱单申报。接收机的名字应该是.MyBroadcastReceiver以来,明显的包中包含james.jamesspackage
Note that the names are relative to the package in the manifest declaration. Your receiver name should be ".MyBroadcastReceiver" since the package of the manifest contains james.jamesspackage
这篇关于安卓:开机启动服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!