Android Beam - fallback when my app is not install

2019-04-02 20:02发布

问题:

I've had a play with the Android Beam sample code and have it working with two devices, sending a string of text. However, if the recipient doesn't have the app installed, my tag is simply collected for use at a later date.

It is possible in some way to take the user to the Android Market if my app is not installed, and to process the data in the intent if it is installed?

回答1:

There is a piece of commented code in the Beam sample that already has the application record set up for you. Just uncomment it and see if that is the behavior you want.



回答2:

To make it work on pre-ICS devices, you can send an NDEF message that consists of 3 records: 1) The Market URL of the app in a URI record (or SmartPoster record) 2) The data you want to Beam 3) The Android Application Record for your app When you add an Intent filter to the Android Manifest file to filter for the Market URL (on pre-ICS devices) in an ACTION_NDEF_DISCOVERED Intent, your app will be started if it is installed and otherwise the Market app will be opened.