How to grant MODIFY_PHONE_STATE permission for apps ran on Gingerbread

后端 未结 5 1391
粉色の甜心
粉色の甜心 2020-11-22 15:40

I write an application that attempts to modify phone call state. It works well on Android 2.2 or less, but throw an exception on Android 2.3 because of the lack of permissio

5条回答
  •  萌比男神i
    2020-11-22 15:51

    Try this.

    public static void answerPhoneHeadsethook(Context context) {
        // Simulate a press of the headset button to pick up the call
        // SettingsClass.logMe(tag, "Simulating headset button");
        Intent buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON);
        buttonDown.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK));
        context.sendOrderedBroadcast(buttonDown, "android.permission.CALL_PRIVILEGED");
    
        // froyo and beyond trigger on buttonUp instead of buttonDown
        Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);
        buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
        context.sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");
    }
    

提交回复
热议问题