I have a question about the p2p functionality of Android OS (4.x and higher). I have a PC program that makes use of the Boost C++ library that can function as a server or as a client. Now i have a Android app that has a server using Java sockets. This program need a accesspoint to connect to each other.
I'm looking for a way to connect the Android server and the PC client program without a accesspoint. After looking around i found out that Android has a p2p library.
Android P2P
As a read it you can only connect two Android devices with each other, my question is if it is possible to use this library to connect the Android device to the PC using wifi p2p? Or if there is a other possiblity? All suggestions are welcome!
Roy, have a look at this: http://en.wikipedia.org/wiki/Wi-Fi_Direct
WiFi P2P is now called WiFi Direct, and it is indeed possible to connect two devices as long as one of the devices supports it. So Android device in P2P mode and a PC without any special configuraiton should work fine. However, the PC can (probably) only connect to one access point at a time, from its perspective the Android device is the access point, it would have to disconnect from its usual access point to connect to the Android device.
Also check out SoftAP.
Related
Is there any way to make a communication between a peripheral with android OS with RS232 support and a non android smart TV with RS232 support? Basically, I have to create an app which will be installed on the android based peripheral so that when it is connected to the TV using single RS232 cable, commands could be sent from peripheral to TV.
I have not been able to proceed because I am unable to find a process for that.
From what I understand, in stock Android unless you are doing something special in NDK (C code) with specific hardware there isn't a serial connector.
Android Things has a UART but that is specific to Android Things hardware.
If you are trying to get a off-the shelf phone/tablet to connect via serial, a USB-serial dongle would probably be the quickest route.
See: Communicating with serial USB device over Android
Since the microUSB connector will be occupied you can run adb over Wifi. See: Run/install/debug Android applications over Wi-Fi
I am working on an app that will act as a dashboard for an electronic card installed in cars and trucks.
I need the application to be able to receive data from this card, so I can display it in various ways on the app.
We chose Wifi for the communication method. To access the card, my app is able to connect to a Wifi network created by it.
I would like to receive JSON sent by the card every second.
I need help on where to start to make the two devices communicate, and what are the good practices on implementing this kind of communication.
The app basically act as a client, and the card as a server.
I found something about sockets, but it seemed to use two Android devices, a server and a client, so I'm kinda stuck here.
I use Android Studio 2.1.2 with the Android APIs ranging from 19 to latest.
One option is to broadcast with UDP the data within the local network. The moment the android device connects to the wifi network it will be in its local network. So the data can be received at the android end with a multicast receiver(check out http://jgroups.org/ ).
Refer example
It may also use the p2p sharing with TCP and bind the device with static IPs for communication. Create a simple socket receiver at the android end and a service at the device end. Depends on the way you choose it.
I'm coding a java app which consists 2 parts (android and desktop). There will be one desktop and multiple android devices.
I want to;
send data from desktop to android device which I choose,
send data from one of android devices to desktop app only.
I want to send data by using local area network. All devices will be connected same network.
It must work on different places. If I use socket programming (I guess I have to);
is it possible to find lan ip addresses all of android devices which is connected on network?
how can these android devices know the desktop's ip address? Because you know it changes network to network.
How about this:
On all devices, send pings to broadcast address.
Try to connect (TCP) to all clients that answered (not sure if every device will answer to broadcast ping). If connection is established, the other client is one of yours, running your application
Find out whether it's Desktop or Android by the messages itself.
I'm trying to create a TCP connection between my PC and Android smartphone to send text from the PC (Client) to the Android App (Server).
I found a tutorial which helped me with the code for the App which creates the server ( http://pastebin.com/z0xPSAvP ).
Now I'm struggling connecting my client with the server. The client is programmed with "AutoIt"
http://pastebin.com/tCW5bK9V
When I run the client the "could not connect to $socket" msg-box is displayed.
Could someone tell me what I'm doing wrong here?
Both devices are in the same Network (smartphone via WiFi and PC via LAN) and I checked for the smartphones IP in the smartphone settings.
First, try to access something like Google from your Android phone using its mobile browser. Maybe something still wrong with the network.
Then create a version of the server that could deliver simple HTTP response, visible from the Android mobile browser. Doing so with success eliminates firewalls and all client-related issues from the list of possible problems, making sure the server works and is accessible.
If it still does not work after you demonstrate connection between server and mobile browser, I would suggest to write the client in Java first using the this tutorial. You can try AutoIt and other more exotic approaches after you get anything working at all.
I need a tutorial on how to process data on android via wifi. F.e., I need to send some message to PC and receive some other message. How should I establish the connection? What should I do to be able to transfer data and how?
Sorry for the dummy question, but I can't find good manual. I'll be grateful for as detailed manual as possible, or for ome simple example on etablishing wifi connection and sending/receiving simple mesages.
You don't have to use any API for connect to wifi its only requires if you want to manually start your wifi in device,
Just make sure your device has a WiFi enable, and make a simple TCP/IP Socket application. With this you can communication with your system and device, And Use System's public IP to connect with your system.
Also don't forget to give permission Internet in your manifest file..
Here some nice links for Socket Programing in Android..
Simple connection example part II - TCP communication
Networking with Android
Simple communication using java.net.Socket
http://www.anddev.org/tcp_sockets-t276.html
http://www.anddev.org/socket_programming-t325-s30.html
EDIT:: Android WiFi examples,
Scan for Wireless Networks
Using WiFi API
SO Question Android: Is there any way to get notified when known wifi networks get in/out of range?