2013-10-06 8 views
2

왜 내 장치에서 receive_boot_completed가 작동하지 않습니까? 내가 어떤 응용 프로그램을 개발하고

그것의 에뮬레이터와 삼성 탭 2 10.1에서 제대로 작동 몇 가지 알람을 재설정 재부팅에 receive_boot_completed를 사용해야합니다 ..하지만 안드로이드 버전 2.2 내 은하 미니 기기에서 작동하지 않습니다 .1 !!!

이 내 코드 :

manifest.xml

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

    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="18" /> 

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

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/app_icon" 
     android:label="@string/app_name"   
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.engahmedphp.collector.SplashActivity" 
      android:label="@string/app_name" 
      android:theme="@android:style/Theme.NoTitleBar.Fullscreen" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name=".PagesActivity" 
      android:label="@string/app_name" > 
     </activity> 
     <activity 
      android:name=".FeedsActivity" 
      android:configChanges="orientation|keyboardHidden" 
      android:label="@string/app_name" > 
     </activity> 
     <activity 
      android:name=".PagePrefsActivity" 
      android:label="@string/app_name" > 
     </activity> 
     <activity 
      android:name=".ManagePagesActivity" 
      android:launchMode="singleTask" 
      android:label="@string/app_name" > 
     </activity>   
     <activity 
      android:name=".FeedsDialogActivity" 
      android:configChanges="orientation|keyboardHidden" 
      android:theme="@android:style/Theme.Dialog" 
      > 
     </activity>   
     <receiver android:name=".FeedsReceiver" > 
     </receiver> 
     <receiver android:name=".BootCompletedReceiver" 
        android:enabled="true" 
        android:permission="android.permission.RECEIVE_BOOT_COMPLETED" > 
      <intent-filter> 
       <action android:name="android.intent.action.BOOT_COMPLETED" /> 
       <category android:name="android.intent.category.DEFAULT"/> 
      </intent-filter> 
     </receiver> 

     <service android:name=".GetFeedsService" > 
     </service> 
     <service android:name=".ResetAlarmsService" > 
     </service> 
    </application> 

</manifest> 

BootCompletedReceiver.java

package com.engahmedphp.facebookcollector; 

import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 

import android.util.Log; 
import android.widget.Toast; 

public class BootCompletedReceiver extends BroadcastReceiver { 

    // ============================================================================== 

    @Override 
    public void onReceive(Context context, Intent intent) { 
      Toast.makeText(context, "nice", Toast.LENGTH_LONG).show(); 
      Log.e("boot", "boot"); 
      Intent resetAlarms = new Intent(context, ResetAlarmsService.class); 
      context.startService(resetAlarms);  

    } 

} 
+0

내 장치에서 코드를 테스트했는데 정상적으로 작동합니다. 의도를 받기 전에 신청서를 적어도 한 번 시작 했습니까? – SLee

+0

아니, 나는 그것을 열지 않고 건배를 표시해야하고 작동하지 않습니다 .. 귀하의 장치가 2.2.1에 ?? –

+0

2.2.2에서 테스트를 마쳤습니다. 시스템을 다시 시작하기 전에 적어도 한 번은 응용 프로그램을 시작해야합니다. – SLee

답변

5

이 라인을 수신기의 인 텐트 필터에 넣으십시오.

<action android:name="android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE" /> 

응용 프로그램이 SD 카드에 설치되어있는 경우, 당신은 android.intent.action.BOOT_COMPLETED 이벤트를 얻을이를 등록해야합니다.

업데이트 : 앱이 알람 서비스를 사용하고 있으므로 외부 저장소에 설치해서는 안됩니다. 참조 : http://developer.android.com/guide/topics/data/install-location.html

+0

맞습니다. SD 카드에 설치하면 ..이 수신기를 수신기에 추가해도 여전히 작동하지 않습니다. –

+2

http://developer.android.com /guide/topics/data/install-location.html 그것은 알람 서비스를 사용하는 응용 프로그램은 외부 저장소에 설치해서는 안된다. 내부 저장소에 앱을 설치하면 모든 것이 정상적으로 작동합니다. – SLee

+0

그래, 그게 바로 친구 야 .. 너는 내 영웅이야 .. .. 내가 android : installLocation = "auto"를 android : installLocation = "internalOnly"로 바꿨을 때, 그것은 잘 작동한다. –

2
<receiver android:name="com.yourpacage.BootReceiver" > 
    <intent-filter> 
     <action android:name="android.intent.action.BOOT_COMPLETED" > 
     </action> 
    </intent-filter> 
</receiver> 

매니페스트

이 시도
+0

수신기에 대한 전체 경로를 추가해도 여전히 작동하지 않습니다. –