android2.3无法自动接听电话的问题,原因是调用answerRingingCall时系统提示没有权限
Neither user 10099 nor current process has android.permission.MODIFY_PHONE_STAT
网上搜了一下发现Android 2.3后不开放使用 MODIFY_PHONE_STATE
详细参见:
http://code.google.com/p/android/issues/detail?id=15031
http://stackoverflow.com/questions/4715250/how-to-grant-modify-phone-state-permission-for-apps-ran-on-gingerbread
有没有人解决过这个问题呢?
网上搜索有两种解决方法,一种是应用有ROOT权限,另外一种是设置APK的UID和system的一样,可是都没有具体的实现方法,而且这两种方法也不是通用的。
有人实现过这个功能么
------解决方案--------------------
- Java code
public synchronized void answerRingingCall() {//据说该方法只能用于Android2.3及2.3以上的版本上 try { Intent localIntent1 = new Intent(Intent.ACTION_HEADSET_PLUG); localIntent1.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); localIntent1.putExtra("state", 1); localIntent1.putExtra("microphone", 1); localIntent1.putExtra("name", "Headset"); context.sendOrderedBroadcast(localIntent1, "android.permission.CALL_PRIVILEGED"); Intent localIntent2 = new Intent(Intent.ACTION_MEDIA_BUTTON); KeyEvent localKeyEvent1 = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK); localIntent2.putExtra("android.intent.extra.KEY_EVENT", localKeyEvent1); context.sendOrderedBroadcast(localIntent2, "android.permission.CALL_PRIVILEGED"); Intent localIntent3 = new Intent(Intent.ACTION_MEDIA_BUTTON); KeyEvent localKeyEvent2 = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK); localIntent3.putExtra("android.intent.extra.KEY_EVENT", localKeyEvent2); context.sendOrderedBroadcast(localIntent3, "android.permission.CALL_PRIVILEGED"); Intent localIntent4 = new Intent(Intent.ACTION_HEADSET_PLUG); localIntent4.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); localIntent4.putExtra("state", 0); localIntent4.putExtra("microphone", 1); localIntent4.putExtra("name", "Headset"); context.sendOrderedBroadcast(localIntent4, "android.permission.CALL_PRIVILEGED"); } catch (Exception e) { e.printStackTrace(); } }