Is there an app which calls a definable URL when a NFC sticker is detected? I want to put different stickers on my desk and when I place my phone on one of the stickers a specific URL should be call:
If StickerA is detectd call https://www.myserver.com/?val=a
If StickerB is detectd call https://www.myserver.com/?val=b
If StickerC is detectd call https://www.myserver.com/?val=c
etc.
Is this possible with android without activating the phone and is there a an existing app for that task?
With Web NFC on Android, any website can write a URL NDEF Record to an NFC tag. This URL will be launched in user's browser on Android when user taps NFC tag.
const urlRecord = {
recordType: "url",
data:"https://w3c.github.io/web-nfc/"
};
const ndef = new NDEFReader();
await ndef.write({ records: [urlRecord] });
See https://web.dev/nfc/#read-and-write-a-url-record
Detecting a sticker, and taking an action are two different things. When you detect a sticker, I think you can get the ID of the sticker, then, based on the ID, you would create an Action View Intent passing the URL and that would cause an external browser window to open with the URL you passed.
//pass any url to this function to open a new browser session
protected void handleExternalDeviceActivity(String url) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
}
you can write unique URL in every "sticker" or nfc tag by many Android App you can try NFC tools, then when you touch your Android device it will open the URL.
without activiating the Android device you will not be able to communicate with NFC tag*.
*you could with rooted device and you need to write the app by your self.
The Android OS itself has the ability to detect NFC and launch a web browser to open a URL on the NFC stickers/Tags (as long has the phone has NFC hardware and it is turned on)
The Sticker/Tag has to have the correctly formatted NDEF data written to it.
You can use https://play.google.com/store/apps/details?id=com.wakdev.wdnfc or other apps to write the correct data to the stickers/tags to store the URL correctly.
You can write your own App to do this as well but it does not require a "rooted device". But it does require then device to have the hardware and for it to be turned on.
Related
How can a user execute my NFC code without downloading my app?
The following code works so long as I have my app installed. However, in the real world, a user won't have my app installed. Rather I just want this code to execute just by scanning a Passive NFC tag. Code follows:
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if(intent.hasExtra(NfcAdapter.EXTRA_TAG))
{
Toast.makeText(this, "NfcIntent!", Toast.LENGTH_SHORT).show();
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage("5555555555", null, "Hello Folks", null, null);
NdefMessage ndefMessage = createNdefMessage("Hi! I am tag #1");
writeNdefMessage(tag,ndefMessage);
}
}
I'm just trying to send a text message from the user's phone to a predetermined number with a hard-coded message...thanks so much for any help.
How can a user execute my NFC code without downloading my app?
The code cannot be executed without the app.
The following code works so long as I have my app installed. However, in the real world, a user won't have my app installed.
Taken from this website:
"NFC tags are passive, meaning they don't have any power source. Instead, they literally draw power from the device that reads them, thanks to magnetic induction. When a reader gets close enough to a tag, it energizes it and transfer data from that tag."
This means they transfer data - they cannot execute code. You can transfer code, but the code will not do anything. The exception is if you have a custom app to recieve code to then execute it - but who has an app like that installed with their phone?
From this website:
"At the time of writing the NFC standard has three modes of operation: the peer-to-peer mode that lets two smartphones swap data, a read/write mode in which one active device picks up info from a passive one, and card emulation, in which an NFC device such as a smartphone can be used like a contactless credit card."
This means that as of now, the action you described:
Rather I just want this code to execute just by scanning a Passive NFC tag.
Is not possible without custom software. Which again means - the user has to install your app. and then the point is lost. In addition, I don't think they will open to code being executed by NFC tags, as it creates a massive security vounerability.
So as of writing, you have to promt the second user to install the app for it to work(if phone to phone transfers is what you are trying to do).
I am using Tizen SDK for Wearable from samsung-gear site in order to communicate a provider android application with Samsung Gear 2 device. I am able to send notifications to gear and once I run the consumer application on gear 2, I am able to transfer data between the watch and my Android phone as well.
What I am trying to do is to check within the Android application if the phone is paired with Gear 2. Something as simple as creating a communication object using the accessory service and calling a method like isPaired()?:
CommunicationObject commObject = new CommunicationObject(Communication parameters);
// I am assuming some connection call like commObject.connect() should be invoked first
// where I can check for it's result afterwards such as
if(commObject.isPaired())
{
// do something
}
I think SDK examples such as consumer/provider application they provide on their site already assume that the device is paired, hence they show how to transfer data between phone and the gear watch. Yet I am seeking something as simple as asking the phone if it's paired with a gear device, which should be the prerequisite for transferring the data, which is done automatically by Samsung Gear Manager I believe right now.
Note: For the case of example provider/consumer applications, one can just check if any connection is available using the code in them. But the data transfer connection enabled only when I manually start the consumer app from the gear device, otherwise it acts like gear device is not paired even though it is.
I believe this is not the most popular topic these days so I will post what I came up with as an answer although I doubt anyone will need it, without being perfect, it's the closest way I could get to my goal using the available documentation.
I should also mention that this slide helped me stay on track as well.
In my solution, there must be an active 2-way connection between the gear widget(consumer/.wgt) and the host side application(provider/.apk) as in the example application provided by Samsung(Hello Accessory) at all times, at least during the time where I wanted to check for the pairing condition. The documentation refers to it as:
Hello Gear is a simple application that consists of:
Host-side application(provider) : HelloAccessoryProvider.apk
Wearable-side Application(consumer) : HelloAccessoryConsumer.wgt (Web app)
See that both sides have some xml configuration and Android requires specific permissions which are explained in detail in Hello Gear documentation.
This 2 way communication is provided by the Samsung Accessory Framework on the network layer(through Samsung Accessory Protocol, SAP) given that both sides implement the same Accessory Service Profile, again, configured via the xml files on both ends(service name, channel id etc.).
Android side implements the protocol as a service, extending the SAAgent abstract class. Then the widget on gear side application(.wgt) can invoke the SAAgent callbacks and provider/consumer communication is handled through SASocket objects claimed on both ends over the predefined channel in the xml configuration files.
Please note that this communication has to be initialized on both ends, in my case I had to open the widget application once on Gear(I believe there should be a way to start the gear widget via an intent or notification, somehow, but I could not find yet) after the Android application has started, here started means that SAAgent service is up and bound to an Activity, being eligible to receive callbacks and send state messages to the rest of the application via broadcasts. Such as the number of active connections, or any data transmission between the gear socket and Android application can be done this way.
Note that if you don't have to transfer data between the gear widget and the Android application, you may just be OK with the notifications. The only requirement to send notifications to the Gear from Android applications seems to be that the Gear is paired with your phone and connected via Bluetooth. Then you can just send an intent as explained in more detail here in Section 6. All you need should be the permission:
com.samsung.wmanager.ENABLE_NOTIFICATION
and some metadata definition in your ApplicationManifest.xml file explained in the same section.
<meta-data
android:name="master_app_packagename"
android:value="com.example.gearMasterApp"/>
<meta-data
android:name="app_notification_maxbyte"
android:value="300 "/>
And here is the sample code for intent, in order to send notifications to the Gear:
public static final String ALERT_NOTIFICATION =
“com.samsung.accessory.intent.action.ALERT_NOTIFICATION_ITEM”;
public static final int NOTIFICATION_SOURCE_API_SECOND = 3;
Bitmap bitmapImg;
// Put data to Intent
Intent myIntent = new Intent(ALERT_NOTIFICATION);
myIntent.putExtra("NOTIFICATION_PACKAGE_NAME", “com.example.gearApp”);
myIntent.putExtra("NOTIFICATION_VERSION", NOTIFICATION_SOURCE_API_SECOND);
myIntent.putExtra("NOTIFICATION_TIME", System.currentTimeMillis(););
myIntent.putExtra("NOTIFICATION_MAIN_TEXT", “Title Text”);
myIntent.putExtra("NOTIFICATION_TEXT_MESSAGE", ”Body text);
byte [] byteArray = convertResizeBitmapToByte(bitmapImg);
myIntent.putExtra("NOTIFICATION_APP_ICON", byteArray);
myIntent.putExtra("NOTIFICATION_LAUNCH_INTENT", “com.example.gearMasterApp”);
myIntent.putExtra("NOTIFICATION_LAUNCH_TOACC_INTENT", “com.example.gearSideApp”);
sendBroadcast(myIntent);
public byte[] convertResizeBitmapToByte(Bitmap bitmap){
Bitmap scBitmap = Bitmap.createScaledBitmap(bitmap, 75, 75, false);
ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
scBitmap.compress(Bitmap.CompressFormat.PNG, 50, byteArrayStream);
return byteArrayStream.toByteArray();
}
Once the notification is read on the gear side, you can receive the intent action along with some optional parameters:
Intent Action :
"com.samsung.accessory.intent.action.UPDATE_NOTIFICATION_ITEM"
This could be another approach to check active communication with the Gear and your phone, but there is no guarantee that the notification will be read and my case did require to keep the Gear communication optional in order to allow the Android application continue it's tasks even though there is no active connection with the Gear.
About the original question, where I asked for a way to detect if the Gear is paired or not, I tried listing paired Bluetooth devices using getBondedDevices() method of Android's BluetoothAdapter but it shows that your Gear is paired even when your Gear is turned off, which was not enough for my needs and I did not find it logical. It's true though once your device is turned back on.
I'm happy with the above solution since it was enough for my needs, therefore I will accept my own answer.
I am looking for some advice regarding NFC data.
I have a device, lets say a printer or speaker. I want to put a NFC tag on this device. The data I want to put in NFC tag is DeviceName/MacAddress/Password.
Now the requirement is when ever user touches my tag with Android or Windows phone
My app should be launched.
If my app is not already installed it should take me to Play Store or Windows store
I shoul be able to get data from NFC tag in my application (DeviceName/MacAddress/Password)
As of now I could get it done in Android using 2 NDEF records
Custom MIME type record with my data (application/vnd.pakage.name )
Android Application record.
The issue is how can I launch app in Windows Phone?
As I understand with custom Mime application/vnd.pakage.name Windows application could not be launched. Pls. let me know if I am wrong.
Windows LaunchApp record should be the first record and if I make that as first record then in Android I don't get my data.
The Only soluction which looks probable is the NDEF records in following formats.
Custom URI with my data (myscheme://my.package.com?DeviceName/MacAddress/Password)
Android application record.
But using this format also I am not able to get data in Android. Pls. let me know if there is any better solution? How I can get data in Android?
Thanks
Your last proposal for a solution should work. Make sure your intent filter declares at least the scheme and the hostname. This article may be of interest, too: How to Create Cross-Platform LaunchApp NFC Tags.
I'd like to share information between my own app running on 2 different phones via a bluetooth intent.
Lets say i have some data on phone a, then i will tap synch and it will start the same app at phone b (if it's not already open) with a bundle containing that "data".
My app on phone b acts acordingly.
Is that possible?
I am not really sure if this is what you're looking for.
Intent i = new Intent(Intent.ACTION_SEND); i.setType("image/jpeg");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse(fileLocation));
startActivity(Intent.createChooser(i, "Send Image"));
This intent shows all available options for file send such as Email and Bluetooth. Choose Bluetooth and the device initiates bluetooth discovery.
Thanks!
From my understanding, it is not possible.
Use BluetoothSocket and BluetoothServerSocket instead
I recently saw this interesting video about NFC, and i know you are talking about bluetooth.
but watch this video http://www.youtube.com/watch?feature=player_detailpage&v=49L7z3rxz4Q#t=768s
Timestamp added, starts at: 12:48.
What they did is starting the app trough nfc but probably they send the data trough bluetooth. Its really user-friendly.
In this way you do not need to push the button sync but just bump eachother phones together!
I hope this helps you maybe further,
Daniel
I think you must make use of BluetoothServerSocket to accept incoming connections. Exchange data with server once connected. To get started check out this doc.
Start-up
You could find the source code in your SDK. Download samples from Android SDK manager. Select 'Samples for SDK' from the required SDK version.
Go to
<location of android-sdk>/samples/<version>/
Open 'Bluetooth Chat' application. It has almost everything you need.
Thanks!
By the way, don't forget to accept the answer!
I am developing an android app in which i want to send (name,email, cell # , address, company, name , picture) from one android phone to another . The problem is that how to send this data + picture . Please provide me some code .
see this link Bluetooth sharing , it shows how to share files between devices
I assume that you have experience of developing Bluetooth application in Android. Android Bluetooth API is not supporting OBEX directly, means I can not push any file directly to any device. Android Bluetooth API provide basic functionalities like discovery, connection and data transfer using streams (InputStream and OutputStream).
Transferring file using Bluetooth need lot of coding. We need to manage device discovery, connection, IO etc.
Now I found very simple way to send file using Bluetooth. Android has build-in Bluetooth application which allow us to send file across the devices. Build-in Bluetooth Application use SharedPerference to manage queue for Incoming and Outgoing files.
I find the way to use same technique. Android Bluetooth application use ContentProvider to manage communication between storage and user interface. so I found the way that we can use it's functionality
Here is the code, Following 6 line allow you to send file using bluetooth, you required only two things 1. URI of file which you want to send 2. DeviceAddress.
ContentValues values = new ContentValues();
values.put(BluetoothShare.URI, "content://" + uritoSend);
values.put(BluetoothShare.DESTINATION, deviceAddress);
values.put(BluetoothShare.DIRECTION, BluetoothShare.DIRECTION_OUTBOUND);
Long ts = System.currentTimeMillis();
values.put(BluetoothShare.TIMESTAMP, ts);
Description of above code.
Create object of ContentValue
put URI of file which you want to send
put DeviceAdddress, destination device address
put Direction, set outbound means you want to send the file.
time stamp which will display at Notification bar
put time stamp.
Note: Above code is useful only if we can have URI of file which we want to send. It is perfectly work for Images because we can get URI of images available in Gallery but If we want to send file from SDCard then it difficult because we can not get URI of file available in SDCard.