電話の起動後に自動的に開始するサービスを実装するために、インターネットからサンプルを取得しました。しかし、アプリケーションはエラーを示しています。問題を解決するのを手伝ってください
前もって感謝します
xmlファイル
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.newtest"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application>
<receiver android:name="com.example.newtest.BootCompletedIntentReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name="com.example.newtest.BackgroundService"/>
</application>
</manifest>
放送受信機クラス
package com.example.newtest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class BootCompletedIntentReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
Intent pushIntent = new Intent(context, BackgroundService.class);
context.startService(pushIntent);
}
}
}
サービスクラス
package com.example.newtest;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;
public class BackgroundService extends Service {
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
Toast.makeText(this, "OK", Toast.LENGTH_LONG).show();
super.onCreate();
}
}
logcat
02-18 16:32:49.949: E/AndroidRuntime(308): FATAL EXCEPTION: main
02-18 16:32:49.949: E/AndroidRuntime(308): java.lang.RuntimeException: Unable to instantiate receiver com.example.newtest.BootCompletedIntentReceiver: java.lang.ClassNotFoundException: com.example.newtest.BootCompletedIntentReceiver in loader dalvik.system.PathClassLoader[/data/app/com.example.newtest-1.apk]
02-18 16:32:49.949: E/AndroidRuntime(308): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1773)
02-18 16:32:49.949: E/AndroidRuntime(308): at android.app.ActivityThread.access$2400(ActivityThread.java:117)
02-18 16:32:49.949: E/AndroidRuntime(308): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:981)
02-18 16:32:49.949: E/AndroidRuntime(308): at android.os.Handler.dispatchMessage(Handler.java:99)
02-18 16:32:49.949: E/AndroidRuntime(308): at android.os.Looper.loop(Looper.java:123)
02-18 16:32:49.949: E/AndroidRuntime(308): at android.app.ActivityThread.main(ActivityThread.java:3683)
02-18 16:32:49.949: E/AndroidRuntime(308): at java.lang.reflect.Method.invokeNative(Native Method)
02-18 16:32:49.949: E/AndroidRuntime(308): at java.lang.reflect.Method.invoke(Method.java:507)
02-18 16:32:49.949: E/AndroidRuntime(308): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-18 16:32:49.949: E/AndroidRuntime(308): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-18 16:32:49.949: E/AndroidRuntime(308): at dalvik.system.NativeStart.main(Native Method)
02-18 16:32:49.949: E/AndroidRuntime(308): Caused by: java.lang.ClassNotFoundException: com.example.newtest.BootCompletedIntentReceiver in loader dalvik.system.PathClassLoader[/data/app/com.example.newtest-1.apk]
02-18 16:32:49.949: E/AndroidRuntime(308): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
02-18 16:32:49.949: E/AndroidRuntime(308): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
02-18 16:32:49.949: E/AndroidRuntime(308): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
02-18 16:32:49.949: E/AndroidRuntime(308): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1764)
02-18 16:32:49.949: E/AndroidRuntime(308): ... 10 more