WiFi P2P network in Android Things
I would like to create a P2P WiFi network using Android Things (5.1) and a couple of Raspberry Pi 3 or alternatively using Bluetooth. I followed the guide in the Android Developer section https://developer.android.com/guide/topics/connectivity/wifip2p.html, so my MainActivity looks like:
private class MainActtivity {
private WifiP2pManager mManager;
....
@Override
public void onCreate(Bundle savedInstances) {
mManager = (WifiP2pManager)
getSystemService(Context.WIFI_P2P_SERVICE);
....
}
}
However when I try to run the app, with WiFI enabled, the SystemServiceRegistry shows a message stating
No service published for: wifip2pand the WifiP2pManager is not retrieved.
How can I solve this issue? Does anybody know if it is possible to create a WiFi P2P network using WiFi Direct and Android Things?
See also questions close to this topic
-
How to retrieve Bluetooth Core Specification in C#
As the title says. I'm using C# to develop a WinRT (Windows Runtime) application. As part of my program, some of the commands I need to send and receive are over the size that is allowed in Bluetooth Core Spec version 4.0 and 4.1. (>20 bytes)
As such, I want to lock certain options away from the user as attempting to send a larger value will break the connection and requires a power-reset. Is there any way to retrieve the current Bluetooth Core Specification of the connected device? Or, finding out the negotiated MTU size the devices have decided on?
-
iOS11 - "Turn on Bluetooth" prompt not working
I am using bluetooth in my app to work with iBeacons (Location Services)
Since iOS11, and the new functionality brought in Control Center, my bluetooth prompts don't show when turning bluetooth off via
Control Center
.But when I turn bluetooth off in the
Settings App
, the prompt does appear.I'm setting
CBCentralManagerOptionShowPowerAlertKey
to beYES
.Here is the code where I'm initialising the
CBCentralManager
:_bluetoothManager =[[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_main_queue() options:@{CBCentralManagerOptionShowPowerAlertKey: @(YES)}];
When getting the bluetooth state from
centralManagerDidUpdateState:(CBCentralManager *)central
, I'm getting the same OFF state when turning bluetooth off from both theSettings App
andControl Center.
But the prompt only appears when turning off viaSettings
.How can I get the "Turn on Bluetooth" prompt to work when turning Bluetooth off via Control Center?
The only workaround that I can think of is to set
CBCentralManagerOptionShowPowerAlertKey
to beNO
and then create a custom dialog to open theSettings App
. It's not possible to open direct to the bluetooth settings page on iOS 11. -
Bluetooth controlller kill switch
My 3yr old just got a razor force drifter and it has a little more power than he is use to. So I’m waiting to wire up a killswitch. My first thought was a rpi zero w as I have a few laying around but is reallly over kill for just a kill switch. So started lookin going into a andruinl uno, relay board and hm10(since it uses ble and will function with the iPhone). Then I got to thinking thatif I did use a rpi I could report back speed, battery life, gps and a lot of other stuff I don’t kno need but as a tinkerer well why not. So my question is how woulld you go about this? I’m a computer programmer by trade so coding a interface for iOS won’t be a issues as for schematics what makes sense to you. If I do this I will document the entire thingthing and provide step by step what I did slot with providing source code. My only concern is if I use something like the pi zero w what kind of Bluetooth range does it have? Would I be better ff using rpi 3 or adding a long range antenna? Any suggestions greatly appreciated!
-
Streaming camera between two devices over wifi
I am trying to make a small application that allows to broadcast the camera of a phone (camera streaming) to another phone using wifi and a server/client architecture but I have a problem concerning either the sending of the images captured by the server or the part of reception by the client the server-side code
@Override public void run() {// Ce que fait le thread (ServerSocketThread) if(s !=null){ String clientIp = s.getInetAddress().toString().replace("/", "");//récuper l'@IP et le port du client int clientPort = s.getPort(); //en utlisant l'objet socket s try { s.setKeepAlive(true); os = s.getOutputStream();//récuperer le flux output du socket while(true){ DataOutputStream dos = new DataOutputStream(os);//Cet objet permet d'ecrire les // données primitives (int ,string....) // sur le flux output dos.writeInt(4); dos.writeUTF("#@@#");//ecrire la taille du buffer de bit (mFrameBuffer) entre les caractere #@@# et -@@- // pour que le client peut le distinguer et l'utiliser pour l'initialisation dos.writeInt(mActivityInstance.mPreview.mFrameBuffer.size()); //dos.writeUTF("-@@-"); dos.flush(); //envoie du flux vers le client System.out.println(mActivityInstance.mPreview.mFrameBuffer.size()); dos.write(mActivityInstance.mPreview.mFrameBuffer.toByteArray()); //Ecrire le buffer (mFrameBuffer) qui contient les données du frames et l'envoyer dos.flush(); Thread.sleep(1000/15);//faire un pause entre chaque envoie // pour garantir latency } } catch (Exception e) { e.printStackTrace(); try { if (os!= null) os.close(); } catch (Exception e2) { e.printStackTrace(); } } }
the client-side code
@Override public void run() { try { InputStream inStream = null; try { inStream = mSocket.getInputStream(); } catch (Exception e) { e.printStackTrace(); } DataInputStream is = new DataInputStream(inStream); while (mRunFlag) { try { int token = is.readInt();//On lit le premier int de flux input if (token == 4) { //Si il egale à 4 alors la taille du frame se trouve apres le carectere "#@@#" if (is.readUTF().equals("#@@#")) { int imgLength = is.readInt();// on lit la taille du frame byte[] buffer = new byte[imgLength];// on reserve un buffer de byte de imgLength int len = 0; while (len < imgLength) { len += is.read(buffer, len, imgLength - len);// on remplit le buffer à partir de flux input (is) } Message m = mHandler.obtainMessage(); m.obj = BitmapFactory.decodeByteArray(buffer, 0, buffer.length,bitmap_options);//On crée une image Bitmap //et l'envoyer à l'activitie pour l'afficher if (m.obj != null) { mHandler.sendMessage(m); } else { System.out.println("Decode Failed"); } } }else{ Log.d(TAG,"Skip Dirty bytes"+Integer.toString(token)); } } catch (Exception e) { e.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } }
`
and the handler who provides the communication so he transmits the recovered image to display it at the client level `class MyHandler extends Handler { private final WeakReference mActivity;
public MyHandler(ClientActivity activity) { mActivity = new WeakReference<ClientActivity>(activity); } @Override public void handleMessage(Message msg) { ClientActivity activity = mActivity.get(); if (activity != null) { try { activity.mLastFrame = (Bitmap) msg.obj; } catch (Exception e) { e.printStackTrace(); } super.handleMessage(msg); } } }
any help please
-
Android Wifi getScanResult() return empty list
Firstable sorry for my english level.
I started android devloppelement last week. I have already check some posts but it wasn't clear or it tell me about problems on specific phones.
I try some basic, i'd like to scan wifi around and display them but when I use WifiManager.getScanResult() I get an empty list.I have already asked permission in the Manifest and I try to use Run-time but debugger never goes in (I read about "normal permission" so I think it's normal :D but on the other posts they use it)
Can you help me ?
here is my code:
Main :@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); listeViewWifi = (ListView) findViewById(R.id.listViewWifi); wifiManager = (WifiManager) this.getApplicationContext().getSystemService(Context.WIFI_SERVICE); listeWifiItem = new ArrayList<WifiItem>(); wifiAdapter = new WifiAdapter(this, listeWifiItem); listeViewWifi.setAdapter(wifiAdapter); broadcastReceiver = new WifiBroadcastReceiver(); registerReceiver(broadcastReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)); boutonRechercher = (Button) findViewById(R.id.buttonRefresh); boutonRechercher.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (wifiManager != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && (checkSelfPermission(Manifest.permission.CHANGE_WIFI_STATE) != PackageManager.PERMISSION_GRANTED || checkSelfPermission(Manifest.permission.ACCESS_WIFI_STATE) != PackageManager.PERMISSION_GRANTED)) { requestPermissions(new String[]{Manifest.permission.ACCESS_WIFI_STATE, Manifest.permission.CHANGE_WIFI_STATE}, WIFI_PERMISSION); } wifiManager.setWifiEnabled(true); wifiManager.startScan(); } } }); } @Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { if (requestCode == WIFI_PERMISSION && grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED) { wifiManager.setWifiEnabled(true); wifiManager.startScan(); } else { Toast.makeText(MainActivity.this, "Allow Permissions", Toast.LENGTH_LONG).show(); } }
Receiver :
public class WifiBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { WifiManager wifiManager = ((MainActivity) context).getCurrentWifiManager(); WifiAdapter wifiAdapter = ((MainActivity) context).getWifiAdapter(); List<WifiItem> listeWifiItem = ((MainActivity) context).getListeWifiItem(); if (wifiManager != null) { List<ScanResult> listeScan = wifiManager.getScanResults(); //empty listeWifiItem.clear(); for (ScanResult scanResult : listeScan) { WifiItem item = new WifiItem(); item.setAdresseMac(scanResult.BSSID); item.setAPName(scanResult.SSID); item.setForceSignal(scanResult.level); Log.d("FormationWifi", scanResult.SSID + " LEVEL " + scanResult.level); listeWifiItem.add(item); } wifiAdapter.notifyDataSetChanged(); } } }
Ty
-
On Oreo (8.1.0) not getting the correct Wifi SSID. It's showing <unknown ssid> though it is connected to a wifi with SSID
I need to check the current connected wifi SSID on android. I checked with Nokia 6 and OnePlus 5 with respectively Oreo 8.1.0 and Oreo 8.0. Other phones with different OS version is working fine with this code. Is there anything wrong with my code?
private WifiInfo wifiInfo; private String ssid = ""; private WifiManager wifiManager; private boolean getWifiStatus() { wifiManager= (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiInfo = wifiManager.getConnectionInfo(); ssid = ""; ssid = wifiInfo.getSSID(); ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean isWiFi = false; if(activeNetwork != null){ isWiFi = activeNetwork.getType() == ConnectivityManager.TYPE_WIFI; } Log.d(TAG, "getWifiStatus: " + ssid); if(ssid.contains("TripleMZim") && wifiManager.isWifiEnabled() && isWiFi ){ return true; } else{ return false; } }
-
Device connecting wifi direct error
Hello tech geniouses i have a question to ask i made a game using wifi direct the connects both devices perfectly at start, when game finish pop up appear declaring winner and option to play again but when playing again one device connects and other not ?,what will be the issue in this. Thank you
-
Connecting wirelessly two android phone
I am developing some app in which I want to connect two android phone by means of wifi and hotspot.First mobile will open a hotspot and other will join the hotspot from wifi like in"MINI MILITIA" and creating of hotspot and connecting should be done with programming.Is there any way to connect the two phone wirelessly with above method.
-
Ping to www.Google.com hostname unresolved but ip address works (connection through wifi direct )
I have established a WiFi direct connection . I am routing all the packets through the GO device .I could ping Google's ip but not with hostname . I am able to ping hostname when contacted through wlan .
-
Where can I download Android things image for intel edison?
I know Android things have stoped support for Intel edison. Is there a way to get the image for android things for edison ?
-
animationset isRunning returns always false
I have the following code:
ObjectAnimator oa = ObjectAnimator.ofInt(xxxx) oa.setInterpolator(new LinearInterpolator()); oa.setDuration(5000); AnimatorSet as = new AnimatorSet(); as.play(oa); as.start(); Log.d(TAG,"check for running just after start:"+as.isRunning());
last log line shows always false , and I am seeing that animation is running properly on the device.
Any ideas? Thank you.
-
Adding Proxy for Android Things
How to add proxy for Android things. I am now running on androidthings dp7 on raspberry pi 3. Connected to internet using ethernet where the android things board is behind the proxy.
-
how can send and receive data along multiple devices without using any server or external network ?
I am creating an app in which I want to add some details. Now the same app is using some more users in their android devices. So I want that what ever i add in my app that data should be visible to every user in their device. But the problem is i can not use any server but i can use wifi , So is there any way to implement my idea.If it is please help to to do this.
I have seen something here related my idea. Demo app for WiFiP2P data sharing in android
-
in WifiP2pGroup, how to set passphrase for myself
I plant below api to my code and make app.
https://android.googlesource.com/platform/frameworks/base/+/cd92588/wifi/java/android/net/wifi/p2p
But I want to set passphrase for myself, but in WifiP2pGroup.java, setPassphrase is set hide, and even if I use setPassphrase function(I found android.jar which hide functions are opened), I can't change it for myself.
The question is I want to make my wifi for public(no passphrase), if I can't, I want to make passphrase to 00000000.
How can I do that?
import android.annotation.SuppressLint; import android.content.Context; import android.net.wifi.WifiConfiguration; import android.net.wifi.p2p.IWifiP2pManager; import android.net.wifi.p2p.WifiP2pGroup; import android.net.wifi.p2p.WifiP2pManager; import android.util.Log; import android.widget.Toast; public final class WifiDirectShare { private final String TAG = getClass().getSimpleName(); private Context applicationContext; private WifiP2pManager p2pManager; private WifiP2pManager.Channel channel; private GroupCreatedListener listener; public WifiDirectShare(Context context, GroupCreatedListener listener) { this.listener = listener; applicationContext = context.getApplicationContext(); } public void start() { initP2p(applicationContext); startP2pGroup(); } public void stop() { try { p2pManager.removeGroup(channel, new WifiP2pManager.ActionListener() { @Override public void onSuccess() { Log.i(TAG, "P2p removeGroup success"); } @Override public void onFailure(int reason) { Log.i(TAG, "P2p removeGroup failed. Reason : "+reason); } }); } catch (Exception e) {/*ignore*/} } @SuppressLint("ServiceCast") private void initP2p(Context context) { if (this.p2pManager == null || this.channel == null) { this.p2pManager = (WifiP2pManager) context.getSystemService(Context.WIFI_P2P_SERVICE); this.channel = this.p2pManager.initialize(applicationContext, context.getMainLooper(), new WifiP2pManager.ChannelListener() { public void onChannelDisconnected() { Log.i(TAG, "P2p channel initialization failed"); } }); } } private void startP2pGroup() { Thread createGroupThread = new Thread(createGroupRunnable); createGroupThread.start(); } private Runnable createGroupRunnable = new Runnable() { @Override public void run() { p2pManager.createGroup(channel, new WifiP2pManager.ActionListener() { public void onFailure(int error) { Log.i(TAG, "createGroup failed. Error code : "+error); } public void onSuccess() { p2pManager.requestGroupInfo(channel, groupInfoListener); } }); } }; private WifiP2pManager.GroupInfoListener groupInfoListener = new WifiP2pManager.GroupInfoListener() { public void onGroupInfoAvailable(WifiP2pGroup group) { if (group != null) { if(group.isGroupOwner()) { Log.i(TAG, "group created with ssid = "+group.getNetworkName() + "\n and password = "+group.getPassphrase()); if(listener != null) listener.onGroupCreated(group.getNetworkName(), group.getPassphrase()); } } else p2pManager.requestGroupInfo(channel, groupInfoListener); } }; public interface GroupCreatedListener { void onGroupCreated(String ssid, String password); } }
mainActivity call part
share = new WifiDirectShare(MainActivity.this, this); share.start();
-
Android Wi-Fi Direct completely remove a connection then new connection
I am developing a Wi-FI Direct android app, I can connect and share information with 2 device. So discover peers and connection with a peer and data share are working.
I have to do a "random walk" with 10 device, so I have to connect 2 random device over and over again.
The problem is, 2 device connected successfully then removeGroup, after this one of these devices cant connect with the other 8 device. The other problem is they might cant discover peers after connection. So after a successfull connection the devices have to be ready for a new connection.
I think the real problem is, how to completely remove a connection with the other peer and then rediscover peers.
Can someone give me advice on how to completely remove a connection with the other peer?
Thanks