简体   繁体   English

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

[英]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. 我无法使用BOOT_COMPLETED intent调用我的BroadcastReceiver onReceive方法。

AndroidManifest.xml 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 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...
       }
}

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. 接收BOOT_COMPLETED广播的所有应用程序必须安装在内部存储上,因为Android在外部存储装入设备之前传送ACTION_BOOT_COMPLETED广播。

To ensure that your application will be installed on the internal memory you just need NOT to declare the android:installLocation manifest attribute. 为了确保您的应用程序将在您只需要申报的内存安装android:installLocation清单属性。

Another option is to set the following in the manifest section: android:installLocation="internalOnly" 另一个选择是在清单部分设置以下内容: android:installLocation="internalOnly"

You can find more information about it here . 您可以在此处找到有关它的更多信息。

EDIT: Forget everything, I've found a better explanation. 编辑:忘了一切,我找到了更好的解释。

You have to define your receiver with exported = true and enabled = true 您必须使用exported = true和enabled = true定义接收器

<receiver android:name="com.jerrellmardis.umbrella.receiver.WeatherStartupReceiver"
  android:enabled="true" 
  android:exported="true" 
>

I think that if you change this line 我想如果你改变这一行

<receiver android:name="com.jerrellmardis.umbrella.receiver.WeatherStartupReceiver">

for this 为了这

<receiver android:name=".WeatherStartupReceiver">

it will fix your problem. 它会解决你的问题。

I tried it on one of my projects and it didn't start. 我在我的一个项目上尝试了它并没有开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM