本文整理汇总了Java中android.net.wifi.p2p.WifiP2pManager类的典型用法代码示例。如果您正苦于以下问题:Java WifiP2pManager类的具体用法?Java WifiP2pManager怎么用?Java WifiP2pManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WifiP2pManager类属于android.net.wifi.p2p包,在下文中一共展示了WifiP2pManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: WiFiDirectConnection
import android.net.wifi.p2p.WifiP2pManager; //导入依赖的package包/类
public WiFiDirectConnection(Activity activity, WiFiTransfer transfer) {
this.activity = activity;
this.transfer = transfer;
intentFilter = new IntentFilter();
intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
manager = (WifiP2pManager) activity.getSystemService(Context.WIFI_P2P_SERVICE);
channel = manager.initialize(activity.getApplicationContext(), activity.getMainLooper(), channelListener);
channelListener = new ChannelListener();
connectionInfoListener = new ConnectionInfoListener();
}
示例2: connect
import android.net.wifi.p2p.WifiP2pManager; //导入依赖的package包/类
public void connect(WifiP2pConfig config) {
manager.connect(channel, config, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
// WiFiDirectBroadcastReceiver will notify us. Ignore for now.
peerListener.connectionSuccess();
}
@Override
public void onFailure(int reason) {
peerListener.connectionFailure();
Toast.makeText(activity, "Connect failed. Retry.", Toast.LENGTH_SHORT).show();
}
});
}
示例3: onCreate
import android.net.wifi.p2p.WifiP2pManager; //导入依赖的package包/类
public void onCreate(){
super.onCreate();
mManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
mChannel = mManager.initialize(this, getMainLooper(), null);
mReceiver = new WiFiDirectBroadcastReceiver(mManager, mChannel, this);
mIntentFilter = new IntentFilter();
mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
mWiFiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL , "WiFiDirectLock");
mHandler = new Handler();
registerReceiver(mReceiver, mIntentFilter);
// try {
// Method enableP2p = WifiP2pManager.class.getMethod("enableP2p", Channel.class);
// enableP2p.invoke(mManager, mChannel);
// } catch (IllegalArgumentException e) {
// e.printStackTrace();
// } catch (IllegalAccessException e) {
// e.printStackTrace();
// } catch (InvocationTargetException e) {
// e.printStackTrace();
// } catch (NoSuchMethodException e) {
// e.printStackTrace();
// }
// mManager.enableP2p(mChannel);
}
示例4: runSetupSteps
import android.net.wifi.p2p.WifiP2pManager; //导入依赖的package包/类
public void runSetupSteps() throws RemoteConnectionException {
intentFilter = new IntentFilter();
intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
manager = (WifiP2pManager) activity.getSystemService(Context.WIFI_P2P_SERVICE);
channel = manager.initialize(activity.getApplicationContext(), activity.getMainLooper(), null);
peerListener = new PeerListener();
connectionListener = new ConnectionListener();
setupCompleted = true;
}
示例5: discoverPeers
import android.net.wifi.p2p.WifiP2pManager; //导入依赖的package包/类
public void discoverPeers ()
{
mManager.discoverPeers(mChannel, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
// Code for when the discovfindNeighborsery initiation is successful goes here.
// No services have actually been discovered yet, so this method
// can often be left blank. Code for peer discovery goes in the
// onReceive method, detailed below.
}
@Override
public void onFailure(int reasonCode) {
// Code for when the discovery initiation fails goes here.
// Alert the user that something went wrong.
}
});
}
示例6: connectToPeer
import android.net.wifi.p2p.WifiP2pManager; //导入依赖的package包/类
private void connectToPeer (WifiP2pDevice device)
{
WifiP2pConfig config = new WifiP2pConfig();
config.deviceAddress = device.deviceAddress;
config.wps.setup = WpsInfo.PBC;
mManager.connect(mChannel, config, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
// WiFiDirectBroadcastReceiver will notify us. Ignore for now.
}
@Override
public void onFailure(int reason) {
}
});
}
示例7: onCreate
import android.net.wifi.p2p.WifiP2pManager; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// add necessary intent values to be matched.
intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
channel = manager.initialize(this, getMainLooper(), null);
}
示例8: onCreate
import android.net.wifi.p2p.WifiP2pManager; //导入依赖的package包/类
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
statusTxtView = (TextView) findViewById(R.id.status_text);
intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
intentFilter
.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
intentFilter
.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
channel = manager.initialize(this, getMainLooper(), null);
startRegistrationAndDiscovery();
servicesList = new WiFiDirectServicesList();
getFragmentManager().beginTransaction()
.add(R.id.container_root, servicesList, "services").commit();
}
示例9: onFailure
import android.net.wifi.p2p.WifiP2pManager; //导入依赖的package包/类
@Override
public void onFailure(int reason) {
String errorMessage = "";
switch (reason){
case WifiP2pManager.BUSY:
errorMessage="busy";
break;
case WifiP2pManager.ERROR:
errorMessage="error";
break;
case WifiP2pManager.P2P_UNSUPPORTED:
errorMessage="p2p unsupported";
break;
}
Log.d(tag,"onError: " + errorMessage);
}
示例10: register
import android.net.wifi.p2p.WifiP2pManager; //导入依赖的package包/类
/**
* WiFiP2pHelperインスタンスをシステムに登録
*/
public synchronized void register() {
if (DEBUG) Log.v(TAG, "register:");
final Context context = mWeakContext.get();
if ((context != null) & (mReceiver == null)) {
mChannel = mWifiP2pManager.initialize(context,
context.getMainLooper(), mChannelListener);
mReceiver = new WiFiDirectBroadcastReceiver(mWifiP2pManager, mChannel, this);
final IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
context.registerReceiver(mReceiver, intentFilter);
}
}
示例11: startDiscovery
import android.net.wifi.p2p.WifiP2pManager; //导入依赖的package包/类
/**
* WiFi Directに対応した機器探索を開始
* @throws IllegalStateException
*/
public synchronized void startDiscovery() throws IllegalStateException {
if (DEBUG) Log.v(TAG, "startDiscovery:");
if (mChannel != null) {
mWifiP2pManager.discoverPeers(mChannel, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
}
@Override
public void onFailure(final int reason) {
callOnError(new RuntimeException("failed to start discovery, reason=" + reason));
}
});
} else {
throw new IllegalStateException("not registered");
}
}
示例12: connect
import android.net.wifi.p2p.WifiP2pManager; //导入依赖的package包/类
/**
* 指定した機器へ接続を試みる
* @param config
* @throws IllegalStateException
*/
public void connect(@NonNull final WifiP2pConfig config) throws IllegalStateException {
if (DEBUG) Log.v(TAG, "connect:config=" + config);
if (mChannel != null) {
mWifiP2pManager.connect(mChannel, config, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
// WiFiDirectBroadcastReceiver will notify us. Ignore for now.
}
@Override
public void onFailure(int reason) {
callOnError(new RuntimeException("failed to connect, reason=" + reason));
}
});
} else {
throw new IllegalStateException("not registered");
}
}
示例13: internalDisconnect
import android.net.wifi.p2p.WifiP2pManager; //导入依赖的package包/类
/**
* 切断する
*/
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);
}
}
}
示例14: onReceive
import android.net.wifi.p2p.WifiP2pManager; //导入依赖的package包/类
/**
* Handle incoming messages. This class handles broadcasts sent by WifiP2pManager.
* We handle them by calling other methods in the class as appropriate to handle
* each type of event. One specific method is called for each type of event
* and handles all the logic related to that event.
*
* @see android.content.BroadcastReceiver#onReceive(android.content.Context,
* android.content.Intent)
*/
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
onWifiP2pStateChanged(context, intent);
} else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {
onWifiP2pPeersChanged(context, intent);
} else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
onWifiP2pConnectionChanged(context, intent);
} else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
onWifiP2pThisDeviceChanged(context, intent);
} else if (WifiP2pManager.WIFI_P2P_DISCOVERY_CHANGED_ACTION.equals(action)) {
onWifiP2pDiscoveryChanged(context, intent);
} else {
// TODO(lerner): This shouldn't happen, exception?
Log.wtf(TAG, "Received an event we weren't expecting: " + action);
}
}
示例15: onWifiP2pStateChanged
import android.net.wifi.p2p.WifiP2pManager; //导入依赖的package包/类
/**
* Receives events indicating whether Wifi Direct is enabled or disabled.
*/
private void onWifiP2pStateChanged(Context context, Intent intent) {
// Since int is a simple type, we have to provide a default value
// in case the requested key isn't contained as an extra.
int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE,
DEFAULT_EXTRA_INT);
if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
Log.d(TAG, "Wifi Direct enabled");
// Wifi Direct mode is enabled
// TODO(lerner): Do something since it's enabled?
} else if (state == WifiP2pManager.WIFI_P2P_STATE_DISABLED) {
Log.d(TAG, "Wifi Direct disabled");
// Wifi Direct mode is disabled
// TODO(lerner): Do something since it's disabled?
} else if (state == DEFAULT_EXTRA_INT) {
Log.e(TAG, "Wifi P2P state changed event handled, but the intent " +
"doesn't include an int to tell whether it's enabled or " +
"disabled!");
}
}