android.net.wifi.p2p.WifiP2pDevice Java Examples
The following examples show how to use
android.net.wifi.p2p.WifiP2pDevice.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WifiDirectGroupManager.java From ShareBox with Apache License 2.0 | 6 votes |
@Override public void onDnsSdTxtRecordAvailable(String fullDomainName, Map<String, String> txtRecordMap, WifiP2pDevice srcDevice) { ALog.i(TAG, "onDnsSdTxtRecordAvailable"); InfoHolder holder=new InfoHolder(); holder.mFullDomainName=fullDomainName; holder.mValueMap=txtRecordMap; holder.mSrcDevice=srcDevice; mHandler.obtainMessage(Event.SERVICE_INFO_AVAILABLE,holder).sendToTarget(); /* String res = ""; for (Entry<String, String> ele : txtRecordMap.entrySet()) { res += ele.getKey(); res += " " + ele.getValue() + " "; }*/ }
Example #2
Source File: WifiDisplayController.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private void updateDesiredDevice(WifiP2pDevice device) { // Handle the case where the device to which we are connecting or connected // may have been renamed or reported different properties in the latest scan. final String address = device.deviceAddress; if (mDesiredDevice != null && mDesiredDevice.deviceAddress.equals(address)) { if (DEBUG) { Slog.d(TAG, "updateDesiredDevice: new information " + describeWifiP2pDevice(device)); } mDesiredDevice.update(device); if (mAdvertisedDisplay != null && mAdvertisedDisplay.getDeviceAddress().equals(address)) { readvertiseDisplay(createWifiDisplay(mDesiredDevice)); } } }
Example #3
Source File: DeviceListFragment.java From commcare-android with Apache License 2.0 | 6 votes |
/** * Initiate a connection with the peer. */ @Override public void onListItemClick(ListView l, View v, int position, long id) { Log.d(TAG, "onListItemClick"); WifiP2pDevice device = (WifiP2pDevice)getListAdapter().getItem(position); Log.d(TAG, "device is: " + device.deviceAddress); WifiP2pConfig config = new WifiP2pConfig(); config.deviceAddress = device.deviceAddress; config.wps.setup = WpsInfo.PBC; if (progressDialog != null && progressDialog.isShowing()) { progressDialog.dismiss(); } progressDialog = ProgressDialog.show(getActivity(), "Press back to cancel", "Connecting to :" + device.deviceAddress, true, true); ((DeviceActionListener)getActivity()).connect(config); }
Example #4
Source File: WifiDisplayController.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private void handleScanResults() { final int count = mAvailableWifiDisplayPeers.size(); final WifiDisplay[] displays = WifiDisplay.CREATOR.newArray(count); for (int i = 0; i < count; i++) { WifiP2pDevice device = mAvailableWifiDisplayPeers.get(i); displays[i] = createWifiDisplay(device); updateDesiredDevice(device); } mHandler.post(new Runnable() { @Override public void run() { mListener.onScanResults(displays); } }); }
Example #5
Source File: WifiDisplayController.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private void handleConnectionFailure(boolean timeoutOccurred) { Slog.i(TAG, "Wifi display connection failed!"); if (mDesiredDevice != null) { if (mConnectionRetriesLeft > 0) { final WifiP2pDevice oldDevice = mDesiredDevice; mHandler.postDelayed(new Runnable() { @Override public void run() { if (mDesiredDevice == oldDevice && mConnectionRetriesLeft > 0) { mConnectionRetriesLeft -= 1; Slog.i(TAG, "Retrying Wifi display connection. Retries left: " + mConnectionRetriesLeft); retryConnection(); } } }, timeoutOccurred ? 0 : CONNECT_RETRY_DELAY_MILLIS); } else { disconnect(); } } }
Example #6
Source File: WifiDisplayController.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private void requestPeers() { mWifiP2pManager.requestPeers(mWifiP2pChannel, new PeerListListener() { @Override public void onPeersAvailable(WifiP2pDeviceList peers) { if (DEBUG) { Slog.d(TAG, "Received list of peers."); } mAvailableWifiDisplayPeers.clear(); for (WifiP2pDevice device : peers.getDeviceList()) { if (DEBUG) { Slog.d(TAG, " " + describeWifiP2pDevice(device)); } if (isWifiDisplay(device)) { mAvailableWifiDisplayPeers.add(device); } } if (mDiscoverPeersInProgress) { handleScanResults(); } } }); }
Example #7
Source File: DeviceListFragment.java From commcare-android with Apache License 2.0 | 6 votes |
private static String getDeviceStatus(int deviceStatus) { Log.d(TAG, "Peer status :" + deviceStatus); switch (deviceStatus) { case WifiP2pDevice.AVAILABLE: return "Available"; case WifiP2pDevice.INVITED: return "Invited"; case WifiP2pDevice.CONNECTED: return "Connected"; case WifiP2pDevice.FAILED: return "Failed"; case WifiP2pDevice.UNAVAILABLE: return "Unavailable"; default: return "Unknown"; } }
Example #8
Source File: ActivityManageP2P.java From nfcspy with GNU General Public License v3.0 | 6 votes |
void handleBroadcast(Intent intent) { closeProgressDialog(); final String action = intent.getAction(); if (WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) { int state = intent.getIntExtra(EXTRA_WIFI_STATE, -1); if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) { p2p.isWifiP2pEnabled = true; } else { showMessage(R.string.event_p2p_disable); resetData(); } } else if (WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) { new Wifip2pRequestPeers(eventHelper).execute(p2p); } else if (WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) { WifiP2pDevice me = (WifiP2pDevice) intent .getParcelableExtra(EXTRA_WIFI_P2P_DEVICE); thisDevice.setText(getWifiP2pDeviceInfo(me)); } }
Example #9
Source File: WifiDirectHandler.java From WiFi-Buddy with MIT License | 6 votes |
/** * Translates a device status code to a readable String status * @param status * @return A readable String device status */ public String deviceStatusToString(int status) { if (status == WifiP2pDevice.AVAILABLE) { return "Available"; } else if (status == WifiP2pDevice.INVITED) { return "Invited"; } else if (status == WifiP2pDevice.CONNECTED) { return "Connected"; } else if (status == WifiP2pDevice.FAILED) { return "Failed"; } else if (status == WifiP2pDevice.UNAVAILABLE) { return "Unavailable"; } else { return "Unknown"; } }
Example #10
Source File: WifiDirectHandler.java From WiFi-Buddy with MIT License | 6 votes |
public String p2pGroupToString(WifiP2pGroup wifiP2pGroup) { if (wifiP2pGroup != null) { String strWifiP2pGroup = "Network name: " + wifiP2pGroup.getNetworkName(); strWifiP2pGroup += "\nIs group owner: " + wifiP2pGroup.isGroupOwner(); if (wifiP2pGroup.getOwner() != null) { strWifiP2pGroup += "\nGroup owner: "; strWifiP2pGroup += "\n" + p2pDeviceToString(wifiP2pGroup.getOwner()); } if (wifiP2pGroup.getClientList() != null && !wifiP2pGroup.getClientList().isEmpty()) { for (WifiP2pDevice client : wifiP2pGroup.getClientList()) { strWifiP2pGroup += "\nClient: "; strWifiP2pGroup += "\n" + p2pDeviceToString(client); } } return strWifiP2pGroup; } else { Log.e(TAG, "WifiP2pGroup is null"); return ""; } }
Example #11
Source File: WifiP2PServiceImpl.java From Wifi-Connect with Apache License 2.0 | 6 votes |
@Override public synchronized void connectDevice(WifiP2pDevice wifiP2pDevice) { WifiP2pConfig config = new WifiP2pConfig(); config.deviceAddress = wifiP2pDevice.deviceAddress; config.wps.setup = WpsInfo.PBC; config.groupOwnerIntent = 15; manager.connect(channel, config, new WifiP2pManager.ActionListener() { @Override public void onSuccess() {} @Override public void onFailure(int reason) { if(wifiP2PConnectionCallback != null) { activity.runOnUiThread(new Runnable() { @Override public void run() { wifiP2PConnectionCallback.onPeerConnectionFailure(); } }); } } }); }
Example #12
Source File: DeviceListFragment.java From Demo_Public with MIT License | 6 votes |
@Override public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if(v == null){ LayoutInflater vi = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.row_devices, null); } WifiP2pDevice device = items.get(position); if(device != null){ TextView top = (TextView)v.findViewById(R.id.device_name); TextView bottom = (TextView)v.findViewById(R.id.device_details); if(null != top){ top.setText(device.deviceName); } if(null != bottom){ bottom.setText(device.deviceAddress); } } return v; }
Example #13
Source File: WifiDirectManager.java From ShareBox with Apache License 2.0 | 6 votes |
public static String getDeviceStatus(int deviceStatus) { switch (deviceStatus) { case WifiP2pDevice.AVAILABLE: return "Available"; case WifiP2pDevice.INVITED: return "Invited"; case WifiP2pDevice.CONNECTED: return "Connected"; case WifiP2pDevice.FAILED: return "Failed"; case WifiP2pDevice.UNAVAILABLE: return "Unavailable"; default: return "Unknown error"; } }
Example #14
Source File: ActivityManageP2P.java From nfcspy with GNU General Public License v3.0 | 6 votes |
private CharSequence getWifiP2pDeviceStatus(WifiP2pDevice dev) { switch (dev.status) { case WifiP2pDevice.CONNECTED: return getString(R.string.status_p2p_connected); case WifiP2pDevice.INVITED: return getString(R.string.status_p2p_invited); case WifiP2pDevice.FAILED: return getString(R.string.status_p2p_failed); case WifiP2pDevice.AVAILABLE: return getString(R.string.status_p2p_available); case WifiP2pDevice.UNAVAILABLE: default: return getString(R.string.status_p2p_unavailable); } }
Example #15
Source File: WiFiP2pHelper.java From libcommon with Apache License 2.0 | 6 votes |
/** * 切断する */ protected void internalDisconnect(final WifiP2pManager.ActionListener listener) { if (DEBUG) Log.v(TAG, "internalDisconnect:"); if (mWifiP2pManager != null) { if ((mWifiP2pDevice == null) || (mWifiP2pDevice.status == WifiP2pDevice.CONNECTED)) { // 接続されていないか、既に接続済みの時 if (mChannel != null) { mWifiP2pManager.removeGroup(mChannel, listener); } } else if (mWifiP2pDevice.status == WifiP2pDevice.AVAILABLE || mWifiP2pDevice.status == WifiP2pDevice.INVITED) { // ネゴシエーション中の時 mWifiP2pManager.cancelConnect(mChannel, listener); } } }
Example #16
Source File: DeviceListFragment.java From Wifi-Connect with Apache License 2.0 | 6 votes |
@Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_device_list, container, false); progressView = rootView.findViewById(R.id.scan_progress); animationView = rootView.findViewById(R.id.gif1); recyclerView = rootView.findViewById(R.id.scanned_list); recyclerView.setLayoutManager(new LinearLayoutManager(activity)); wifiListAdapter = new WifiListAdapter(activity, new ArrayList<WifiP2pDevice>()); recyclerView.setAdapter(wifiListAdapter); emptyView = rootView.findViewById(R.id.empty_view); swipeRefreshLayout = rootView.findViewById(R.id.swipeRefreshLayout); ((SenderActivity)activity).wifiP2PService.onCreate(); ((SenderActivity)activity).wifiP2PService.onResume(); return rootView; }
Example #17
Source File: DeviceListFragment.java From commcare-android with Apache License 2.0 | 6 votes |
@Override public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if (v == null) { LayoutInflater vi = (LayoutInflater)getActivity().getSystemService( Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.component_row_devices, null); } WifiP2pDevice device = items.get(position); if (device != null) { TextView top = v.findViewById(R.id.device_name); TextView bottom = v.findViewById(R.id.device_details); if (top != null) { top.setText(device.deviceName); } if (bottom != null) { bottom.setText(getDeviceStatus(device.status)); } } return v; }
Example #18
Source File: WiFiDirectActivity.java From Demo_Public with MIT License | 6 votes |
@Override public void cancelDisconnect() { if(mManager != null){ final DeviceListFragment fragment = (DeviceListFragment)getFragmentManager().findFragmentById(R.id.frag_list); if(fragment.getDevice() == null || fragment.getDevice().status == WifiP2pDevice.CONNECTED){ disconnect(); }else if(fragment.getDevice().status == WifiP2pDevice.AVAILABLE || fragment.getDevice().status == WifiP2pDevice.INVITED){ mManager.cancelConnect(mChannel, new WifiP2pManager.ActionListener() { @Override public void onSuccess() { } @Override public void onFailure(int reason) { } }); } } }
Example #19
Source File: DeviceListFragment.java From Demo_Public with MIT License | 6 votes |
private static String getDeviceStatus(int deviceStatus){ Log.e(WiFiDirectActivity.TAG, "Peer status: "+deviceStatus); switch(deviceStatus){ case WifiP2pDevice.AVAILABLE: return "Avaiable"; case WifiP2pDevice.INVITED: return "Invited"; case WifiP2pDevice.CONNECTED: return "Conntend"; case WifiP2pDevice.FAILED: return "Failed"; case WifiP2pDevice.UNAVAILABLE: return "Unavailable"; default: return "Unkonw"; } }
Example #20
Source File: WifiDirectHandler.java From WiFi-Buddy with MIT License | 6 votes |
/** * Takes a WifiP2pDevice and returns a String of readable device information * @param wifiP2pDevice * @return */ public String p2pDeviceToString(WifiP2pDevice wifiP2pDevice) { if (wifiP2pDevice != null) { String strDevice = "Device name: " + wifiP2pDevice.deviceName; strDevice += "\nDevice address: " + wifiP2pDevice.deviceAddress; if (wifiP2pDevice.equals(thisDevice)) { strDevice += "\nIs group owner: " + isGroupOwner(); } else { strDevice += "\nIs group owner: false"; } strDevice += "\nStatus: " + deviceStatusToString(wifiP2pDevice.status) + "\n"; return strDevice; } else { Log.e(TAG, "WifiP2pDevice is null"); return ""; } }
Example #21
Source File: WifiDirectGroupManager.java From ShareBox with Apache License 2.0 | 5 votes |
@Override public void onDnsSdServiceAvailable(String instanceName, String registrationType, WifiP2pDevice srcDevice) { ALog.i(TAG, "onDnsSdServiceAvailable name:"+instanceName); InfoHolder holder=new InfoHolder(); holder.mInstanceName=instanceName; holder.mRegistrationType=registrationType; holder.mSrcDevice=srcDevice; mHandler.obtainMessage(Event.SERVICE_AVAILABLE,holder).sendToTarget(); }
Example #22
Source File: ActivityManageP2P.java From nfcspy with GNU General Public License v3.0 | 5 votes |
private void connectPeer(WifiP2pDevice peer) { CharSequence dev = getWifiP2pDeviceInfo2(peer); CharSequence msg = Logger.fmt(getString(R.string.info_connect), dev); CharSequence msg2 = Logger .fmt(getString(R.string.info_connecting), dev); CommandHelper cmd = new CommandHelper(new Wifip2pConnectPeer(peer, eventHelper), p2p, msg2); new AlertDialog.Builder(this, AlertDialog.THEME_HOLO_LIGHT) .setTitle(R.string.lab_p2p_connect).setMessage(msg) .setNegativeButton(R.string.action_cancel, cmd) .setPositiveButton(R.string.action_ok, cmd).show(); }
Example #23
Source File: P2pConnect.java From ShareBox with Apache License 2.0 | 5 votes |
@Override public void onPeersAvailable(WifiP2pDeviceList peers) { for(WifiP2pDevice device:peers.getDeviceList()) { Log.i(TAG,device.toString()); } _p2pDeviceList.clear(); _p2pDeviceList.addAll(peers.getDeviceList()); }
Example #24
Source File: P2pManager.java From ShareBox with Apache License 2.0 | 5 votes |
public void connect(WifiP2pDevice device,WifiP2pManager.ActionListener listener) { WifiP2pConfig config=new WifiP2pConfig(); config.deviceAddress=device.deviceAddress; config.wps.setup= WpsInfo.PBC; _wifiP2pManager.connect(_channel, config, listener); }
Example #25
Source File: SalutDevice.java From Salut with MIT License | 5 votes |
public SalutDevice(WifiP2pDevice device, Map<String, String> txtRecord) { this.serviceName = txtRecord.get("SERVICE_NAME"); this.readableName = txtRecord.get("INSTANCE_NAME"); this.instanceName = txtRecord.get("INSTANCE_NAME"); this.deviceName = device.deviceName; this.macAddress = device.deviceAddress; this.txtRecord = txtRecord; }
Example #26
Source File: P2pChatService.java From android-p2p with MIT License | 5 votes |
public List<PeerDevice> getDevices() { List<PeerDevice> devices = new ArrayList<>(); for (WifiP2pDevice p2pDevice : P2pChatService.this.Devices) { ClientInfo comparable = ClientInfo.GetComparable(p2pDevice.deviceAddress); PeerDevice device = new PeerDevice(p2pDevice, P2pChatService.this.Clients.contains(comparable)); devices.add(device); } return devices; }
Example #27
Source File: PeerActivity.java From android-p2p with MIT License | 5 votes |
private void connectPeer(WifiP2pDevice peer) { WifiP2pConfig config = new WifiP2pConfig(); config.deviceAddress = peer.deviceAddress; config.wps.setup = WpsInfo.PBC; this.Application.P2pHandler.Manager.connect(this.Application.P2pHandler.Channel, config, new WifiP2pManager.ActionListener() { @Override public void onSuccess() { Toast.makeText(PeerActivity.this, "Connecting to peer ...", Toast.LENGTH_SHORT).show(); } @Override public void onFailure(int reason) { Toast.makeText(PeerActivity.this, "Peer connection failed with code " + Integer.toString(reason), Toast.LENGTH_SHORT).show(); } }); }
Example #28
Source File: ActivityManageP2P.java From nfcspy with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_manage_p2p); peerdevs = new ArrayList<WifiP2pDevice>(); peers = new ArrayAdapter<CharSequence>(this, R.layout.listitem_peer); eventHelper = new EventHelper(); ListView lv = ((ListView) findViewById(R.id.list)); lv.setAdapter(peers); lv.setOnItemClickListener(eventHelper); thisDevice = (TextView) findViewById(R.id.txtThisdevice); }
Example #29
Source File: ActivityManageP2P.java From nfcspy with GNU General Public License v3.0 | 5 votes |
private void disconnectPeer(WifiP2pDevice peer) { CharSequence dev = getWifiP2pDeviceInfo2(peer); CharSequence msg = Logger.fmt(getString(R.string.info_disconnect), dev); CommandHelper cmd = new CommandHelper(new Wifip2pCancelConnect( eventHelper), p2p, null); new AlertDialog.Builder(this, AlertDialog.THEME_HOLO_LIGHT) .setTitle(R.string.lab_p2p_disconnect).setMessage(msg) .setNegativeButton(R.string.action_cancel, cmd) .setPositiveButton(R.string.action_ok, cmd).show(); }
Example #30
Source File: WiFiP2pHelper.java From libcommon with Apache License 2.0 | 5 votes |
/** * 周辺のWiFi Direct機器の状態が変化した時のコールバックリスナーを呼び出す * @param devices */ protected void callOnUpdateDevices(@NonNull final List<WifiP2pDevice> devices) { if (DEBUG) Log.v(TAG, "callOnUpdateDevices:"); for (final WiFiP2pListener listener: mListeners) { try { listener.onUpdateDevices(devices); } catch (final Exception e1) { Log.w(TAG, e1); mListeners.remove(listener); } } }