Yes I have tried using Service /Broadcast reciever, having intent filter, 
not sure how to catch / read the intent filter while NFC tag is read


@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
System.out.println("on create");
 }

Manifest 

 <service
            android:name=".NfcService" >
             <intent-filter>
                <action android:name="android.nfc.action.TAG_DISCOVERED" />
                <!-- <action android:name="android.intent.action.VIEW" /> 
-->
                <category android:name="android.intent.category.DEFAULT" />

                <!-- <data android:mimeType="text/plain" /> -->
                <data android:mimeType="text/plain" />
                
            </intent-filter>
            
        </service>

BroadcastReciever 


public class NfcIntentReciever extends BroadcastReceiver{

@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if(intent.getAction().equals(NfcAdapter.ACTION_NDEF_DISCOVERED)){
System.out.println("Receiver :  ACTION_NDEF_DISCOVERED");
}
if(intent.getAction().equals(NfcAdapter.ACTION_TAG_DISCOVERED)){
System.out.println("Reciever : ACTION_TAG_DISCOVERED ");
}
} 
 }

Manifest for Reciever

<receiver android:name=".NfcIntentReciever" >
            <intent-filter>
                <action android:name="android.nfc.action.NDEF_DISCOVERED" />
                <!-- <action android:name="android.intent.action.VIEW" /> 
-->
                <category android:name="android.intent.category.DEFAULT" />

                 <data android:mimeType="text/plain" /> 
                                
            </intent-filter>
            
        </receiver>

I can see few logs whenever NFC tag is scanned

01-08 05:05:59.093: D/NfcDispatcher(473): dispatch tag: TAG: Tech 
[*android.nfc.tech.MifareUltralight, 
android.nfc.tech.NfcA, android.nfc.tech.Ndef*] message: NdefMessage 
[NdefRecord tnf=2 
type=6170706C69636174696F6E2F636F6D2E776970726F2E6E66637461676C696272617279 
payload=557365204D4D54206174204D63446E6C6420333025206F6666207573696E672049434943492044656269742043617264,
 
NdefRecord tnf=2 
type=6170706C69636174696F6E2F636F6D2E776970726F2E6E66637461676C696272617279 
payload=6F666665722E68746D6C]
01-08 05:05:59.117: D/NfcHandover(473): tryHandover(): NdefMessage 
[NdefRecord tnf=2 
type=6170706C69636174696F6E2F636F6D2E776970726F2E6E66637461676C696272617279 
payload=557365204D4D54206174204D63446E6C6420333025206F6666207573696E672049434943492044656269742043617264,
 
NdefRecord tnf=2 
type=6170706C69636174696F6E2F636F6D2E776970726F2E6E66637461676C696272617279 
payload=6F666665722E68746D6C]
01-08 05:05:59.128: I/*ActivityManager(258): START* {flg=0x10008000 
cmp=com.android.nfc/.NfcRootActivity (has extras) u=0} from pid 473
01-08 05:05:59.160: I/*NfcDispatcher(473)*: matched multiple TECH
01-08 05:05:59.164: I/*ActivityManager(258)*: START 
{cmp=com.android.nfc/.TechListChooserActivity (has extras) u=0} from pid 473
01-08 05:05:59.238: D/dalvikvm(473): GC_CONCURRENT freed 368K, 10% free 
8323K/9159K, paused 12ms+8ms, total 52ms
01-08 05:05:59.312: I/*ActivityManager(258): Displayed 
com.android.nfc/.TechListChooserActivity*: +142ms (total +160ms)


Does the above log means that it only allows to start Activity component 
from the NFC framework, whenever Tag is scaned, coz in case of Activity, we 
can see onNewIntent() is invoked whenevr Tag is detected with New Intent 
and singleTask flag is defined, but no such overriden method Im able to 
identify to detect the Intent discovery.

Same with Receiver, not sure if it is dependent with the framework, which 
needs to send a broadcast for this intent at all.

Let me know, if anybody has information with the same.

Thanks,
Pallavi Roy


On Monday, September 24, 2012 2:10:18 PM UTC+5:30, Nikolay Elenkov wrote:
>
> On Mon, Sep 24, 2012 at 5:24 PM, android_solutions 
> <[email protected] <javascript:>> wrote: 
> > Hi 
> > I am using NFC for Tag reading / Writing capability, I want to make a 
> > library service, which will run in background to listen to the NDEF or 
> Tag 
> > related intents. 
> > Is it possible to design application, where Service would listen to the 
> NDEF 
> > intents and not activity, using Broadcast Receivers, provided that I 
> cannot 
> > use onNewIntent() and onResume() for intent discovery. 
>
> Did you try it? Unless there are some additional checks in place, it 
> should 
> work since you are simply getting an intent, and if you have the proper 
> filters 
> your service should receive it. However, you cannot intercept all NFC 
> events, 
> since activities using foreground dispatch have priority if they register 
> for 
> the same tech, etc. 
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to