本文整理汇总了Java中android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceRequest.newInstance方法的典型用法代码示例。如果您正苦于以下问题:Java WifiP2pDnsSdServiceRequest.newInstance方法的具体用法?Java WifiP2pDnsSdServiceRequest.newInstance怎么用?Java WifiP2pDnsSdServiceRequest.newInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceRequest
的用法示例。
在下文中一共展示了WifiP2pDnsSdServiceRequest.newInstance方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addServiceDiscoveryRequest
import android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceRequest; //导入方法依赖的package包/类
private void addServiceDiscoveryRequest() {
serviceRequest = WifiP2pDnsSdServiceRequest.newInstance();
// Tell the framework we want to scan for services. Prerequisite for discovering services
wifiP2pManager.addServiceRequest(channel, serviceRequest, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
Log.i(TAG, "Service discovery request added");
}
@Override
public void onFailure(int reason) {
Log.e(TAG, "Failure adding service discovery request: " + FailureReason.fromInteger(reason).toString());
serviceRequest = null;
}
});
}
示例2: addServiceRequest
import android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceRequest; //导入方法依赖的package包/类
private void addServiceRequest() {
WifiP2pDnsSdServiceRequest request =
WifiP2pDnsSdServiceRequest.newInstance();
final Handler handler = new Handler();
p2p.addServiceRequest(channel, request, new ActionListener() {
public void onSuccess() {
Log.d(TAG, "Added service request");
// Calling discoverServices() too soon can result in a
// NO_SERVICE_REQUESTS failure - looks like a race condition
// http://p2feed.com/wifi-direct.html#bugs
handler.postDelayed(new Runnable() {
public void run() {
startServiceDiscovery();
}
}, 1000);
}
public void onFailure(int reason) {
print("Adding service request failed, error code " + reason);
// No point starting service discovery
}
});
}
示例3: setupDnsSdServiceRequest
import android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceRequest; //导入方法依赖的package包/类
private void setupDnsSdServiceRequest() {
if (serviceRequest == null){
// After attaching listeners, create a service request for the type of service desired
serviceRequest = WifiP2pDnsSdServiceRequest.newInstance();
manager.addServiceRequest(channel, serviceRequest,
new ActionListener() {
public void onSuccess() {
// appendStatus("Added service discovery request");
}
public void onFailure(int reason) {
// appendStatus("Failed adding service discovery request");
}
});
}
}
示例4: setupLocalServiceDiscovery
import android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceRequest; //导入方法依赖的package包/类
/**
* Setups listeners that are called, when a new "susurrus"-service is found.
*/
public void setupLocalServiceDiscovery() {
Log.d(LOG_TAG, "Setup discovering rooms.");
wifiDirectManager.setDnsSdResponseListeners(wifiDirectChannel, servListener, txtListener);
// get an instance of the WifiP2P service request object
WifiP2pDnsSdServiceRequest roomRequest = WifiP2pDnsSdServiceRequest.newInstance();
// add a service discovery request
wifiDirectManager.addServiceRequest(wifiDirectChannel, roomRequest,
new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
// Success!
Log.d(LOG_TAG, "... wifiDirectManager.addServiceRequest success ...");
discoverLocalServices();
}
@Override
public void onFailure(int code) {
// Command failed. Check for P2P_UNSUPPORTED, ERROR, or BUSY
Log.d(LOG_TAG, "addServiceRequest error: " + code);
}
}
);
}
示例5: NFGame
import android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceRequest; //导入方法依赖的package包/类
public NFGame(Context context, NFGameNotifyListener nFGameNotifyListener) {
mContext = context;
mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
mWifiP2pManager = (WifiP2pManager) mContext.getSystemService(Context.WIFI_P2P_SERVICE);
mChannel = mWifiP2pManager.initialize(mContext, mContext.getMainLooper(), null);
mNFGameNotifyListener = nFGameNotifyListener;
mNFGameBroadcastReceiver = new NFGameBroadcastReceiver();
mNFGameDnsSdServiceResponseListener = new NFGameDnsSdServiceResponseListener();
try {
ApplicationInfo appInfo = mContext.getPackageManager().getApplicationInfo(mContext.getPackageName(), 0);
appLabel = mContext.getPackageManager().getApplicationLabel(appInfo).toString();
} catch (NameNotFoundException e) {
// e.printStackTrace();
}
serviceType = mContext.getPackageName();
mWifiP2pDnsSdServiceInfo = WifiP2pDnsSdServiceInfo.newInstance(appLabel, serviceType, null);
mWifiP2pDnsSdServiceRequest = WifiP2pDnsSdServiceRequest.newInstance();
mHandler = new Handler();
mDiscoveryingRunnable = new Runnable() {
@Override
public void run() {
discoverPeers();
}
};
peers = new ArrayList<WifiP2pDevice>();
servicePeers = new ArrayList<WifiP2pDevice>();
}
示例6: init
import android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceRequest; //导入方法依赖的package包/类
public void init (GilgaService service)
{
mService = service;
mWifiManager = (WifiP2pManager) mService.getSystemService(Context.WIFI_P2P_SERVICE);
mWifiChannel = mWifiManager.initialize(mService, mService.getMainLooper(), new ChannelListener()
{
@Override
public void onChannelDisconnected() {
Log.d(GilgaService.TAG,"wifi p2p disconnected");
}
});
WifiP2pDnsSdServiceRequest serviceRequest = WifiP2pDnsSdServiceRequest.newInstance();
mWifiManager.addServiceRequest(mWifiChannel,
serviceRequest,
new ActionListener() {
@Override
public void onSuccess() {
// Success!
Log.d(TAG,"SUCCESS: added service request wifi name service");
}
@Override
public void onFailure(int code) {
// Command failed. Check for P2P_UNSUPPORTED, ERROR, or BUSY
Log.d(TAG,"FAILURED: added service request wifi name service: " + code);
}
});
}
示例7: initPeersDiscovery
import android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceRequest; //导入方法依赖的package包/类
private void initPeersDiscovery() {
WifiP2pDnsSdServiceRequest serviceRequest = WifiP2pDnsSdServiceRequest.newInstance("run2gether", "presence");
p2pManager.addServiceRequest(p2pChannel, serviceRequest,
new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
Log.d(TAG, "success");
}
@Override
public void onFailure(int code) {
// Command failed. Check for P2P_UNSUPPORTED, ERROR, or BUSY
}
});
WifiP2pManager.DnsSdTxtRecordListener txtListener = new WifiP2pManager.DnsSdTxtRecordListener() {
@Override
public void onDnsSdTxtRecordAvailable(String fullDomain, Map<String, String> userAttribMap, WifiP2pDevice device) {
final WDSwanDevice nearbyUser = new WDSwanDevice(userAttribMap.get("name"), userAttribMap.get("regId"), device);
if (!hasPeer(nearbyUser.getUsername())) {
addPeer(nearbyUser);
slpActivity.getNearbyPeersAdapter().notifyDataSetChanged();
Log.d(TAG, "Found new nearby user " + nearbyUser);
} else {
if (updatePeer(nearbyUser)) {
log("Updated nearby user " + nearbyUser, true);
}
}
}
};
WifiP2pManager.DnsSdServiceResponseListener servListener = new WifiP2pManager.DnsSdServiceResponseListener() {
@Override
public void onDnsSdServiceAvailable(String instanceName, String registrationType, WifiP2pDevice resourceType) {
// nothing to do here
Log.d(TAG, "onBonjourServiceAvailable " + instanceName);
}
};
p2pManager.setDnsSdResponseListeners(p2pChannel, servListener, txtListener);
nearbyPeersChecker.run();
}
示例8: discoverServices
import android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceRequest; //导入方法依赖的package包/类
private void discoverServices() {
WifiP2pManager.DnsSdTxtRecordListener txtListener = new WifiP2pManager.DnsSdTxtRecordListener() {
@Override
/* Callback includes:
* fullDomain: full domain name: e.g "printer._ipp._tcp.local."
* record: TXT record dta as a map of key/value pairs.
* device: The device running the advertised service.
*/
public void onDnsSdTxtRecordAvailable(
String fullDomain, Map record, WifiP2pDevice device) {
Log.d(TAG, "DnsSdTxtRecord available -" + record.toString());
//buddies.put(device.deviceAddress, (String)record.get("buddyname"));
// Add to the custom adapter defined specifically for showing
// wifi devices
connectToDevice(device);
}
};
WifiP2pManager.DnsSdServiceResponseListener servListener = new WifiP2pManager.DnsSdServiceResponseListener() {
@Override
public void onDnsSdServiceAvailable(String instanceName, String registrationType,
WifiP2pDevice resourceType) {
// Update the device name with the human-friendly version from
// the DnsTxtRecord, assuming one arrived.
resourceType.deviceName = buddies
.containsKey(resourceType.deviceAddress) ? buddies
.get(resourceType.deviceAddress) : resourceType.deviceName;
// Add to the custom adapter defined specifically for showing
// wifi devices.
Log.d(TAG, "onBonjourServiceAvailable " + instanceName);
}
};
manager.setDnsSdResponseListeners(channel, servListener, txtListener);
WifiP2pDnsSdServiceRequest serviceRequest = WifiP2pDnsSdServiceRequest.newInstance();
manager.addServiceRequest(channel,
serviceRequest,
new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
Log.v(TAG, "Suggesfully added a servicerequest");
}
@Override
public void onFailure(int reason) {
Log.e(TAG, "Failed to add servicerequest");
}
});
}
示例9: discover
import android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceRequest; //导入方法依赖的package包/类
@Override
public void discover() {
mP2PManager.setDnsSdResponseListeners(mChannel, mDnsListener, mDnsTxtRecordListener);
mServiceRequest = WifiP2pDnsSdServiceRequest.newInstance();
mP2PManager.addServiceRequest(mChannel, mServiceRequest, mServiceAddListener);
}