0

当用户按下按钮时,我正在尝试编程免提通话。

到目前为止,我可以拨打电话,但无法启用免提模式。

我尝试了这个答案,但它对我不起作用。

这是我的代码示例:

private void callCaregiver(String number){
        Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+number.trim()));          
        enableHandsFree();           
        startActivity(callIntent);
    }

    private void enableHandsFree(){
        Class audioSystemClass = Class.forName("android.media.AudioSystem");
        Method setForceUse = audioSystemClass.getMethod("setForceUse", int.class, int.class);
        // First 1 == FOR_MEDIA, second 1 == FORCE_SPEAKER. To go back to the default
        // behavior, use FORCE_NONE (0).
        setForceUse.invoke(null, 1, 1);
    }

有没有人知道另一种让它工作的方法?

4

0 回答 0