Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
shafich
Posts: 74
Registered: ‎01-12-2012
My Device: Developer
My Carrier: Developer
Accepted Solution

use NFC to open my application ???

Hello,
I am new to using NFC.
I was able so far to read a tag and to write to a tag (learned the official supportforums.blackberry post on NFC)
...

However is question is "How can I open my application when the NFC is triggered"
say I am writing the following String to my tags "myAppName_[id] : url=1"
where "myAppName_[id]" is unique.

So problem is that after reading any tag I have A DIALOG BOX WILL POP-UP containing the data in the nfc,
is there a way to open my application instead of getting this DIALOG ?


same question in a different words (sorry  because I am not knowing how to express myself well ):
Is it possible to Open my application (or bring it from foreground to background) , AFTER reading and Verifying(verifying it via myfunction that will make sure that this tag is mine! ) the TAG (via NFC).

Please use plain text.
Retired
mwoolley
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: use NFC to open my application ???

Hi

 

I'm not completely sure I understand the question so let me start with some basics and then you can correct me if I have this wrong.

 

To have an NFC tag launch a particular application, you do not put the application details in the tag. You must implement the NDEFMessageListener interface and then register your application as a listener using the ReaderWriterManager addNDEFMessageListener method. This will register your application as a handler for tags containing NDEFMessages of a particular type. By "type" I mean type and Type Name Format as defined by the NFC Forum. You might specifiy TNF=TNF_WELL_KNOWN and Type="Sp" for example if you want your application to handle Smart Poster tags.

 

When a tag of a given type is read:

1. if no application has registered for that type then your device may beep/vibrate but no other action will be apparent

2. if only one application has registered (say, your application) then your application will be launched and you should not see a dialogue.

3. if the only application to have registered for that type is the standard Smart Tags application then you will see a screen giving details of the tag content and asking you to confirm an action (like launching the browser)

4. if more than one application has registered for this type (e.g. your app and the Smart Tags app) then you will see a dialogue listing the applications and be asked to select one. 

 

I'm guessing you are seeing the screen in (3). If so then this indicates your application has not registered for this type.

 

If you only want your app to be launched to handle a tag of a given type then consider using TNF_EXTERNAL which allows you to create your own, custom tag types which no other application will know about. As the only handler for that type, your app will be launched with no intermediate dialogue or screen and you have complete control over the user experience.

 

Details and examples of how to work with tags are explained here:

 

http://supportforums.blackberry.com/t5/Java-Development/Reading-and-Writing-NFC-Smart-Tags/ta-p/1379...

 

Information on how tag handlers behave is given here:

 

http://supportforums.blackberry.com/t5/Java-Development/NFC-NDEF-Message-Handling-Behaviors/ta-p/153...

 

Let me know if you need more help with this.

 

Regards

 

Martin

 

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Please use plain text.
Regular Contributor
shafich
Posts: 74
Registered: ‎01-12-2012
My Device: Developer
My Carrier: Developer

Re: use NFC to open my application ???

Thank you for replying ...

What I am trying to achieve is to make myApplication launch when say "a specific tag is read by the NFC"

but what I am actaully getting now is this:

4. if more than one application has registered for this type (e.g. your app and the Smart Tags app) then you will see a dialogue listing the applications and be asked to select one. 


I saw some other applications for NFC that do not show this dialog (Example: NFCspeaker does not prompt a Dialog to choose with WHICH app do i want to read this TAG(in the speaker), no instead it just opens the bluetooth and prompts ITS OWN dialog saying "connected to NFCSpeaker") <= I want something like this. Is it possible ?

So now after you explaining ...I guess I should not be using "NDEF" since it is available for all developers (meaning any one working with NFC will/can use this for his application so the DIALOG box will appear incase the DEVICE contains more than 1 NFC NDEF registered apps) . 
So my guess is I need to do something unique/custom for reading/writing on the tag,
so that  Case - 2
2. if only one application has registered (say, your application) then your application will be launched and you should not see a dialogue.  )
always happens.

Am I thinking right ?
Is it possible ?


And...Thank you  :smileyhappy:  

Please use plain text.
Retired
mwoolley
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: use NFC to open my application ???

Hi

 

yes, using a custom type would be a good move. Note that this is still "NDEF" though.... the NDEF format allows you to define your own types. But since no other type will know about the type you invented, only your application will have registered.

 

The BlueTooth scenario is a little different. This is something known as connection handover. It's triggered by the device when certain types of NDEF message are encountered automatically and usually the NDEF message is being transferred using something called SNEP (Simple NDEF Exchange Protocol) rather than standard tag reading.... the difference being that SNEP is a peer to peer protocol. I wouldn't worry about this if I were you as I don't think it's important for your aim.

 

Invent your own type. You'll need a type and domain value and to specify then when registering as a single string seperated by a ":" so for example:

 

com.martin:special_type

 

So your code might look like this:

 

ReaderWriterManager nfcManager = ReaderWriterManager.getInstance();
nfcManager.addNDEFMessageListener(listener,
NDEFRecord.TNF_EXTERNAL, "com.martin:special_type");

 

Good luck

 

Martin

 

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Please use plain text.
Regular Contributor
shafich
Posts: 74
Registered: ‎01-12-2012
My Device: Developer
My Carrier: Developer

Re: use NFC to open my application ???

Thanks ...
That worked perfectly ! :smileyvery-happy:
I really Appreciate ur help. 

Please use plain text.
Retired
mwoolley
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: use NFC to open my application ???

You're welcome. Please that worked for you :-)

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Please use plain text.
New Contributor
lferreira
Posts: 6
Registered: ‎12-27-2012
My Device: Curve 9360
My Carrier: Vivo

Re: use NFC to open my application ???

Hi, I've tried to do that, but it threw a NFCException with the following message: " Your NFC applications do not recognize this content...".

 

Here's a piece of the code:

ReaderWriterManager rwManager = ReaderWriterManager.getInstance();
rwManager.addNDEFMessageListener( new NDEFMsgListener(), NDEFRecord.TNF_EXTERNAL, "mydomain.com:mytype" );

 

I'm not sure, but I think only setting the string "mydomain.com:mytype" doesn't actually create a custom External Type. Anyway, I still don't know how to fix this.

Thanks,

 

Lucas

 

Please use plain text.
Developer
simon_hain
Posts: 16,113
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: use NFC to open my application ???

please open a new thread. you can link relevant topics there.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Retired
mwoolley
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: use NFC to open my application ???

It's the NDEFRecord.TNF_EXTERNAL that designates the type as "EXTERNAL" not the string.

 

Make sure you are registering your listener when application is first installed by making it an auto-starting application.

 

Our sample application NfcRaceTime7 uses custom external tags and shows how to register on start-up here:

 

https://github.com/blackberry/Samples-for-Java/blob/master/NFC/NfcRaceTime7/src/nfc/sample/racetimeb...

 

and here's the registration code itself:

 

https://github.com/blackberry/Samples-for-Java/blob/master/NFC/NfcRaceTime7/src/nfc/sample/racetimeb...

 

Let me know how this goes for you.

 

Regards

 

Martin

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Please use plain text.
New Contributor
lferreira
Posts: 6
Registered: ‎12-27-2012
My Device: Curve 9360
My Carrier: Vivo

Re: use NFC to open my application ???

I managed to fix my error, but this didn't really help me, I'm sorry. Thank you for the fast reply anyway :smileyhappy:
Please use plain text.