Java Code Examples for android.net.wifi.p2p.WifiP2pDevice#AVAILABLE

The following examples show how to use android.net.wifi.p2p.WifiP2pDevice#AVAILABLE . 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: WifiDirectManager.java    From ShareBox with Apache License 2.0 6 votes vote down vote up
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 2
Source File: WiFiP2pHelper.java    From libcommon with Apache License 2.0 6 votes vote down vote up
/**
 * 切断する
 */
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 3
Source File: WiFiDirectActivity.java    From Demo_Public with MIT License 6 votes vote down vote up
@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 4
Source File: DeviceListFragment.java    From Demo_Public with MIT License 6 votes vote down vote up
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 5
Source File: WifiDirectHandler.java    From WiFi-Buddy with MIT License 6 votes vote down vote up
/**
 * 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 6
Source File: ActivityManageP2P.java    From nfcspy with GNU General Public License v3.0 6 votes vote down vote up
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 7
Source File: DeviceListFragment.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
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: WifiDirectManager.java    From ShareBox with Apache License 2.0 5 votes vote down vote up
public void disconnectWifiDirect() {
	if (mWifiP2pDevice != null) {
		ALog.i(TAG, "disconnectWifiDirect mWifiP2pDevice.status:" + mWifiP2pDevice.status);
		if (mWifiP2pDevice.status == WifiP2pDevice.CONNECTED) {
			disconnect();
		} else if (mWifiP2pDevice.status == WifiP2pDevice.AVAILABLE 
				|| mWifiP2pDevice.status == WifiP2pDevice.INVITED) {
			cancelConnect();
		}
	}
}
 
Example 9
Source File: WiFiDirectManagementFragment.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
public void onThisDeviceChanged(Intent intent) {

        setStatusText("This device's connection status changed...");

        WifiP2pDevice mDevice = intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE);

        int status = mDevice.status;

        if (status == WifiP2pDevice.AVAILABLE && isHost) {
            Logger.log(TAG, "Relaunching Wi-fi direct group as host");
            setStatusText("Host relaunching group...");
            mManager.createGroup(mChannel, this);
        }

        mActivity.updateDeviceStatus(mDevice);
    }