广播接收器不包安装完成后立即工作 [英] Broadcast Receiver not working immediately after package installation

查看:145
本文介绍了广播接收器不包安装完成后立即工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在接收利用广播接收机的BOOT_COMPLETED操作的应用程序。接收器是静态注册在AndroidManifest.xml。

它的工作原理在下次启动安装为Android 2.2而不是3.1了。 3.1我有一次启动应用程序启动时,广播接收机得到BOOT_COMPLETED行动之前。

我怀疑,直到应用程序被启动一次东西在改变3.1,是造成我的接收器处于非活动状态。

有没有人见过这个或不知道如何制止这种行为?任何帮助将大大AP preciated。谢谢你,汤姆。

AndroidManifest.xml中:

 <?XML版本=1.0编码=UTF-8&GT?;
  <清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=com.test.receiver
    安卓版code =1
    机器人:=的versionName1.0>
  <采用-SDK安卓的minSdkVersion =8/>
  <使用许可权的android:NAME =android.permission.RECEIVE_BOOT_COMPLETED/>
  <应用
    机器人:图标=@绘制/图标
    机器人:标签=@字符串/ APP_NAME>
    <活动机器人:名字=。MainActivity
              机器人:标签=@字符串/ APP_NAME>
        &所述;意图滤光器>
            <作用机器人:名字=android.intent.action.MAIN/>
            <类机器人:名字=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
    < /活性GT;
    <接收机器人:名字=TestReceiver机器人:启用=真正的>
        &所述;意图滤光器>
            <作用机器人:名字=android.intent.action.BOOT_COMPLETED/>
        &所述; /意图滤光器>
    < /接收器>
  < /用途>
< /清单>

TestReceiver.java:

 包com.test.receiver;
进口android.content.BroadcastReceiver;
进口android.content.Context;
进口android.content.Intent;
进口android.util.Log;公共类TestReceiver扩展广播接收器{
  @覆盖
  公共无效的onReceive(上下文的背景下,意图意图){
    Log.i(TestReceiver,的onReceive()被称为);
  }
}

MainActivity.java:

 包com.test.receiver;
进口android.app.Activity;
进口android.os.Bundle;公共类MainActivity延伸活动{
  / **当第一次创建活动调用。 * /
  @覆盖
  公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);
  }
}


解决方案

我发现这是一个3.1政策变化。直到用户启动它的第一次一个应用程序保持安装后无效。

I am currently working on an app that receives the BOOT_COMPLETED action using a Broadcast Receiver. The receiver is statically registered in the AndroidManifest.xml.

It works on the next boot after installation for android 2.2 but not 3.1. With 3.1 I have to start the app once before the broadcast receiver gets the BOOT_COMPLETED action when booting.

I suspect that something changed in 3.1 that is causing my receiver to be inactive until the app is started once.

Has anyone ever seen this before or know how to stop this behavior? Any Help would be greatly appreciated. Thanks, Tom.

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?> 
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.test.receiver"
    android:versionCode="1"
    android:versionName="1.0">
  <uses-sdk android:minSdkVersion="8" />
  <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
  <application 
    android:icon="@drawable/icon" 
    android:label="@string/app_name">
    <activity android:name=".MainActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <receiver android:name="TestReceiver" android:enabled="true">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>
  </application>
</manifest>

TestReceiver.java:

package com.test.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class TestReceiver extends BroadcastReceiver {
  @Override
  public void onReceive(Context context, Intent intent) {
    Log.i("TestReceiver", "onReceive() was called");    
  }
}

MainActivity.java:

package com.test.receiver;
import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
  }
}

解决方案

I found out this is a policy change in 3.1. An app remains inactive after installation until the user launches it for the first time.

这篇关于广播接收器不包安装完成后立即工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆