I’m trying to detect and read any NFC tag that gets near the device.
I modified the AndroidManifest.xml to add the NDEF and TAG discovered intent filters to the UnityPlayerProxyActivity.
Also added nfc permissions at the end
.......
<activity android:name="com.unity3d.player.UnityPlayerProxyActivity" android:screenOrientation="sensorLandscape"
android:label="@string/app_name"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.NFC" />
<uses-feature android:name="android.hardware.nfc" />
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="15" />
</manifest>
then on a unity script I’m running the following code:
public void Update()
{
AndroidJavaClass JClass1 = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject mActivity = JClass1.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject mIntent = mActivity.Call<AndroidJavaObject>("getIntent");
string sAction = mIntent.Call<string>("getAction");
Debug.Log(sAction);
}
The problem is that sAction is never “android.nfc.action.NDEF_DISCOVERED”. In fact its never different from “android.intent.action.MAIN”
Am I missing something. Do I need to write a java class inheriting from UnityPlayerActivity?
As soon as a NFC tag gets near the device, a popup appears telling me that it has collected an Empty Tag but my app doesn’t return a different intent or action string.
Any help will be awesome!