Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
360 views
in Technique[技术] by (71.8m points)

android - My BroadcastReceiver is not receiving the BOOT_COMPLETED intent after my N1 boots

I am unable to get my BroadcastReceiver onReceive method called using the BOOT_COMPLETED intent.

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...
       }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

All the applications that receive the BOOT_COMPLETED broadcast must be installed on the internal storage because Android delivers ACTION_BOOT_COMPLETED broadcast before the external storage is mounted to the device.

To ensure that your application will be installed on the internal memory you just need NOT to declare the android:installLocation manifest attribute.

Another option is to set the following in the manifest section: android:installLocation="internalOnly"

You can find more information about it here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...