如何关闭物理按钮的点击声(音效),在我的Andr​​oid应用程序? [英] How to turn off physical button's sound click (sound effects) in my Android app?

查看:214
本文介绍了如何关闭物理按钮的点击声(音效),在我的Andr​​oid应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Android应用程序,用户可以静置他的手在设备上,我要禁用物理按键,使用户不会被不必要的点击生气。

I'm developing an Android app where the user is allowed to rest his hand on the device, and I want to disable physical buttons so the user don't get annoyed by unwanted clicks.

我已经禁用了返回 菜单搜索使用以下按钮:

I've disabled the back, menu and search buttons with the following:


@Override
public void onBackPressed() {}

@Override
public boolean onPrepareOptionsMenu(Menu menu) {return false;}

@Override
public boolean onSearchRequested() {return false;}

和我已经了解到,禁止在首页键不受支持和/或不劝(虽然我想它)。

And I've learned that disabling the home key is unsupported and/or not adviced (although I'd like it to).

好了,现在我无法弄清楚如何禁用我残疾,他们什么也不做密钥的咔嗒声,但保留滴答作响,有没有办法把它关掉?

Ok, now I couldn't figure out how to disable the clicking sound for the keys I've disabled, they do nothing but keep ticking, is there a way to turn it off?

我想为静音它为我的应用程序而已。如果没有可能,我想知道有关以编程方式更改系统设置的替代品,将其还原后的关闭或焦点变化。

I'd like to mute it for my app only. If not possible, I'd like to know about alternatives that change system settings programmatically, to restore it latter on closing or on focus changing.

推荐答案

您可以静音当你的应用程序启动并在完成后取消静音

You can mute the sound when your app starts and unmute when it finishes

@override
public void onResume(){
    super.onResume();
    AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
    mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true);
}


@override
public void onPause(){
    super.onPause();
    AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
    mgr.setStreamMute(AudioManager.STREAM_SYSTEM, false);
}

这篇关于如何关闭物理按钮的点击声(音效),在我的Andr​​oid应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆