0

Может кто-нибудь сказать, какую глупую ошибку я делаю для следующего кода и получения ошибки.AlarmManager Невозможно начать службу Intent

Я пробовал аналогичные записи и образцы stackoverflow.

ошибка: 06-24 09: 06: 36,074: W/ActivityManager (61): Не удалось запустить службу Intent {FLG = 0х4 = 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); 
      } 
     } 
     } 



    } 

Updater.class

 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 ====================================================================="); 
     } 

     } 

menifest

<?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> 

ответ

0

Два тонких gs:

  1. Вы должны объявить Updater в своем манифесте.
  2. Действительно ли Updater услуга или деятельность? Вы должны расширить суперкласс, который является либо службой, либо активностью.