我正在通過使用以下代碼片段與android BroadCastReceiver捕獲android.intent.action.PHONE_STATE更改事件。我可以成功識別事件並處理來電也可以通過以下代碼完成。Android BroadCastReceiver和android.intent.action.PHONE_STATE事件
我的要求是確定來自特定號碼的呼叫,通過代碼結束該呼叫並針對該呼入事件調用Web服務。
在這裏,這段代碼運行兩次,用於呼叫接收和結束事件。
我想停止兩次調用此方法。我該如何停止爲第二個事件調用該代碼段(結束呼叫)。如果有人能幫助我,這將是非常棒的。
if (intent.getAction().equals(
"android.intent.action.PHONE_STATE")) {
Log.i("INFO", "Call Received");
try {
TelephonyManager telephony = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
Bundle bundle = intent.getExtras();
Log.i("Calling database", "Creatinng DataHandler Object");
DatabaseHandler db = new DatabaseHandler(context);
String phoneNumber =db.getContact().getPhoneNumber();
Log.i("Retriving : ", "Retriving .."+ db.getContact().getPhoneNumber());
if ((bundle.getString("incoming_number").equals(phoneNumber))) {
Log.i("Test Call", "This is the test call");
@SuppressWarnings("rawtypes")
Class c = Class.forName(telephony.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
ITelephony telephonyService = (ITelephony) m
.invoke(telephony);
telephonyService = (ITelephony) m.invoke(telephony);
telephonyService.endCall();
// Call the web service and send log details
ServiceClient sc = new ServiceClient();
sc.serviceCall(context);
} else {
Log.i("Normal Call", "This is not the test call");
}
} catch (Exception e) {
Log.i("Exception Occured", "Exception in call code snipet");
}
}
}
哪部分代碼運行兩次? –
你解決了問題 – Dory