我正在开发一些应用需要在重启时使用receive_boot_completed
来重置某些警报
它在模拟器和三星标签2 10.1上正常工作但是它不适用于我的带有2.2.1版本的Galaxy迷你设备!
这在我的代码中:
的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 :(得分: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
答案 1 :(得分:2)
<receiver android:name="com.yourpacage.BootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" >
</action>
</intent-filter>
</receiver>
在清单
中试试