高版本自动接听电话方法
原文地址:http://www.eoeandroid.com/forum.php?mod=viewthread&tid=894679&page=1&_dsign=b92c470b
高版本自动接听电话方法:
try {
Method method = Class.forName("android.os.ServiceManager")
.getMethod("getService", String.class);
IBinder binder = (IBinder) method.invoke(null, new Object[]{TELEPHONY_SERVICE});
ITelephony telephony = ITelephony.Stub.asInterface(binder);
telephony.answerRingingCall();
} catch (NoSuchMethodException e) {
Log.d("Sandy", "", e);
} catch (ClassNotFoundException e) {
Log.d("Sandy", "", e);
}catch (Exception e) {
Log.d("Sandy", "", e);
try{
Log.e("Sandy", "for version 4.1 or larger");
Intent intent = new Intent("android.intent.action.MEDIA_BUTTON");
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK);
intent.putExtra("android.intent.extra.KEY_EVENT",keyEvent);
sendOrderedBroadcast(intent,"android.permission.CALL_PRIVILEGED");
} catch (Exception e2) {
Log.d("Sandy", "", e2);
Intent meidaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK);
meidaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT,keyEvent);
sendOrderedBroadcast(meidaButtonIntent, null);
}
}