Android BroadCastReceiver で次のコード スニペットを使用して、android.intent.action.PHONE_STATE 変更イベントをキャッチしています。イベントを正常に認識し、着信コールを処理することも、次のコードで実行できます。
私の要件は、特定の番号から着信している通話を識別し、コードを介してその通話を終了し、その着信イベントに対して Web サービスを呼び出すことです。
ここでは、このコードは着信イベントと終了イベントに対して 2 回実行されます。
このメソッドを 2 回呼び出すのをやめたいです。2 番目のイベントのコード スニペットの呼び出しを停止するにはどうすればよいですか (呼び出しを終了します)。誰かがこれについて私を助けることができれば、それは素晴らしいことです。
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");
}
}
}