Android Wifi Direct: Avoiding user acceptance when connecting to a known peer - android

While connecting to a peer using WiFi Direct, user's permission is required. I know that connection can't be made without user never giving the permission and there's a feature request for this kind of functionality:
https://code.google.com/p/android/issues/detail?id=30880
But I don't need this feature, asking for permission on the first connection is OK (also, more secure). Is there any method such that the permission is asked for the first time only? And when trying to connect to same peer later, the permission is not required.

From the P2P specification we can find something called "persistent P2P group" which is intended to re-establish a group without user-intervention.
In a persitent P2P group the Group Owner stores the credentials of the group so that the group can be re-established in the future by the request of any group member without the need of user intervention.
Such a group can be formed by specifying persistent while connecting using command line (see the P2P of wpa_supplicant and search for p2p_connect command https://android.googlesource.com/platform/external/wpa_supplicant_8/+/ics-plus-aosp/wpa_supplicant/README-P2P). But I don't know if the option is available with the current devices.
Edit:
See the answer to the question Can I change the group owner in a persistent group in Wi-Fi Direct?
Since I worked with Wi-Fi Direct on Ubuntu, I used wpa_cli (which comes along with wpa_supplicant) to create a persistent group as specified in the p2p_readme file.

The closest thing to have Wi-Fi Direct features without prompt I've managed is to use Service Discovery combined with legacy mode, i.e. when the connection is supposed to happen, you don't use WifiP2pManager.connect() but WifiManager.enableNetwork() instead.
I'm the author of a very simple P2P stack which automates all the magic, you can check out an example on https://github.com/croconaut/wifon-mini to see how well/bad it works (plus some documentation).

Unfortunately, not at this time. Perhaps in the future, or if you write your own ROM.

I am using two HTC One V's as well as an HTC One X+. I've been running the WifiDirectDemo given by Android. Apart from switching Wifi Direct on, no other setup is required. I simply press a search button in the application and peers are listed.
I did at first think I needed another devices permission as you've described, needing to reenable it every time I installed the application on my devices. But this was before I noticed the search button in the application, and realised this was not required.
Could you have made the same mistake as me?

Its possible through the reflection method.

Related

How to find a Group owner device automatically

I am developing an android application , in which i need to connect multiple devices with each other using WiFi Direct. i am done with multiple connections as i am aware of connecting devices through one group owner device as if all client devices sends a request to one specific device.But i am doing it manually because if all client devices clicks on a name of one specific device then it is OK with multiple connections.But now i need to do it programmatically so that one device automatically becomes group owner and all other devices should automatically send connection request to that specific device.Please help me with this problem.I am stuck at this point from last many days.Thanks in advance for your help.
What is the exact logic/problem there ?
Does it has to be fully automated ? or can the group owner selection be manual ?
In case all devices start the connections same time, then you must really do either manual selection, or have the devices somehow negotiate how they are selecting the group owner. Selection case you be really easy:
Group owner uses createGroup to create the group for connection
Group owner adds local service, and starts Peers Discovery and keeps it running (generally my research has shown that if there is no active connection, or peer discovery, the device local service is invisible for other dervices)
Clients, simply do Peer & Service discovery and do the connections
if there is possibility that the devices appear is same place different times, then of course the logic for fully automatic would be simple.
First all devices advertise & search for devices same time
with The first connection one device is set as Group owner and the other gets to be client
Both devices stop Peer & service discoveries
The Client device stops advertising the service, thus making the Group owner only visible service for any devices appearing into the vicinity, thus they would be connecting to it.
Anyways, I would have small example project which might help you at: Thali/WDConApp, anyways, with WiFi-Direct you would need to manually allow connections, You would try doing the pairing as I explained in my Blog, though I have to admit that since tuesday this week, I'm not so sure if it really works that way. I would need to do some additional tests (when I have time) to verify that I would actually know how it behaves.
Then, if you don't want to have the manual user acceptance of the dialogs, I would have two options for you. You could use unsecured Bluetooth connection as is used in Thali/BtConApp, or you could use WiFi Direct Access points for connectivity.
Note that Using the access point connectivity, will cut off any other WiFi connections. I do have example for it as well, and I actually uploaded it while writing this reply and you can find it from Thali/WAPConApp. Note that its just my first test version, and I'll likely do loads more work on improving it.

connect to android devices using wifi direct without prompt

i am trying to connect two android devices using WIFI direct and i was successful. But the problem is the second device has to accept the a connection prompt after the other device initiates the connection. It is undesirable for what i am trying to achieve. I saw a few post here in stack overflow itself saying that currently its not possible. But came across an app called SUPERBEAM which user WIFI direct but without the prompt. A search in google gave me the following link from xda forum which says
SuperBeam creates an access point using Android's WiFi direct API's.
This essentially works like hotspot mode in old devices, but it is
guaranteed to work on newer devices like Nexus 7. Moreover, this mode
allows older devices to connect and receive files without having to
support WiFi direct's peer-to-peer connections and, more importantly, it
gets rid of the annoying "accept connection" prompt.
But no where i found information on how to implement this. Can anybody help me. Here is the link
http://forum.xda-developers.com/showthread.php?t=2177133
You could indeed simply use the createGroup function from the API to create a group, which also makes the access point. The first problem here is that the access point name & password are set automatically, and you can not change them.
So, you do need to pass the info to the connecting party, and for this, I would suggest using the local service advertising, and using the instance name there.
Did make simple test app for this and you can find it from Github under DrJukka/MyWifiMesh, also some discussions on the topic can be found from my blog
This can be achieve using Xposed framework. You need add the code and install the App. The phone needs to be rooted in order for it to work. I have tested it on multiple Samsung phones and it works.
Check this answer for details: How to auto-accept Wi-Fi Direct connection requests in Android

Automatically accept wifi direct connections through root

In Android SDK the Wireless P2P (WiFi Direct) API is provided.
I am developing an application that would require for the app to connect to other devices on the fly that have the same application and share information among them (text data). In order to do so I require that the devices could connect automatically between each other. I was wondering if there is a way to do it if you have root permissions on your device. And another thing is if it is possible to work around by creating some kind of automate response of clicking the OK button on the dialog of the user request.
Best regards.
It can be done with the help of some classloader patching framework, like Xposed or Substrate. See my answer here for detailes.

Manually pairing Bluetooth Decives in Android?

I was reading this
http://developer.android.com/guide/topics/wireless/bluetooth.html#QueryingPairedDevices
which is allot of help on how to pair,connect to a bluetooth device.
I have a situation where I have several BT devices that are in Non-Discover mode always. I know the MAC and the PIN of these devices. IS there a way in Android Dev to manually add devices to the PAIRED list so i can just use the connect as a client.
I understand this maual is written allot for V3. i think i will need to do this on 2.0 ; 2.1- has anybody done this before?
Basically these devices I want to connect to are power saving modules I used pre built BT modules to monitor daylight, another one humidity, etc.. every 3hrs or when interrupted and runs of a single battery for months. So turning off divcory on server saves immense power and prevents other people trying to connect and waste battery.
Not sure what you mean by "manually": Do you mean "manually" as in GUI/user interaction, or "manually" as "I do it in my own application code"?
Some suggestions though:
If you can make your BT devices discoverable at all, you could do it this way:
Make your BT device discoverable
Let Android search for and find the device and then initiate a connection
Android will ask for the PIN for pairing with the device; enter the PIN.
Once pairing was successful, Android stores the pairing information for future use, so that you can
Make your BT device invisible again.
From then on your app should be able to connect to the BT device at any time without further pairing operations.
If the said is not an option for you, maybe you want to go another way:
In current Android versions there are different API routines implemented which are neither documented nor exposed in the normal SDK. A hack kind of solution may be to use some of these "hidden" ("#hide"...) APIs, either via reflection or via modification of your SDK installation.
But be aware that this is always a hack and it may work on a specific device with a specific version of Android and is likely to break your app on another device and/or any other Android version.
Having said that, here comes some reference:
Example of how to access "hidden" bluetooth API.
Then, have a look at the source code for android.bluetooth.BluetoothDevice, e.g. here.
In there, public boolean createBond(){...} may do what you want.

Android Wifi direct multiple connection ad-hoc

I try to create an ad-hoc network between many Android devices, but I can't find documentation to do that.
I thought Wifi direct could work for what I want, but is it possible to have multiple connection on one device ? I saw that we could do a device acting like an access point and communicate with many devices, but can we communicate from one client device to two access point devices ?
I have for example 3 devices: A -> B -> C
The "A" device need to communicate with "C" device but he's too far away, so I want to have ad-hoc wifi direct connection between A&B and ad-hoc wifi direct connection between B&C, so A can communicate with C. It should also work with more than 3 devices.
Thanks !
Here is the link to the Wifi Direct Demo http://developer.android.com/resources/samples/WiFiDirectDemo/index.html
I have been working on establishing ad hoc communication over Android phones for a month. I am trying to create an app that could work without having 3G or access point. Main idea is to let the clients to be able transfer voice or data in a close range.
There are some guys implemented a basic system regarding almost the same topic. It basically works with Wi-Fi access point. So you need an access point in order to establish the connection. Although this is not what I am looking for, it might be helpful for others. You might need to contact them for more details.
https://sites.google.com/site/androidwalkietalkie/home
Android does not have support for ad-hoc WiFi at this time -- sorry!
Update (2019): Android has supported WiFi Direct for a while, and this answer has not been updated.
Your scenario would work. A would be able to connect with C as long as B (the group owner) is within range of both A and C.
See Android's developer documentation for more info:
https://developer.android.com/guide/topics/connectivity/wifip2p
At this time only Galaxy S 2 support Wi-Fi Direct
The wifi direct supports concurrent hosting and client capabilities on single interface. Which means, the device will act as an AP, allowing other devices to connect to it as clients, And also connect to another AP as a client. And can share internet connection by driving the internet traffic between the interfaces.
However, current implementations of wifi direct on android are specific to the phone and not part of andorid sdk. So there is not much clarity if they support concurrency. This capability is not limited by hardware.
Ad hoc wifi is disabled in Android. You need to ask Google why they have chosen to do so. If you have access to a device that allow you to install custom Android images, you will be able to patch Android to support it. Or you can root your device and reenable ad hoc Wifi, there are plenty of solutions on the web on how to enable ad hoc on rooted Android devices. This is a software issue, the hardware on every Android device that I know of has support for ad hoc Wifi.
The Serval Project, based in part on WiFi Tether, is the only place I've found this functionality. It's still alpha phase, but seems to be the forerunner in the field. The wiki is much more useful than the main project page linked above, with installation instructions and a bit of documentation.
Serval may or may not be right for your needs, but I felt it should be pointed out that ad-hoc networking is not impossible on Android. It might be better to wait until Google gets around to implementing it as standard API, though (if you believe they ever will :) ).
Well You might be interested in looking at AllJoyn. It is qualcoms SDK for android OS which includes wi-fi peer-to-peer implementations by creating adhoc connections. This is same as Wi-Fi Direct.

Categories

Resources