Skip to content

Instantly share code, notes, and snippets.

@aslamanver
Last active August 14, 2020 11:12
Show Gist options
  • Save aslamanver/39aa668b3073bc4f52aeb09b5a7ea3be to your computer and use it in GitHub Desktop.
Save aslamanver/39aa668b3073bc4f52aeb09b5a7ea3be to your computer and use it in GitHub Desktop.
Changing WifiDirect Name - Android Java
public void setDeviceName(String devName) {
try {
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] = devName;
arglist[2] = new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
updateLog("setDeviceName: onSuccess");
}
@Override
public void onFailure(int reason) {
updateLog("setDeviceName: onSuccess");
}
};
setDeviceName.invoke(manager, arglist);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment