0
我正在寫一個應用程序接收SMS數據信息,加密其內容並將其保存到數據庫。爲了實現它,我已經創建了一個服務與本地廣播接收器如下:BroadcastReceiver在服務沒有反應
public class SMMReceiverService extends Service {
private class SMMreceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent)
{
Bundle extras = intent.getExtras();
//call a method from service
}
}
private SMMreceiver smmReceiver;
private IntentFilter intentFilter;
@Override
public void onCreate(){
super.onCreate();
android.os.Debug.waitForDebugger();
smmReceiver = new SMMreceiver();
intentFilter = new IntentFilter();
intentFilter.addAction("android.provider.Telephony.DATA_SMS_RECEIVED");
intentFilter.addDataScheme("sms");
intentFilter.addDataAuthority("localhost","8901");
registerReceiver(smmReceiver, intentFilter);
}
}
服務正常啓動,但SMMreceiver的的onReceive方法不會被調用。在清單中,我只聲明我的服務如下:
<service
android:name=".Services.SMMReceiverService"
android:enabled="true"
android:exported="true" >
</service>
也有所有必需的權限:
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
如何解決我在正確的方式問題嗎?我會感謝您的幫助!
我認爲,當接收機動態註冊時,我不必聲明它在清單。我還需要將接收器更改爲靜態並將其公開。 – Blady214