private void endCall() { try { mTelephony.endCall(); } catch (RemoteException e) { e.printStackTrace(); } }
@Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); if (null == bundle) return; this.mContext = context; Log.d(TAG, "Intent action: " + intent.getAction()); String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); Log.d(TAG, "Outgoing Call = " + phonenumber); SharedPreferences preferences = context.getSharedPreferences("TRIP", 1); boolean isTripStarted = preferences.getBoolean("isTripStarted", false); if (isTripStarted && new ConfigurePreferences(mContext).isTripAbandon()) { Log.v(TAG, "Outgoing call received when trip abandon"); return; } if (isTripStarted && !TrackingService.ignoreLocationUpdates) { if (TAGS.disableCall) { telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); connectToTelephonyService(); if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) { if (!isEmergencyNumber(phonenumber)) { try { Log.d(TAG, "Ending Outgoing Call"); setResultData(null); telephonyService.endCall(); } catch (RemoteException e) { e.printStackTrace(); } } else { Log.v(TAG, "Allowing emergency outgoing call & activate emergency trip save"); // Activate trip save as background new ConfigurePreferences(context).setEmergencyTripSave(true); // Util.saveInterruption(context, SCInterruption.EMEO); } } } else { if (isEmergencyNumber(phonenumber)) { Log.v(TAG, "Allowing emergency outgoing call & activate emergency trip save"); // Activate trip save as background new ConfigurePreferences(context).setEmergencyTripSave(true); // Util.saveInterruption(context, SCInterruption.EMEO); } else { if (!new ConfigurePreferences(mContext).isTripAbandon()) { Toast.makeText(mContext, "Outgoing call interruption", Toast.LENGTH_LONG).show(); Util.saveInterruption(context, SCInterruption.CALL); } } } } }
private void ringOff() { try { Method method = Class.forName("android.os.ServiceManager").getMethod("getService", String.class); IBinder binder = (IBinder) method.invoke(null, new Object[] {Context.TELEPHONY_SERVICE}); ITelephony mService = ITelephony.Stub.asInterface(binder); mService.endCall(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
@Override public synchronized void onResults(Bundle results) { ArrayList<String> matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION); Log.i(TAG, "result:"); for (String i : matches) { Log.i(TAG, "onResults content: " + i); } if (MyService.this.isCalling && (matches.contains("no") || matches.contains("No") || matches.contains("nO") || matches.contains("NO"))) { try { Class clazz = Class.forName(tmgr.getClass().getName()); Method method = clazz.getDeclaredMethod("getITelephony"); method.setAccessible(true); ITelephony telephonyService = (ITelephony) method.invoke(tmgr); telephonyService.endCall(); // MyService.this.isCalling = false; } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } else if (!MyService.this.isMakePhoneCall && (matches.contains("yes") || matches.contains("Yes") || matches.contains("yes") || matches.contains("YES"))) { PhoneUtil.answerRingingCall(MyService.this); } else { initComponent(); mSpeechRecognizer.startListening(mSpeechRecognizerIntent); } if (!MyService.this.isCalling) { ContentContact contentContact = MyService.this.getContactFromName(matches.get(0)); if (contentContact != null) { MyService.this.makePhoneCall(contentContact.getPhoneNumber()); } } }
private int test01PhoneCallEnd() { try { Log.i(TAG, "test01PhoneCallEnd"); Method method = Class.forName("android.os.ServiceManager").getMethod("getService", String.class); method.setAccessible(true); IBinder binder = (IBinder) method.invoke(null, new Object[] {TELEPHONY_SERVICE}); ITelephony phone = (ITelephony) ITelephony.Stub.asInterface(binder); phone.endCall(); return MSG_TEST_FINISH; } catch (ClassNotFoundException e) { Log.e(TAG, e.toString()); } catch (NoSuchMethodException e) { Log.e(TAG, e.toString()); } catch (InvocationTargetException e) { Log.e(TAG, e.toString()); } catch (IllegalAccessException e) { Log.e(TAG, e.toString()); } catch (RemoteException e) { Log.e(TAG, e.toString()); } return MSG_TEST_FAILED; }