2013-10-06 147 views
2

我正在開發一些應用程序需要在重啓重新設定報警爲什麼receive_boot_completed在我的設備上不起作用?

這是正確的仿真器和三星標籤2 10.1工作使用receive_boot_completed ..但它不工作我的星系微型設備上使用Android 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

我添加完整路徑接收器,它仍然無法正常工作 –

相關問題