我有一个非常简单的问题让我发疯。我正在创建一个 BroadcastReceiver,在清单上声明它,但它不会运行。我试图让它在设备启动时触发。这是代码:
package com.vullnetdyla.bcreceiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class Receiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("ftw", "It worked");
}
}
和清单文件:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vullnetdyla.bcreceiver"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:theme="@style/AppTheme">
<receiver android:name="com.vullnetdyla.bcreceiver.Receiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>