0

谁能告诉我为以下代码犯了什么愚蠢的错误并得到错误。

我尝试过类似的 stackoverflow 帖子和示例。

错误:06-24 09:06:36.074:W/ActivityManager(61):无法启动服务 Intent { flg=0x4 cmp=com.example.myapp/.Updater(有附加功能)}:未找到

package com.example.myapp;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;

public class Booter extends BroadcastReceiver {

      public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();

        if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
          Log.e("boot-status","BOOT_COMPLETED==========================");
        //  SharedPreferences prefs = context.getSharedPreferences("$MYPACKAGE_preferences",0);
        //  if (prefs.getBoolean("startatboot",false)) {
        if(true){
        Intent updateIntent = new Intent();
        updateIntent.setClass(context, Updater.class);

        PendingIntent pendingIntent = PendingIntent.getService(context, 0, updateIntent, 0);
        AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
        alarmManager.set(AlarmManager.RTC_WAKEUP, java.lang.System.currentTimeMillis()+60000, pendingIntent);
          }
        }
      }



    }

更新程序类

      package com.example.myapp;

      import android.os.Bundle;
      import android.util.Log;
      import android.util.Log;
      public class Updater {
        public void onCreate() {  

              Log.e("app-status","ping =====================================================================");
        }

      }

清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

    <application

    android:allowBackup="true"
    android:debuggable="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.myapp.MainActivity"
        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="com.example.myapp.SettingsActivity"
        android:label="@string/title_activity_settings" >
    </activity>


    <receiver android:name="Booter" >
        <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <category android:name="android.intent.category.HOME" />
        </intent-filter>
    </receiver>

    </application>

</manifest>
4

1 回答 1

0

两件事情:

  1. 您必须Updater在清单中声明。
  2. Updater服务还是活动?您应该扩展一个超类,它可以是服务或活动。
于 2013-06-24T12:52:05.650 回答