List of usage examples for android.net.wifi.p2p WifiP2pManager getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:org.physical_web.physicalweb.FileBroadcastService.java
private void changeWifiName() { String deviceName = "PW-" + mTitle + "-" + mPort; if (deviceName.length() > MAX_DEVICE_NAME_LENGTH) { deviceName = DEFAULT_DEVICE_NAME + mPort; }/*from w w w .j a v a 2 s. com*/ try { WifiP2pManager manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE); WifiP2pManager.Channel channel = manager.initialize(this, getMainLooper(), null); Class[] paramTypes = new Class[3]; paramTypes[0] = WifiP2pManager.Channel.class; paramTypes[1] = String.class; paramTypes[2] = WifiP2pManager.ActionListener.class; Method setDeviceName = manager.getClass().getMethod("setDeviceName", paramTypes); setDeviceName.setAccessible(true); Object arglist[] = new Object[3]; arglist[0] = channel; arglist[1] = deviceName; arglist[2] = new WifiP2pManager.ActionListener() { @Override public void onSuccess() { Log.d(TAG, "setDeviceName succeeded"); } @Override public void onFailure(int reason) { Log.d(TAG, "setDeviceName failed"); } }; setDeviceName.invoke(manager, arglist); } catch (NoSuchMethodException e) { Log.d(TAG, e.getMessage()); } catch (IllegalAccessException e) { Log.d(TAG, e.getMessage()); } catch (IllegalArgumentException e) { Log.d(TAG, e.getMessage()); } catch (InvocationTargetException e) { Log.d(TAG, e.getMessage()); } }