我正在開發一些應用程序需要在重啓重新設定報警爲什麼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);
}
}
我測試你的代碼在我的設備上,它工作正常。在收到意圖之前,您是否至少啓動了一次該應用程序? – SLee
不,我不打開它,它應該顯示烤麪包,它不工作..你的設備是在2.2.1? –
我在2.2.2上測試過。我的意思是啓動應用程序至少一次,然後重新啓動系統。 – SLee