Android: NFC intents in library that main project depends on

sub1020

New member
Jul 25, 2018
1
0
0
I am new to Android development...

I have an application which uses a library to upload data to a website. I want to make additions to the application to be able to read NFC tags.

I started out creating a small, separate application to get the hang of NFC. That app works fine. Now, I need to bring in some of that code into this other application which depends on the aforementioned library.

The problem is, UNLESS I add an application node to the AndroidManifest.xml in the LIBRARY specifying the NFC intents, the intents do not fire.

[Snippet from library manifest mentioned above]

<application
android:supportsRtl="true"
android:allowBackup="true">
<activity
android:name=".MainActivity"
android:label="My App..."
android:supportsRtl="true">
<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.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
[The main application contains this application node in its manifest]

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.microsoft.azure.storage.samples.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<meta-data
android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/nfc_tech_filter" />
</activity>
</application>
Now comes the problem.... when a tag is detected, android tries to launch the activity from the library manifest file. Since that activity doesn't exist, I get a ClassNotFoundException. I tried specifying MainActivity class from the application for the android:name of the application node in the LIBRARY manifest, but:

I can't compile the code.
It would be extremely poor practice even if that worked...
How do I get the NFC intents to fire without having to add intent-filter nodes in the library manifest?

Thank you!
 
I moved this to the Software Development forum for more specific traffic.
 

Forum statistics

Threads
955,527
Messages
6,965,076
Members
3,163,304
Latest member
dijjf