telephonyService := TAndroidHelper.Context.getSystemService(TJContext.JavaClass.TELEPHONY_SERVICE); telephonyManager := TJTelephonyManager.Wrap((telephonyService as ILocalObject).GetObjectID);
if JStringToString(Intent.getAction).Equals('android.intent.action.PHONE_STATE') then begin state:= Intent.getStringExtra(TJTelephonyManager.JavaClass.EXTRA_STATE);
if state.equals(TJTelephonyManager.JavaClass.EXTRA_STATE_IDLE) then outputResult:= outputResult + 'Phone is IDLE ' + #13#10 else if state.equals(TJTelephonyManager.JavaClass.EXTRA_STATE_RINGING) then begin incomingCallNumber:= JStringToString(Intent.getStringExtra(TJTelephonyManager.JavaClass.EXTRA_INCOMING_NUMBER)); if incomingCallNumber.Equals('') then incomingCallNumber:= 'PRIVATE NUMBER';
outputResult:= outputResult + 'Phone is RINGING' + #13#10; outputResult:= outputResult + 'Incoming call from ' + incomingCallNumber + #13#10; if incomingCallNumber = '1371510XXXX' then //要屏蔽的电话号码 if KillCall(Context) then outputResult:= outputResult + 'Call was terminated' + #13#10 else outputResult:= outputResult + 'Call was not terminated' + #13#10; end else if state.equals(TJTelephonyManager.JavaClass.EXTRA_STATE_OFFHOOK) then outputResult:= outputResult + 'Phone is OFFHOOK' + #13#10; end else if JStringToString(Intent.getAction).Equals('android.intent.action.NEW_OUTGOING_CALL') then begin outgoingCallNumber:= JStringToString(Intent.getStringExtra(TJIntent.JavaClass.EXTRA_PHONE_NUMBER)); outputResult:= outputResult + 'Outgoing call to ' + outgoingCallNumber + #13#10; if outgoingCallNumber = 'xyz' then begin BroadcastReceiver.SetResultData(nil); outputResult:= outputResult + 'Call is not allowed to ' + outgoingCallNumber + #13#10; end; end;