Advertisement
Guest User

Untitled

a guest
May 26th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT License. See license.txt in the project root for further information.
  2. package test.microsoft.com.wifitestpower;
  3.  
  4. import android.net.wifi.p2p.WifiP2pManager;
  5. import android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceInfo;
  6. import android.util.Log;
  7.  
  8. import java.util.HashMap;
  9. import java.util.Map;
  10.  
  11. /**
  12.  * Created by juksilve on 28.2.2015.
  13.  */
  14. public class WifiServiceAdvertiser {
  15.  
  16.     private WifiP2pManager p2p;
  17.     private WifiP2pManager.Channel channel;
  18.  
  19.     int lastError = -1;
  20.     public WifiServiceAdvertiser(WifiP2pManager Manager, WifiP2pManager.Channel Channel) {
  21.         this.p2p = Manager;
  22.         this.channel = Channel;
  23.     }
  24.  
  25.     public int GetLastError(){
  26.         return lastError;
  27.     }
  28.     public void Start(String instance,String service_type) {
  29.  
  30.         Map<String, String> record = new HashMap<String, String>();
  31.         record.put("available", "visible");
  32.  
  33.         WifiP2pDnsSdServiceInfo service = WifiP2pDnsSdServiceInfo.newInstance(instance, service_type, record);
  34.  
  35.         debug_print("Add local service :" + instance);
  36.         p2p.addLocalService(channel, service, new WifiP2pManager.ActionListener() {
  37.             public void onSuccess() {
  38.                 lastError = -1;
  39.                 debug_print("Added local service");
  40.             }
  41.  
  42.             public void onFailure(int reason) {
  43.                 lastError = reason;
  44.                 debug_print("Adding local service failed, error code " + reason);
  45.             }
  46.         });
  47.     }
  48.  
  49.     public void Stop() {
  50.         p2p.clearLocalServices(channel, new WifiP2pManager.ActionListener() {
  51.             public void onSuccess() {
  52.                 lastError = -1;
  53.                 debug_print("Cleared local services");
  54.             }
  55.  
  56.             public void onFailure(int reason) {
  57.                 lastError = reason;
  58.                 debug_print("Clearing local services failed, error code " + reason);
  59.             }
  60.         });
  61.     }
  62.  
  63.     private void debug_print(String buffer) {
  64.         Log.i("ACCESS point",buffer);
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement