Prevent alert tone when scanning / identifying an NFC intent

◇◆丶佛笑我妖孽 提交于 2019-12-11 05:49:09

问题


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 :-/


回答1:


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




回答2:


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()




回答3:


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
}

}



来源:https://stackoverflow.com/questions/8743588/prevent-alert-tone-when-scanning-identifying-an-nfc-intent

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!