Research Article

Profile-Based Ad Hoc Social Networking Using Wi-Fi Direct on the Top of Android

Algorithm 1

// MainActivity.java
public void startOffatAddListener () {
startOffat.setOnClickListener ( new
 View.OnClickListener () {
@Override
public void onClick (View v) {
WifiManager wifi = (WifiManager)
 getApplicationContext ().getSystemService (Context.WIFI_SERVICE);
wifi.reconnect ();
if (!e1.getText ().toString ().equals (””) &&
 !e2.getText ().toString ().equals (””)) {
GlobalData.name = e1.getText ().toString ();
GlobalData.interests =
 e2.getText ().toString ().replaceAll (”\\s+”,”,”).replaceAll (”,+”,”,”);
Intent intent = new Intent (v.getContext (),
 WiFiDirectActivity.class);
startActivity (intent);
}
}
} );
}
// WiFiDirectActivity.java
public void setNameInterests () {
try {
Method method =
 manager.getClass ().getMethod (”setDeviceName”,
WifiP2pManager.Channel.class, String.class,
 WifiP2pManager.ActionListener.class);
method.invoke ( manager, channel,
 GlobalData.name+”#”+GlobalData.interests,
 new WifiP2pManager.ActionListener () {
public void onSuccess () {}
public void onFailure (int reason) {}
} );
} catch (Exception e) {
Toast.makeText (getApplicationContext (),”Unable
 send User name and
 Interests”,Toast.LENGTH_SHORT).show ();
}
}