打电话
<intent-filter >
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
</intent-filter>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
接电话
<intent-filter >
<action android:name="android.intent.action.PHONE_STATE"/>
</intent-filter>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
开机:有点问题
<intent-filter >
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
安装包相关
<intent-filter >
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
//注意这个是必须的
<data android:scheme="package"/>
</intent-filter>
<uses-permission android:name="android.permission.RESTART_PACKAGES"/>
接受短信 pdus是标准
<intent-filter >
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Object[] object = (Object[]) intent.getExtras().get("pdus");
for (Object obj : object) {
SmsMessage ss = SmsMessage.createFromPdu((byte[]) obj);
String messageBody = ss.getMessageBody();
String originatingAddress = ss.getDisplayOriginatingAddress();
System.out.println(messageBody+":"+originatingAddress);
}
}
}
屏幕的锁屏和解锁:由于解锁等事件是发生的比较频繁的所以只可以使用代码进行注册
receiver = new BootReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction("android.intent.action.SCREEN_OFF");
filter.addAction("android.intent.action.SCREEN_ON");
registerReceiver(receiver, filter);
unregisterReceiver(receiver);