Android广播启动完成无法正常工作

时间:2012-11-14 15:01:27

标签: android broadcastreceiver bootcompleted

我的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>

CODE:

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.**
     }

}

2 个答案:

答案 0 :(得分:3)

我认为你的行动名称是错误的。

只需替换

<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";

答案 1 :(得分:1)

要完成启动,需要在AndroidManifest文件中添加两项内容:

  • 内部广播“接收者”的“意图过滤器”

    &LT;动作android:name =“android.intent.action.BOOT_COMPLETED”/&gt;

  • 也获得许可

    &LT; uses-permission android:name =“android.permission.RECEIVE_BOOT_COMPLETED”/&gt;