本文整理汇总了Java中android.net.wifi.p2p.WifiP2pGroup类的典型用法代码示例。如果您正苦于以下问题:Java WifiP2pGroup类的具体用法?Java WifiP2pGroup怎么用?Java WifiP2pGroup使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WifiP2pGroup类属于android.net.wifi.p2p包,在下文中一共展示了WifiP2pGroup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: p2pGroupToString
import android.net.wifi.p2p.WifiP2pGroup; //导入依赖的package包/类
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 "";
}
}
示例2: closeP2PConnection
import android.net.wifi.p2p.WifiP2pGroup; //导入依赖的package包/类
/**
* This closes the P2P Connection. After some research, this seems to be the proper way to do it.
* Before closing a group the group information should be refreshed by calling requestGroupInfo().
* The next step is to call removeGroup(), but only if we are the group owner. This properly
* tears down the connection on both sides and will fire onConnectionChanged on both devices.
*/
private void closeP2PConnection() {
Log.d(TAG, "Closing P2P connection...");
if (mManager != null && mChannel != null) {
mManager.requestGroupInfo(mChannel, new WifiP2pManager.GroupInfoListener() {
@Override
public void onGroupInfoAvailable(WifiP2pGroup group) {
if (group != null && mManager != null && mChannel != null && group.isGroupOwner()) {
mManager.removeGroup(mChannel, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
Log.d(TAG, "P2P Group removed");
}
@Override
public void onFailure(int i) {
Log.d(TAG, "P2P Group NOT removed");
}
});
}
}
});
}
}
示例3: onGroupInfoAvailable
import android.net.wifi.p2p.WifiP2pGroup; //导入依赖的package包/类
@Override
public void onGroupInfoAvailable(WifiP2pGroup group) {
try {
callback.GroupInfoAvailable(group);
if(mNetworkName.equals(group.getNetworkName()) && mPassphrase.equals(group.getPassphrase())){
debug_print("Already have local service for " + mNetworkName + " ," + mPassphrase);
}else {
mNetworkName = group.getNetworkName();
mPassphrase = group.getPassphrase();
startLocalService("NI:" + group.getNetworkName() + ":" + group.getPassphrase() + ":" + mInetAddress);
}
} catch(Exception e) {
debug_print("onGroupInfoAvailable, error: " + e.toString());
}
}
示例4: disconnectFromDevice
import android.net.wifi.p2p.WifiP2pGroup; //导入依赖的package包/类
protected void disconnectFromDevice()
{
manager.requestGroupInfo(channel, new WifiP2pManager.GroupInfoListener() {
@Override
public void onGroupInfoAvailable(final WifiP2pGroup group) {
if (group != null) {
manager.removeGroup(channel, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
isConnectedToAnotherDevice = false;
deleteGroup(manager, channel, group);
Log.d(TAG, "Removed WiFi Direct Group.");
}
@Override
public void onFailure(int reason) {
Log.e(TAG, "Failed to remove a WiFi Direct Group. Reason: " + reason);
}
});
}
}
});
}
示例5: disconnectFromDevice
import android.net.wifi.p2p.WifiP2pGroup; //导入依赖的package包/类
protected void disconnectFromDevice() {
manager.requestGroupInfo(channel, new WifiP2pManager.GroupInfoListener() {
@Override
public void onGroupInfoAvailable(final WifiP2pGroup group) {
if (group != null) {
manager.removeGroup(channel, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
isConnectedToAnotherDevice = false;
deleteGroup(manager, channel, group);
Log.d(TAG, "Removed WiFi Direct Group.");
}
@Override
public void onFailure(int reason) {
Log.e(TAG, "Failed to remove a WiFi Direct Group. Reason: " + reason);
}
});
}
}
});
}
示例6: onGroupInfoAvailable
import android.net.wifi.p2p.WifiP2pGroup; //导入依赖的package包/类
@Override
public void onGroupInfoAvailable(WifiP2pGroup group)
{
mOwner = group.getOwner();
String owner;
if (mOwner.deviceAddress.equals(mDevice.deviceAddress)) {
owner = "YOU ARE THE GROUP OWNER";
} else {
owner = mOwner.deviceName + " [" + mOwner.deviceAddress + "]";
}
TextView view = (TextView) mContentView.findViewById(R.id.my_g_name);
view.setText(owner);
view = (TextView) mContentView.findViewById(R.id.my_g_status);
view.setText("Status: "
+ AperiMainActivity.getDeviceStatus(mOwner.status));
view = (TextView) mContentView.findViewById(R.id.my_g_is_group_owner);
view.setText(mOwner.isGroupOwner() ? "Is: Group Owner" : "Is: Client");
}
示例7: onReceive
import android.net.wifi.p2p.WifiP2pGroup; //导入依赖的package包/类
@Override
@SuppressLint("InlinedApi")
public void onReceive(Context context, Intent intent) {
if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(intent.getAction())) {
WifiP2pGroup wifiP2pGroup = intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_GROUP);
onWifiP2pGroupChange(wifiP2pGroup);
} else if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(intent.getAction())) {
int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, 0 /* default to unknown */);
onWifiP2pStateChange(state);
}
}
示例8: onWifiP2pGroupChange
import android.net.wifi.p2p.WifiP2pGroup; //导入依赖的package包/类
/** Handle a change notification about the wifi p2p group. */
private void onWifiP2pGroupChange(WifiP2pGroup wifiP2pGroup) {
if (wifiP2pGroup == null || wifiP2pGroup.getInterface() == null) {
return;
}
NetworkInterface wifiP2pInterface;
try {
wifiP2pInterface = NetworkInterface.getByName(wifiP2pGroup.getInterface());
} catch (SocketException e) {
Logging.e(TAG, "Unable to get WifiP2p network interface", e);
return;
}
List<InetAddress> interfaceAddresses = Collections.list(wifiP2pInterface.getInetAddresses());
IPAddress[] ipAddresses = new IPAddress[interfaceAddresses.size()];
for (int i = 0; i < interfaceAddresses.size(); ++i) {
ipAddresses[i] = new IPAddress(interfaceAddresses.get(i).getAddress());
}
wifiP2pNetworkInfo =
new NetworkInformation(
wifiP2pGroup.getInterface(),
ConnectionType.CONNECTION_WIFI,
WIFI_P2P_NETWORK_HANDLE,
ipAddresses);
observer.onNetworkConnect(wifiP2pNetworkInfo);
}
示例9: handleConnectionChanged
import android.net.wifi.p2p.WifiP2pGroup; //导入依赖的package包/类
/**
* The state of Wi-Fi P2P connectivity has changed
* Here is where you can request group info
* Available extras: EXTRA_WIFI_P2P_INFO, EXTRA_NETWORK_INFO, EXTRA_WIFI_P2P_GROUP
* @param intent
*/
private void handleConnectionChanged(Intent intent) {
Log.i(TAG, "Wi-Fi P2P Connection Changed");
if(wifiP2pManager == null) {
return;
}
// Extra information from EXTRA_NETWORK_INFO
NetworkInfo networkInfo = intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);
if(networkInfo.isConnected()) {
Log.i(TAG, "Connected to P2P network. Requesting connection info");
wifiP2pManager.requestConnectionInfo(channel, WifiDirectHandler.this);
} else {
Intent disconnected = new Intent(Action.COMMUNICATION_DISCONNECTED);
localBroadcastManager.sendBroadcast(disconnected);
}
// Requests peer-to-peer group information
wifiP2pManager.requestGroupInfo(channel, new WifiP2pManager.GroupInfoListener() {
@Override
public void onGroupInfoAvailable(WifiP2pGroup wifiP2pGroup) {
if (wifiP2pGroup != null) {
Log.i(TAG, "Group info available");
Log.i(TAG, "WifiP2pGroup:");
Log.i(TAG, p2pGroupToString(wifiP2pGroup));
WifiDirectHandler.this.wifiP2pGroup = wifiP2pGroup;
}
}
});
}
示例10: onConnectionInfoAvailable
import android.net.wifi.p2p.WifiP2pGroup; //导入依赖的package包/类
@Override
public void onConnectionInfoAvailable(final WifiP2pInfo info) {
/* This method is automatically called when we connect to a device.
* The group owner accepts connections using a server socket and then spawns a
* client socket for every client. This is handled by the registration jobs.
* This will automatically handle first time connections.*/
manager.requestGroupInfo(channel, new WifiP2pManager.GroupInfoListener() {
@Override
public void onGroupInfoAvailable(WifiP2pGroup group) {
if (isRunningAsHost && !registrationIsRunning) {
if (info.groupFormed && !group.getClientList().isEmpty()) {
startHostRegistrationServer();
}
} else if (!thisDevice.isRegistered && !info.isGroupOwner) {
if (serviceRequest == null) {
//This means that discoverNetworkServices was never called and we're still connected to an old host for some reason.
Log.e(Salut.TAG, "This device is still connected to an old host for some reason. A forced disconnect will be attempted.");
forceDisconnect();
}
Log.v(Salut.TAG, "Successfully connected to another device.");
startRegistrationForClient(new InetSocketAddress(info.groupOwnerAddress.getHostAddress(), SALUT_SERVER_PORT));
}
}
});
}
示例11: deleteGroup
import android.net.wifi.p2p.WifiP2pGroup; //导入依赖的package包/类
private void deleteGroup(WifiP2pManager manager, WifiP2pManager.Channel channel, WifiP2pGroup wifiP2pGroup)
{
try {
Method getNetworkId = WifiP2pGroup.class.getMethod("getNetworkId");
Integer networkId = (Integer) getNetworkId.invoke(wifiP2pGroup);
Method deletePersistentGroup = WifiP2pManager.class.getMethod("deletePersistentGroup",
WifiP2pManager.Channel.class, Integer.class, WifiP2pManager.ActionListener.class);
deletePersistentGroup.invoke(manager, channel, networkId, null);
} catch (Exception ex) {
Log.v(Salut.TAG, "Failed to delete persistent group.");
}
}
示例12: deleteGroup
import android.net.wifi.p2p.WifiP2pGroup; //导入依赖的package包/类
private void deleteGroup(WifiP2pManager manager, WifiP2pManager.Channel channel, WifiP2pGroup wifiP2pGroup) {
try {
Method getNetworkId = WifiP2pGroup.class.getMethod("getNetworkId");
Integer networkId = (Integer) getNetworkId.invoke(wifiP2pGroup);
Method deletePersistentGroup = WifiP2pManager.class.getMethod("deletePersistentGroup",
WifiP2pManager.Channel.class, Integer.class, WifiP2pManager.ActionListener.class);
deletePersistentGroup.invoke(manager, channel, networkId, null);
} catch (Exception ex) {
Log.v(Salut.TAG, "Failed to delete persistent group.");
}
}
示例13: notify_connectivity_changed
import android.net.wifi.p2p.WifiP2pGroup; //导入依赖的package包/类
private void notify_connectivity_changed(final WifiP2pInfo p2pInfo, final NetworkInfo networkInfo, final WifiP2pGroup group) {
executorService.execute(new Runnable() {
@Override
public void run() {
for (IBlaubotWifiDirectEventListener listener : eventListeners) {
listener.onConnectivityChanged(p2pInfo, networkInfo, group);
}
}
});
}
示例14: onGroupInfoAvailable
import android.net.wifi.p2p.WifiP2pGroup; //导入依赖的package包/类
@Override
public void onGroupInfoAvailable(WifiP2pGroup group) {
if (group != null) {
Log.d(WiFiDirectActivity.TAG, "onGroupInfoAvailable - " + group.getNetworkName());
Log.d(WiFiDirectActivity.TAG, "onGroupInfoAvailable - " + group.getPassphrase());
TextView view = (TextView) mContentView.findViewById(R.id.group_ip);
view.setText(group.getNetworkName() + " - " + group.getPassphrase());
for (WifiP2pDevice device : group.getClientList()) {
Log.d(WiFiDirectActivity.TAG, "group.getClientList() - " + device);
}
}
}
示例15: onGroupInfoAvailable
import android.net.wifi.p2p.WifiP2pGroup; //导入依赖的package包/类
@Override
public void onGroupInfoAvailable(WifiP2pGroup group) {
wifiP2pGroup = group;
try {
Method getNetworkId = group.getClass().getMethod("getNetworkId");
getNetworkId.setAccessible(true);
mNetId = (Integer) getNetworkId.invoke(group);
} catch (Exception e) {
e.printStackTrace();
}
onNFGameNotify();
Log.d(TAG, "wifiP2pGroup = " + wifiP2pGroup);
}