I'm developing an application which is allowed to be used as Launcher as well. We use mainly Samsung tablet that have recently received an upgrade to Android 5.1.1 which seems to have changed how our App behaves when used as launcher.
The problem is that Android seem to use the default com.android.nfc/.NfcRootActivity
system default activity instead of our application. It works fine when the application is started regular. This was used to work before the Samsung deployed the update.
Here is log snipped .
When started as launcher (NFC NOT WORKING)
Line 474: E/NxpNfcJni( 1457): setReconnectState = 0x0
Line 476: D/NativeNfcTag( 1457): Starting background presence check
Line 478: D/NfcDispatcher( 1457): tryStartActivity. Send intent.
Line 480: D/PackageManager( 1014): Resolving for NFC Intent { flg=0x10008000 cmp=com.android.nfc/.NfcRootActivity (has extras) } flag 66688 user 0
Line 480: D/PackageManager( 1014): Resolving for NFC Intent { flg=0x10008000 cmp=com.android.nfc/.NfcRootActivity (has extras) } flag 66688 user 0
Line 480: D/PackageManager( 1014): Resolving for NFC Intent { flg=0x10008000 cmp=com.android.nfc/.NfcRootActivity (has extras) } flag 66688 user 0
Line 482: W/ResourcesManager( 1014): Asset path '/system/framework/com.broadcom.nfc.jar' does not exist or contains no resources.
Line 492: V/WindowManager( 1014): addAppToken: AppWindowToken{11f6a866 token=Token{513b8c1 ActivityRecord{951b5a8 u0 com.android.nfc/.NfcRootActivity t24}}} to stack=1 task=24 at 0
Line 492: V/WindowManager( 1014): addAppToken: AppWindowToken{11f6a866 token=Token{513b8c1 ActivityRecord{951b5a8 u0 com.android.nfc/.NfcRootActivity t24}}} to stack=1 task=24 at 0
Line 498: D/NfcPlugin( 1494): onPause Intent { }
Line 502: D/NfcPlugin( 1494): stopNfc
And when started regular (WORKING)
Line 261: E/NxpNfcJni( 1457): setReconnectState = 0x0
Line 263: D/PersonaManager( 1457): isNFCAllowed
Line 269: D/NativeNfcTag( 1457): Starting background presence check
Line 273: W/ActivityManager( 1014): startActivity called from non-Activity context; forcing Intent.FLAG_ACTIVITY_NEW_TASK for: Intent { act=android.nfc.action.TECH_DISCOVERED flg=0x24000000 cmp=com.bstmedia.xxx/yyy.KioskActivity (has extras) }
Line 277: D/NfcPlugin( 1494): onPause Intent { }
Line 279: D/NfcPlugin( 1494): stopNfc
Here is what we have in the Manifest file.
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|uiMode" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="@string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<data android:mimeType="text/xxx" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|uiMode" android:keepScreenOn="true" android:label="My App Name" android:launchMode="singleInstance" android:name="yyy.KioskActivity" android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</activity>
It seems that the foreground dispatch mode was not triggered when the device is restarted and the app opened as launcher. We did not found a way to change this behavior.
However a quick fix was to press the "recent app" button which than activated the forground dispatch mode for NFC once the app comes back to foreground.
We add the code from https://stackoverflow.com/a/32453115/2616377 to have this happen automatically on every reboot.
I understand that this will not work with every device or android version. But we are happy to go this direction since the issue is specific to that particular Samsung update anyway.