表现:
<application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".AlarmActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> </intent-filter> </activity> <receiver android:name="CallReciver"> <intent-filter> <action android:name="android.intent.action.PHONE_STATE"> </action> </intent-filter> </receiver> <receiver android:name=".SmsReceiver"> <intent-filter android:priority="1000"> <action android:name= "android.provider.Telephony.SMS_RECEIVED" /> </intent-filter> </receiver> <receiver android:name=".OnBootReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> <service android:enabled="true" android:name=".AlarmService"> </service> </application> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"> </uses-permission> <uses-permission android:name="android.permission.READ_PHONE_STATE"> </uses-permission> <uses-permission android:name="android.permission.WRITE_SMS"> </uses-permission> <uses-permission android:name="android.permission.READ_SMS"> </uses-permission> <uses-permission android:name="android.permission.SEND_SMS"> </uses-permission> <uses-permission android:name="android.permission.RECEIVE_SMS"> </uses-permission> <uses-permission android:name="android.permission.INTERNET"> </uses-permission>
接收器:
import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; import android.widget.Toast; public class OnBootReceiver extends BroadcastReceiver { @Override public void onReceive(Context context,Intent intent) { Log.d("Test","booot"); Toast.makeText(context,"Test",Toast.LENGTH_LONG).show(); } }
接收器不工作.我关掉了我的设备,没有任何反应.
SMS和Call Receiver在这个项目中工作得很好.
SMS接收器和CallReceviver – 工作正常.
第一次更新 – 添加完整清单.
解决方法
如果您有HTC设备,您还需要注册“android.intent.action.QUICKBOOT_POWERON”.所以清单中的输入应该是:
<receiver android:name=".OnBootReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.QUICKBOOT_POWERON" /> </intent-filter> </receiver>
在我的HTC上,如果我关闭设备并打开一段时间,我有QUICKBOOT_POWERON,没有BOOT_COMPLETED.
如果我关闭设备并取出电池一段时间 – 启动后我收到BOOT_COMPLETED.