當前位置:名人名言大全網 - 短信平臺 - BroadcastReceiver 的onReceive方法為什麽不調用?

BroadcastReceiver 的onReceive方法為什麽不調用?

要確保壹下幾點都做到了:

(以短信為例)

1、訂閱對應的IntentFilter

在代碼中訂閱

IntentFilter filter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");

IncomingSMSReceiver receiver = new IncomingSMSReceiver();

registerReceiver(receiver, filter);

或者在在AndroidManifest.xml文件中的<application>節點裏進行訂閱:

2、權限聲明

比如接收短信的廣播

<uses-permission android:name="android.permission.RECEIVE_SMS"/><!-- 接收短信權限 -->

<uses-permission android:name="android.permission.SEND_SMS"/><!-- 發送短信權限 -->