gpt4 book ai didi

Android BootReceiver 不工作

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:59:59 24 4
gpt4 key购买 nike

我正在尝试监听重启事件。

我创建了以下类:

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!");
}
}

然后在 list 文件中我放入了以下 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>

但是,在我安装此应用并重新启动设备后,没有任何反应。 (我正在使用带有 android 3.2 的 galaxy tab 8.9)。正如您从 list 中看到的那样,我已经在内部存储器上安装了该应用程序(就像在 stackoverflow 上的类似问题上所建议的那样)...我还进行了 Quickboot_poweron 操作(以查看 galaxy 选项卡是否具有与 htc 设备类似的行为) ... 但什么也没有。我希望有人能帮助我!

最佳答案

问题在于,对于 Honeycomb 及更高版本,广播信号不会自动启动尚未以其他方式启动的应用程序。有一个标志可用于更改此设置,但 BOOT_COMPLETED 广播不带有该标志。您需要安装在系统分区上才能克服这种细微差别。

如果您无法安装在系统分区上,您需要找到其他启动方式——说服用户手动启动您,或者让用户安装您提供的小部件等

关于Android BootReceiver 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11098926/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com