Prevent alert tone when scanning / identifying an

2019-08-08 16:34发布

Perhaps I'm missing something but when I scan an NFC tag via a galaxy nexus, the phone always makes the default alert tone.

Is there a way of programmatically switching this off ? I have scoured the menus / preferences and can't find a way of doing this. The next step ... ICS source code :-/

3条回答
疯言疯语
2楼-- · 2019-08-08 17:10

There isn't a way to pro grammatically turn this sound off or to override the Touch to Beam UI.

查看更多
看我几分像从前
3楼-- · 2019-08-08 17:32

with android-19 you can:

as described in: http://developer.android.com/reference/android/nfc/NfcAdapter.html#FLAG_READER_NO_PLATFORM_SOUNDS

By using NfcAdapter.enableReaderMode() and the flag FLAG_READER_NO_PLATFORM_SOUNDS instead of NfcAdapter.enableForegroundDispatch()

查看更多
我只想做你的唯一
4楼-- · 2019-08-08 17:36

Here is a simple example of how to silence/change nfc sounds

public class MainActivity extends Activity implements ReaderCallback{
private NfcAdapter mNfcAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
}

@Override
public void onResume() {
    super.onResume();
    // This example works using using simple mifare ultralight tags. Set any necessary flags for other tags 
    mNfcAdapter.enableReaderMode(this, this, NfcAdapter.FLAG_READER_NFC_A | NfcAdapter.FLAG_READER_NO_PLATFORM_SOUNDS, null);
}

@Override
public void onPause() {
    super.onPause();
    mNfcAdapter.disableReaderMode(this);
}

@Override
public void onTagDiscovered(Tag tag) {
    // Play your own sound here

    // Then handle your tag
}

}

查看更多
登录 后发表回答