我看到这已被问了很多,但我似乎无法解决我的问题。自动启动应用程序问题
我的onReceive()
广播接收器中的方法没有被调用。
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.app.test.TestActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:theme="@style/FullscreenTheme" >
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</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>
BootUpReceiver.java
package com.app.test;
public class BootUpReceiver extends BroadcastReceiver {
private static final String TAG = "TESTAPP_BootUpReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "helllllllllllllllo");
Toast.makeText(context, "boot completed received", Toast.LENGTH_LONG).show();
// Intent i = new Intent(context, TestActivity.class);
// i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// context.startActivity(i);
}
}
必须使用全路径,而不是试图.BootUpReceiver
,没有工作。没有看到任何来自logcat或任何Toast消息。进入adb shell
并发出boot_completed事件这种方式并不能帮助设备重新启动。
有什么我做错了吗?我读了一些关于应用程序在设备启动时处于不活动状态的问题,这是否会影响我的问题?
您不需要在 -tag内再次给予许可。尽管一见钟情,但我没有看到我的工作复兴和你的区别。我现在仔细观察:) –
bofredo
测试它。虽然日志消息未显示在我的日志中,但Toast在锁屏上可见。 – bofredo
这就是为什么吐司在那里 - 我读日志没有启动并在事件发送之前运行。我无法在锁屏中看到它,也许我会尝试其他设备。 – tbh1