Can I connect 2 android devices via WiFi Direct using QR Codes - android

I want to make a data sharing app which uses WiFi-Direct where there's one Activity for the sender device where a QR Code would be displayed containing all the info about the device for other peers to connect to this one (like MAC Address , which device is the group owner, etc.)
The receiver devices would then scan the QR code and connect to the device after which the Sender would open the explorer to choose the data to send and then send it.
The Problem:
I am not able to find any way to just connect the devices directly using the give data instead of first scanning and then connecting.
Can anyone help me for this?

I think this tutorial will help you..
https://dzone.com/articles/android-device-matching-with-socket-programming
QRGEncoder qrgEncoder = new QRGEncoder(preSharedKey, null, QRGContents.Type.TEXT, smallerDimension);
ServerSocket server = new ServerSocket(6678);
Socket socket = server.accept();

Related

pass string between two wifi direct connected user in android using wifi direct?

i have recently implement wifi direct into my project,my aim is pass string value between two wifidirect connected devices when some of my app condition satisfies.right now i have listed all peers and also made connection between the selected peer.now i need to pass String values to the connected devices..how can i pass string between two connected device. i have checked the [Wifi Direct chat][1]
[1]: https://github.com/life0fun/wifi-direct-chat project but it is very complicated.so any one suggest me any idea how can i pass the String values between two connected wifi device.(If code is needed i will post the code here)
you can use socket to connect between two peers in the same network.
for instance create a server socket on one of the peers on any port and then from the client side connect to that port on the other user . then you can use this socket connection to send strings, file whatever you want.
for starters i would recommend you employ the server socket on the group owner so it will be easier on your client side to get the ip of the peer(i.e group owner) using the groupOwnerAddress field provided by the api
refer to this -> http://www.oracle.com/technetwork/java/socket-140484.html
You can get text chat code from your installed SDK sample just goto
\sdk\samples\android-22\legacy\WiFiDirectServiceDiscovery
import that code into your eclipse, this is great sample in this text chating has been done nicely and code is too easy to understand.
I hope it will help you.

connect to external bluetooth device and start receiving data

want to connect to device and start receiving data from the external device
now able to list devices and pair to that .....now wish to connet to it and start receiving data from it
Is there any way because i dont exactly know wat kind of data it is sending
means in which formate etc ...
that is Bluetooth device is continuously sends data to app so the app should continuously receive data
use listenUsingRfcommWithServiceRecord instead of
this code in service
Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class} );
btSocket = (BluetoothSocket) m.invoke(device, 1);
Answers to your questions are as follows
Is there any way because i dont exactly know wat kind of data it is
sending means in which formate etc ...
Yes there are 2 ways you can do it
1) use intent
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("image/jpeg");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("/sdcard/file.jpg")); startActivity(Intent.createChooser(i, "Send Image"));
code sample to send data using inbuild bluetooth
2) Use open source code which use socket connection and bluetooth manager to do it via code. following is the link of open source code
blueterm opensource code
Data sent over bluetooth is in form of byte array which you have to parse and convert it to string or any form that you want to use in your code.
There are two things in bluetooth
1) pairing.
2) global connection.
If you use first method of bluetooth (via intent) device will be paired but connection will not be continuous. while sending data connection is established else connection is not there. But if you are using blueterm open source code you pairing and connection is constant and will not break untill user wants.
So its upto you which kind of bluetooth functionality you want.
Let me know if my answer solves your problem

How do i send information via a setup bluetooth connection

So im working around with bluetooth and trying to figure out how to send two strings via a bluetooth connection. From one android device to another.
I found this guide http://developer.android.com/guide/topics/connectivity/bluetooth.html
but it talks alot about setting up the connection. So i went straight down to the chapter about Managing a Connection. The reason i do this is that in the apps i create i plan to setup the bluetooth connection before opening the apps (via the phones usual bluetooth setup) and then open the apps and send when it is necessary.
So my question is how do i find the bluetooth socket that should be setup? Since that should be what im searching for to create the sending and recieving threads?
Hope this is enough information, else tell what more you need and ill try and answer to the best of my ability.
Best Regards Drakthal
The usual bluetooth setup only pairs between devices, it doesn't create a data connection between them (And even if it would, you wouldn't be able to access this Socket object because it's not created in your process).
After Bluetooth is turned on, you can call BluetoothAdapter.getBondedDevices() to get a set of the paired devices. You can then iterate over them, and initiate a connection to the one you want. You can't avoid the connection creation :( If you want a simplified example, you can look here (An answer I posted a while ago, regarding the whole pairing/connecting/sending/receiving subject with bluetooth).
Once you acquired an open connection, sending the 2 string is easy.
String s1 = "A", s2 = "B";
byte[] buf1 = s1.getBytes(), buf2 = s2.getBytes();
OutputStream os = connection.getOutputStream();
os.write(buf1);
os.write(buf2);
os.flush();
connection.close();

How to transfer data from one device to another using wifi network in android 2.2

I need to trnasfer data from one android device to another device over wifi network?
If one device is willing to perform access-point like functionality as part of a portable hotspot, and you select that as a wirelss network on the other, you may achieve a network connection between the two that can be used for custom traffic. Though there are ways the hotspot could be implemented where that would not work. Also of concern, the "client" device will now be sending all of its network traffic through the hotspot device, including not just foreground apps but anything it decides to do in the background.
First you need to know to which device you want to transfer the data over network like to mobile device to pc. Suppose you are trying to send data you need will a continuous socket connection using a thread ... the back end device should accept the socket connection and accept the stream....
consider the frist device as client which will write the stream
Runnable action = new Runnable() {
public void run() {
//create your connection
while (true){
//write your stream here
}
}
};
new Thread(action).start();
and server side the device will open the stream and read it continuously
now in the write your stream code use link the and integrate like the example
Click here!

Reading the values from OBD II Bluetooth adapter in the android application

Can anyone give me an idea on how to read the values from the OBD II Bluetooth adapter in an android application.
I want to start with scanning for the bluetooth devices from my android application, then after bluetooth device is found, how would I interact with it and get the values from it?
You should start by reading this http://developer.android.com/guide/topics/wireless/bluetooth.html
it contains step by step procedure .
add required permissions,
make a bt adapter,
then find paired/unpaired devices
I used the BluetoothChat Application and was able to get some basic communications, I am not moving into data logging. You can use this application to have a sort of instant messenger conversation with your ECM.
What particular dongle are you using?
Do you know what protocols are in use within your vehicle?
Download the BluetoothChat sample application -
They will have already handled the intricacies of the connection for you, you will have to change the UUID in order to connect with your device - 00001101-0000-1000-8000-00805F9B34FB
Read up on your particular dongle, some require the return character to be sentat the end of every command "\r"
This should get you started!
Once you have made the Bluetooth connection using the android bluetooth api, use the transport to send and receive data via the Bluetooth channel.
This is new developer resource document:
https://developer.android.com/guide/topics/connectivity/bluetooth.html
The general workflow of the application functionality should go like this:
1) connect to the OBDII adapter through Bluetooth;
2) initialize OBDII adapter with AT commands;
3) continuously get data from the vehicle through issuing the corresponding PID codes.
This article also may be helpful.
http://blog.lemberg.co.uk/how-guide-obdii-reader-app-development

Categories

Resources