Android的BootReceiver不起作用 [英] Android BootReceiver does not work

查看:2047
本文介绍了Android的BootReceiver不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想监听重启事件。

我心中已经创建了以下类:

I'v created the following class:

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class OnBootReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i("MYBOOTRECEIVER", "HELLO!");
    }
}

,然后在清单文件,我的推杆下面的XML:

and then in the manifest file I've putted the following xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mypackage"
    android:installLocation="internalOnly"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="3"
        android:targetSdkVersion="8" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <application android:label="@string/app_name" >
        <receiver android:name=".OnBootReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
                <category android:name="android.intent.category.HOME" />
            </intent-filter>
        </receiver>
    </application>
</manifest>

不过,我已经安装了这个程序,并重新启动设备后,没有任何反应。 (我使用的Galaxy Tab 8.9与Android的是3.2)。
你可以从我已经安装在内存中的应用程序(如在这里计算器类似的问题的建议)清单见......我还推一个Quickboot_poweron动作(查看是否Galaxy Tab的有HTC设备的类似行为) ...但没有。我希望有人能帮助我!

However, after I've installed this app and rebooted the device, nothing happens. (I'm using a galaxy tab 8.9 with android 3.2 on it). As you can see from the manifest I've installed the app on internal memory (like suggested on similar questions here on stackoverflow) ... I've also putted a Quickboot_poweron action (to see if galaxy tab have similar behaviour of htc devices) ... but nothing. I hope that someone can help me!

推荐答案

我面临同样的问题在前面后3.0设备。

I faced same problem earlier on post 3.0 device.

原因是

3.1时启动应用程序安装他们是在一个
  停止状态,这样,他们将无法直到用户运行
  明确启动它们。 pressing强制停止将他们回到这
  状态。

Starting with 3.1 when applications are installed they are in a "stopped" state so they will not be able to run until the user explicitly launches them. Pressing Force Stop will return them to this state.

一旦用户运行首次应用程序(而不会强制停止
  它),一切都表现为前 - 重新启动将导致BOOT_COMPLETED
  要被接收的广播等等。然而,如果用户安装
  应用程序,直至及除非他们手工运行的应用程序,没有广播会
  收到。

once the user runs the app for the first time (and does not Force Stop it), everything behaves as before — a reboot will cause BOOT_COMPLETED broadcasts to be received and so on. However, if the user installs the app, until and unless they run the app manually, no broadcasts will be received.

所以你的情况,你必须创建活动启动,并确保您开始发射活动至少一次,那么你将开始收到的引导赛事转播。

So in your case you will have to create launcher activity and make sure you start that launcher activity at least once then you will start receive boot event broadcast.

这篇关于Android的BootReceiver不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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