Googleで検索しました。Android2.2およびsdk8では、AndroidのリストでSSIDを使用するにはどうすればよいですか?
SSIDを使用することにより、プログラムによって特定のWi-Fi対応デバイスのプロパティを取得する必要があります。その助けを借りて、Androidの2つのWifi対応デバイス間でデータを転送する必要があります。
Googleで検索しました。Android2.2およびsdk8では、AndroidのリストでSSIDを使用するにはどうすればよいですか?
SSIDを使用することにより、プログラムによって特定のWi-Fi対応デバイスのプロパティを取得する必要があります。その助けを借りて、Androidの2つのWifi対応デバイス間でデータを転送する必要があります。
2つのAndroidデバイス間で意味のある方法でデータを送信するには、TCP接続を使用します。これを行うには、他のデバイスがリッスンしているIPアドレスとポートが必要です。
例はここから取られています。
サーバー側(リスニング側)には、サーバーソケットが必要です。
try {
Boolean end = false;
ServerSocket ss = new ServerSocket(12345);
while(!end){
//Server is waiting for client here, if needed
Socket s = ss.accept();
BufferedReader input = new BufferedReader(new InputStreamReader(s.getInputStream()));
PrintWriter output = new PrintWriter(s.getOutputStream(),true); //Autoflush
String st = input.readLine();
Log.d("Tcp Example", "From client: "+st);
output.println("Good bye and thanks for all the fish :)");
s.close();
if ( STOPPING conditions){ end = true; }
}
ss.close();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
クライアント側には、サーバーソケットに接続するソケットが必要です。「localhost」をリモートAndroidデバイスのIPアドレスまたはホスト名に置き換えてください。
try {
Socket s = new Socket("localhost",12345);
//outgoing stream redirect to socket
OutputStream out = s.getOutputStream();
PrintWriter output = new PrintWriter(out);
output.println("Hello Android!");
BufferedReader input = new BufferedReader(new InputStreamReader(s.getInputStream()));
//read line(s)
String st = input.readLine();
//. . .
//Close connection
s.close();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}