jir*_*a85 4 android broadcastreceiver
我正在尝试重启事件.
我创建了以下类:
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!");
}
}
Run Code Online (Sandbox Code Playgroud)
然后在清单文件中我推出了以下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>
Run Code Online (Sandbox Code Playgroud)
但是,在我安装此应用程序并重新启动设备后,没有任何反应.(我正在使用带有android 3.2的Galaxy tab 8.9).正如您从清单中看到的那样,我已经在内部存储器上安装了应用程序(就像在stackoverflow上的类似问题上提到的那样)......我还推出了一个Quickboot_poweron动作(看看galaxy tab是否有与htc设备相似的行为) ......但没什么.我希望有人可以帮助我!
我在3.0版设备上遇到了同样的问题.
原因是
从3.1开始安装应用程序时,它们处于"停止"状态,因此在用户显式启动它们之前它们将无法运行.按下强制停止将使它们返回此状态.
一旦用户第一次运行应用程序(并且没有强制停止它),一切都像以前一样 - 重新启动将导致接收BOOT_COMPLETED广播等等.但是,如果用户安装了应用程序,除非他们手动运行应用程序,否则不会收到任何广播.
因此,在您的情况下,您将必须创建启动器活动,并确保至少启动一次启动器活动,然后您将开始接收启动事件广播.
| 归档时间: |
|
| 查看次数: |
5391 次 |
| 最近记录: |