1.注册BroadcastReceiver的两种方法:
1).使用代码进行指定:
IntentFilter filter=new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
IncomingSMSReceive isr=new IncomingSMSReceive();
registerReceiver(isr, filter);
2).在配置文件中配置:
<receiver android:name=".IncomingSMSReceive"
>
<intent-filter ><action android:name="android.provider.Telephony.SMS_RECEIVED"/></intent-filter>
</receiver>
2.发送广播
启动具有指定action的广播
Intent intent=new Intent();
intent.setAction("android.provider.Telephony.SMS_RECEIVED");
sendBroadcast(intent);
3.有序广播
发送广播的两种方法:
sendBroadcast(intent);
sendOrderedBroadcast(intent, null);
有序广播中可以指定广播优先级:配置文件的<intent-filter.../>中的android:priority属性,或使用代码中的IntentFilter的setPriority方法 属性范围-1000~1000,数越大优先级越高,用以下方法取出或加入广播传递过程中的数据:
setResultExtras(Bundle extras);
getResultExtras(boolean makeMap);
终止广播:
abortBroadcast();