在Android(5.1版)中以编程方式接听电话

时间:2017-02-21 15:43:09

标签: android call android-5.1.1-lollipop

我正在开发适用于Android的应用程序(Android版本5.1)。我想以编程方式回答电话。我在网上发现很多帖子使用:

 try {
    Runtime.getRuntime().exec("input keyevent " +
            Integer.toString(KeyEvent.KEYCODE_HEADSETHOOK));
} catch (IOException e) {
    // Runtime.exec(String) had an I/O problem, try to fall back
    String enforcedPerm = "android.permission.CALL_PRIVILEGED";
    Intent btnDown = new Intent(Intent.ACTION_MEDIA_BUTTON).putExtra(
            Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN,
                    KeyEvent.KEYCODE_HEADSETHOOK));
    Intent btnUp = new Intent(Intent.ACTION_MEDIA_BUTTON).putExtra(
            Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP,
                    KeyEvent.KEYCODE_HEADSETHOOK));

    mContext.sendOrderedBroadcast(btnDown, enforcedPerm);
    mContext.sendOrderedBroadcast(btnUp, enforcedPerm);
}

但上面的代码似乎对我不起作用。请任何人帮忙吗?

0 个答案:

没有答案