为什么 receive_boot_completed 在我的设备上不起作用?

2024-04-23

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

它可以在模拟器和 Samsung tab 2 10.1 上正常工作..但它不能在我的 android 版本 2.2.1 的 Galaxy Mini 设备上工作!

在我的代码中:

清单文件

<?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);      

    }

}

尝试将此行放入接收器的意图过滤器中。

<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 http://developer.android.com/guide/topics/data/install-location.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么 receive_boot_completed 在我的设备上不起作用? 的相关文章

随机推荐