Send "something" to a Device that has my app installed? - android

when a certain condition is true, I need to send a message to a certain device that has my app installed.
How can I realize it? E.g. A klicks on the name B, B shall get an AlertDialog that A clicked on his name. I know that I will need something like a deviceID. But what else?

You don't need a device ID, you need a server that handles the communiation between the two devices.
In order for a device (A) to communicate directly to another device (B) without a server, A needs to know who B is and how to reach it.
You could do that either with an SMS and the only thing you need to know about B is its phone number, but I guess this is not what you want to hear.
The other options is through a TCP/IP network. A would need to know B's IP address, which is something almost unfeasible, unless both devices are connected to the same network, probably via WiFi, and even so, there's no direct way to know B's address.
The usual solution is that both devices connect to a server through the network, using a particular protocol. When A want's to send a message to B, it does it through the server, which forward the request to B (since B is also connected to the server). In order to identify the devices you can use any information bit you want (it can be a user name, such as in chat systems, it can be the device ID which is not very reliable...)

If the recipient device currently has your app running and is connected, then the app you would presumably maintain a connection to a server or implement polling by the app.
For a non-running recipient app, you'll either have to utilize a standard messaging protocol (SMS, email, etc.). Or you will have to implement a background service in your app that periodically wakes up and polls a server that maintains the messages. This is how Twitter, Facebook, etc. work.
Just to be clear, opening or maintaining direct network connections between multiple devices not on the same local network is not really doable.

You need to poll the app you want to send something to.

Related

Android WiFi (sending and receiving data without specifying recipient)

I want to make an application is via WiFi would send and receive data without sending them to a specific recipient. I explained to the example of a simple chat: The user sends a message via WiFi, but without a specific destination. As a result, his report available to all users nearby. Similarly other users can receive and send messages. I also want to realize the function of repeater, where each user's device not only receives a message from the other devices, and retransmits them to others allowing increase the coverage area of WiFi connection.
But at the moment it is not possible to send data without a specific recipient. The same WiFi Direct necessarily require pairing before data transfer. Can not specify that the recipient is unknown.
Recently I heard the news about the technology WiFi Aware, which involves greater interaction between WiFI devices. Please reply, WiFi Aware allows to do what I described above? Namely - the transfer of data and we will without a clear indication of the recipient and the need to do additional work (eg preliminary pairing between devices).
If WiFi Aware allows to do what I described - when it is expected to release its API? In particular, for Android devices. And if not - you can tell me how to implement what I need? And in general - it is technically possible?
Thank you for your time and sorry for my bad English.
You should try to look into nsd via wifi-direct. This Network Service discovery via Wifi-Direct. What this helps you to achieve is broadcast information to all listening devices.
On the device which wants to convey the information you addLocalService and on the other devices you should discoverServices. In the ServiceInfo object you can the pass the information you want to communicate to the other devices who are listening for services. Please try to study from the link attached above.
I am not very sure about how repeater will work with this.

android bluetooth implementation basics

can anyone in simple words explain me the need of UUID in android bluetooth example. I have read some articles about it but it is still not getting clear the exact need of UUID.
And now let me explain you the scenario of what I want to develop:
I want to develop an android application to transfer data for example a "FILE with .xyz extension"
from my phone to the other phone over bluetooth. IT IS NOT AT ALL NECESSARY THAT THE RECEIVING PHONE SHOULD ALSO HAVE THE APPLICATION THAT I AM USING. I just want to transfer data from my application to other phone and thats it. I don't care what the receiver does with the data.
I just want to connect to a device within range and transfer that file using my application
Now how should I do this? Where does the the role of UUID come here? I have read that UUID is for my application , and both the server and the receiver should be aware of this UUID to form a connection . But what if the receiver does not have the my application? It will surely not know my Applications UUID ? then how the data transfer will be possible? I simply want to use Bluetooth without concerning a specific application.
In here, what my application should be doing? Should it be creating a server socket / a client socket or what? and Why.
An explanation in simple words is appreciated(some articles if possible). I dont want regular answers having BluetoothChat suggestions. If you don't understand the question please let me know, I will try to be more specific and elaborate it for you.
The basic goal of this question is to clarify the use of UUID and transfer data between two DEVICES (and not an application) using bluetooth from an application running on one android phone.
Even with bluetooth you can create a client-server application.. there is a BluetoothSocket
read here http://developer.android.com/reference/android/bluetooth/BluetoothSocket.html
Now, lets say you have two devices:
device A
device B
and assume that device A sending data to device B, You didn't say if device B is also sending data to device A, so I'll just describe the first scenario when A send to B.
So in that case, since all the data is stored in device A and you want to send it to device B, it will be more reasonable to create device A as a BluetoothServer and device B as BluetoothClient which listening to the server.
But.. If you want both of devices will exchange data.. you can make one of them as a server
and for each one of them create 2 threads:
Thread that sends data
thread that listening to data
so both of them can exchange data..
Another thing.. if you ever programmed a regular client server you noticed the accept() method which is blocking until there is a client which connected to server.. the same is with Bluetooth client-server application.
Summarize:
One device will act as a server - so you'll need to write a server project and install
it on the first device
Second device will act as a client - so you'll need to write a client project and
install it on the second device
Don't forget to add the bluetooth permission in the manifest file for both
projects.
Both of the projects need the same UUID as you mentioned in your question.
in simple words both of the sides need the UUID so they each know with who they're
communicate
I think it's more like a port in a regular client-server..
I read somewhere that is used for RFC communication.. as you probably know there are
some protocols for Bluetooth like RFC,SDP and etc..
EDIT:
In most of the phones there is a pairing process when you want to send data through
bluethooth. so if you don't want to use the client-server version, I think you can
do this:
Your application will search for devices to connect to. (pairing process)
After pairing you are connected to the other device and just send the data
EDIT 2:
You want to send data from A to B right?
I'll explain more clearly..
You're right when you said the client should know who is the server and need insert the port and
the IP of the server this is correct and works in this way.
Now, look..
The server listen to connection from clients, when a connection established the communication
begins.
Client ask for data
The server processing the client request and send him the related data
So any data like: Files, Databases should be stored on the server side..
Now in your case, the files you want to send are located in device A and not in device B,
So if device A is the server he will listen for connections.. when device B connects to the server
(device A) the communication begins.. Device B can request for files from Device A..
Also, since device A is the server, he can even broadcast a message.. means send the same message
for all clients which are connected to him.
But what you're want to do is to send file even if device b didn't ask for it, right?
I don't understand if you want that device B will also send file to device A, so lets divide it
into scenarios:
just device A send to B:
In this case, since the files are located in device A, means device A have the data,
device A is the server and device B is the client.
So when connection established you can send from A to B.
Both devices exchange data:
In this case, both devices should listen to each other, but just one of the should act
as a server and the other as a client. means that you need to install the serverApp on
one of them and the clientApp on the other.
But each of them can send and listen to other. so for each of the you need to create
thread that handle with the sending data and another thread that handles the receiving data
UUID is the Universal Unique Identifier. When you want to connect to any of the service that bluetooth is exposing then you should have the UUID to tell to the bluetooth software module that it has to inititae connection to this particular service. In your case in order to send file from DevA to DevB it has to use File Transfer Profile and there is specific uuid which is associated with this and this is defined by Bluetooth SIG which is the authority which qualifies bluetooth products and works on the technology. This is known by all the devices which uses bluetooth.
Tu cut the story in short when DevB receives the incoming connection request with the uuid which is unique it comes to know to which particular service of DevB the device is trying to connect to and it connects to that service. Hence if you want to send file from DevA to DevB then you need not have the same application at DevB. But you need to make sure that you use the UUID which is specified for File Transfer profile by Bluetooth SIG.
Regards,
Shripathi

Simplest way to pass information between the same application installed on different phones

As the topic name suggests, what I am looking for is to add my android app the option to send data to a different phone running the same application so the receiving phone will process it accordingly.
The obvious option for me was to use app engine and use push notification with the phone number acting as the identifier.
Does a simpler solution exist?
Thanks ahead :)
The best and most robust solution is to have something like your messaging clients, in which Device A sends data to the server, which pushes it to Device B. Device B sends a reply to the server, which pushes it to Device A.
This process has the advantage of retrying the sending without requiring your users to stay connected, as may be required if Device B is offline when A sends a message.
A less foolproof solution is to have a server work as a middle man, and get each device's IP Address, and then open up a direct socket between them. In this solution, you'll lose any data that doesn't make it through.
If the devices are on the same network or in Bluetooth range, you could try Bluetooth or WiFi direct.

best way to get multiple Android devices on one WiFi network to share info

I'm trying to figure out what the solution is to having multiple android devices on one network share data.
Assuming all of them are running the same app, and a user "registers", I'd like to figure out (without any user input) what other devices on the network are available to be talked to and then to send them this registration data, so that when the user goes to the next device, their info is already there.
I'm able to ping the 255 connected devices in the x.x.x.0-255 range to see which respond, but am not clear on how I can write an app resident server (using the term loosely) that I could then send the data to.
I can't be the first person to need to solve this problem, but am unable to find anything useful on this front.
One caveat is that this is for devices that have no 3G (or other means) of getting to the internet, and the wifi network they're on won't have access to the internet either, so the solution has to be 100% internal network and can't include any additional devices (like a box running apache that all the device can use as a server).
TIA
but am not clear on how I can write an app resident server (using the term loosely) that I could then send the data to.
Create a Service that has code that opens a ServerSocket and listens on incoming requests, such as an HTTP server.
On the whole, this is dangerous, but for constrained circumstances -- such as your "100% internal network" -- it should be safe.

How to connect web service to android

I want to connect a web service to android phone i.e. a request is to be made from web service to android phone. All i can find is article about android to web service but in it (as far as i know..may be wrong) a request is sent to server from android but i want vice versa.
Most carriers give you an IP address inside their networks, so you can't access the devices through any standard method. If the device is online via WiFi then you may have a chance (depending on your ISP and router policies, and given the case you have a web server or a permanent socket listening for requests). Nevertheless, it's still a very bad idea.
I would recommend you to use a different approach: make your android device call a Web Service that recognizes it (either via IMEI, IMSI, both, or a user parameter, depending on your app) and see if it has some "news" for him. If it does, then it should take an action depending on the received data. If you're familiar to Java, it's roughly like the MDB (EJB) idea.

Categories

Resources