我在Android中的BROADCAST接收器有问题。所有接收器都工作良好,但不能RECEIVED_BOOT_COMPLETED工作。一些想法?
最快捷的文件:
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<receiver
android:name="telint.sms.appClass.SMSReceiver"
android:enabled="true" >
<intent-filter android:priority="2147483647" >
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
<action android:name="android.provider.Telephony.RECEIVE_BOOT_COMPLETED" />
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
法典:
public class SMSReceiver extends BroadcastReceiver {
private static final String ACTION_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
private static final String ACTION_BOOT = "android.provider.Telephony.RECEIVE_BOOT_COMPLETED";
private static final String ACTION_INTERNET = "android.net.conn.CONNECTIVITY_CHANGE";
private static final String ACTION_SHUTDOWN = "android.intent.action.ACTION_SHUTDOWN";
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(ACTION_BOOT)){
**//NOT WORKING HERE.**
}
}
我认为你的动作名称是错误的。
只需更换
<action android:name="android.provider.Telephony.RECEIVE_BOOT_COMPLETED" />
由
<action android:name="android.intent.action.BOOT_COMPLETED" />
而且
private static final String ACTION_BOOT = "android.provider.Telephony.RECEIVE_BOOT_COMPLETED";
由
private static final String ACTION_BOOT = "android.intent.action.BOOT_COMPLETED";
要完成启动,需要在 AndroidManifest 文件中添加 2 件事:
-
内部广播"接收器"的"意图过滤器"
<动作安卓:名称>
-
同时获得许可
<使用权限 />