chariotsolutions / phonegap-nfc

PhoneGap NFC Plugin
MIT License
712 stars 568 forks source link

Usage of "Choose an option" in Android #347

Closed marioshtika closed 5 years ago

marioshtika commented 6 years ago

In an Android phone if you get your NFC device close to your mobile. It prompts an action sheet that gives the user the option to choose which application he wants to open it with.

Can your plugin do this? Is there any thing I can do to make it happened?

Thank you in advanced.

simonGleamorb commented 5 years ago

You could get your payload informations with this plugin and do what you want after. For example, display a modalWindow with your payloads info inside and some href or other. It depend what are the option and action that you want to use.

don commented 5 years ago

@marioshtika When there are multiple apps that can handle NFC tags, Android will present the user with a list.

One strategy is to do something make your tags unique. You can use a mime type and restricting filtering to just your tags. This doesn't work as well with a generic app that scans multiple tags.

marioshtika commented 5 years ago

Hello @don and thank you for your response. How can I use a mime type and restricting filtering to just my tags. Can this be done in a cordova project? Can this be done through your plugin? Or should this be done through the android project?

Thank you in advance.

don commented 5 years ago

You can do this with Cordova, but you need to edit the [AndroidManifest.xml](Launching your Android Application when Scanning a Tag) to specify which tags launch your app. In your app, you need to use nfc.addMimeTypeListener to handle the tag that launched the app. The intent filter can filter on mime-type, plain-text, or a URL. See the Android NFC docs for additional details. You'll need to figure out which NDEF type to use for your tags. You can make up a new mime type or use a url.