Change the NFC sound

Please follow the instructions below to change the NFC sound files for FAMOCO devices:

Custom NFC sound files path:

  • /data/local/nfc-start.ogg
  • /data/local/nfc-end.ogg
  • /data/local/nfc-error.ogg

Code Add this somewhere between "on post-fs-data" block and "on init" block.

mediatek/config/itek82_wet_kk/init.project.rc

+## Allow access to /data/local
+chmod 0771 /data/local
+chown root shell /data/local 
packages/apps/Nfc/src/com/android/nfc/NfcService.java  

commit 91924f9291a3836e336aeb88433ea41af5d0fce1
Author: Guillaume Loret <guillaume@famoco.com>
Date:   Wed Feb 11 13:26:52 2015 +0100

    Allow to use custom NFC files sounds

    Custom files path:
    /data/local/nfc-start.ogg
    /data/local/nfc-end.ogg
    /data/local/nfc-error.ogg

diff --git a/packages/apps/Nfc/src/com/android/nfc/NfcService.java b/packages/apps/Nfc/src/com/android/nfc/NfcService.java
index 8cafbf3..580a7de 100644
--- a/packages/apps/Nfc/src/com/android/nfc/NfcService.java
+++ b/packages/apps/Nfc/src/com/android/nfc/NfcService.java
@@ -181,6 +181,11 @@ public class NfcService implements DeviceHostListener {
     // goes off
     static final int ROUTING_WATCHDOG_MS = 10000;

+    //Custom NFC sound files
+    public final static String NFC_START_SOUND_FILE = "/data/local/nfc-start.ogg";
+    public final static String NFC_END_SOUND_FILE = "/data/local/nfc-end.ogg";
+    public final static String NFC_ERROR_SOUND_FILE = "/data/local/nfc-error.ogg";
+
     // for use with playSound()
     public static final int SOUND_START = 0;
     public static final int SOUND_END = 1;
@@ -527,9 +532,16 @@ public class NfcService implements DeviceHostListener {
         synchronized(this) {
             if (mSoundPool == null) {
                 mSoundPool = new SoundPool(1, AudioManager.STREAM_NOTIFICATION, 0);
-                mStartSound = mSoundPool.load(mContext, R.raw.start, 1);
-                mEndSound = mSoundPool.load(mContext, R.raw.end, 1);
-                mErrorSound = mSoundPool.load(mContext, R.raw.error, 1);
+
+                //Try to load custom NFC sound files
+                mStartSound = mSoundPool.load(NFC_START_SOUND_FILE, 1);
+                mEndSound = mSoundPool.load(NFC_END_SOUND_FILE, 1);
+                mErrorSound = mSoundPool.load(NFC_ERROR_SOUND_FILE, 1);
+
+                //If a custom NFC sound file didn't load, use default sound
+                if (mStartSound == 0) mStartSound = mSoundPool.load(mContext, R.raw.start, 1);
+                if (mEndSound == 0) mEndSound = mSoundPool.load(mContext, R.raw.end, 1);
+                if (mErrorSound == 0) mErrorSound = mSoundPool.load(mContext, R.raw.error, 1);
             }
         }
     }

Test

Follow the process here below to test the new sound:

adb push nfc-start.ogg /data/local/nfc-start.ogg
adb push nfc-end.ogg /data/local/nfc-end.ogg
adb push nfc-error.ogg /data/local/nfc-error.ogg
  • Restart the device
adb shell reboot
  • Verify you hear the new NFC sounds by scanning a tag