android – 在我的N1启动后,我的BroadcastReceiver没有收到BOOT_COMPLETED意图

前端之家收集整理的这篇文章主要介绍了android – 在我的N1启动后,我的BroadcastReceiver没有收到BOOT_COMPLETED意图前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我无法使用BOOT_COMPLETED intent获取调用的BroadcastReceiver onReceive方法.

AndroidManifest.xml中

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.jerrellmardis.umbrella"
      android:versionCode="4"
      android:versionName="1.0.3">
    <application android:icon="@drawable/icon" android:label="@string/app_name" 
            android:theme="@android:style/Theme.NoTitleBar">
        <activity android:name=".activities.Umbrella" android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".activities.Preferences" android:label="@string/app_name" android:screenOrientation="portrait" />
        <receiver android:name="com.jerrellmardis.umbrella.receiver.WeatherStartupReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
        <service android:name=".service.WeatherUpdateService">
            <intent-filter>
                <action android:name="com.jerrellmardis.umbrella.service.WeatherUpdateService" />
            </intent-filter>
        </service>
    </application>
    <uses-sdk android:minSdkVersion="3" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
</manifest>

WeatherStartupReceiver.java

package com.jerrellmardis.umbrella.receiver;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.provider.Contacts.People;
import android.util.Log;

import com.jerrellmardis.umbrella.R;

public class WeatherStartupReceiver extends BroadcastReceiver {

       private NotificationManager mNotificationManager;
       private int SIMPLE_NOTFICATION_ID;

       @Override
       public void onReceive(Context context,Intent intent) {
                // Do something interesting here...
       }
}

解决方法

接收BOOT_COMPLETED广播的所有应用程序必须安装在内部存储上,因为Android在将外部存储装入设备之前传送ACTION_BOOT_COMPLETED广播.

要确保您的应用程序将安装在内部存储器上,您只需要声明android:installLocation清单属性.

另一个选择是在清单部分设置以下内容:android:installLocation =“internalOnly”

您可以在其中找到有关它的更多信息here.

猜你在找的Android相关文章