I was wondering if anybody could shed some light on an issue regarding WifiP2pDevice's name field.
As you may already know, WifiP2pDevice has a devicename field, but no methods to "set" the devicename, only to read it.
As discussed in this post: How change the device name in WiFi direct p2p?
It may be possible to set the device's name via reflection. I know it is bad custom, but since the API doesn't support this and I need this functionality in my application, how would I go about doing this?
As of now, my code:
try
{
WifiP2pDevice device = new WifiP2pDevice();//create a temporary device to call the setDeviceName method on
method = device.getClass().getMethod("setDeviceName", new Class[] { WifiP2pManager.Channel.class, String.class,
WifiP2pManager.ActionListener.class });
method.invoke(myManager, myChannel, getIntent().getStringExtra(NETWORK_NAME));
Toast.makeText(this, "Name set successful", Toast.LENGTH_SHORT).show();
}
Currently, the application gets to this point and returns a NoSuchMethodException, implying that the setDeviceName does not exist. Any help/alternatives on java reflection?
Aucun commentaire:
Enregistrer un commentaire