android.permission.RECEIVE_BOOT_COMPLETED不会在开机启动活动 [英] android.permission.RECEIVE_BOOT_COMPLETED does not launch activity at boot
问题描述
我有我试图用项值
使用 BootU preceiver
类发动活动当设备启动。问题是 - 它似乎并没有这样做,当我启动应用程序,然后重新启动设备。
I have a BootUpReceiver
class which I'm attempting to use with RECEIVE_BOOT_COMPLETED
to launch an Activity when the device boots. The problem is - it does not seem to do so when I launch the app then restart the device.
我已经验证没有运行Activity1.java没有问题 - 这个问题在清单或 BootU preceiver
类要么谎言,但我不知道到底为什么它不会重新启动后推出。
I have verified there is no issue running Activity1.java - the issue lies either in the Manifest or the BootUpReceiver
class but I'm not sure exactly why it will not launch after rebooting.
public class BootUpReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, Activity1.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.com.idg.voiscphone"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.idg.voiscphone.Activity1"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.idg.voiscphone.Activity2"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.idg.voiscphone.Activity3"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.idg.voiscphone.Activity3a"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.idg.voiscphone.Activity3b"
android:label="@string/app_name" >
</activity>
<receiver android:enabled="true" android:name=".BootUpReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
</manifest>
示例源:
的http://androidrocksonmobility.blogspot.com/2012/01/how-to-create-auto-start-android.html
推荐答案
删除的android:权限=android.permission.RECEIVE_BOOT_COMPLETED
键,然后重试。
除此之外,还有就是你的活动出现,可能在同一时间启动任何其他活动,面前如主屏幕没有任何要求。
Beyond that, there is no requirement that your activity appear in front of any other activity that might be started around the same time, such as the home screen.
这篇关于android.permission.RECEIVE_BOOT_COMPLETED不会在开机启动活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!