2

我正在开发一些需要receive_boot_completed在重启时使用的应用程序来重置一些警报

它在模拟器和三星 tab 2 10.1 上正常工作.. 但它不适用于我的 android 版本 2.2.1 的 Galaxy mini 设备!

这在我的代码中:

清单.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);      

    }

}
4

2 回答 2

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

于 2013-10-06T08:48:15.097 回答
2
<receiver android:name="com.yourpacage.BootReceiver" >
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" >
        </action>
    </intent-filter>
</receiver>

在清单中试试这个

于 2013-10-06T08:28:11.707 回答