TechInstitute_Vol6_063-129_Chap14_fix.indd



Similar documents
TechInstitute_Vol7_Chap17_fix.indd

Vuzix M100 SDKインストールガイド

Tech2_Vol6_Chap15_3kou.indd

HTTPの 規 格

¥Í¥Ã¥È¥ï¡¼¥¯¥×¥í¥°¥é¥ß¥ó¥°ÆÃÏÀ

/03/26 2

55 7 Java C Java TCP/IP TCP/IP TCP TCP_RO.java import java.net.*; import java.io.*; public class TCP_RO { public static void main(string[] a


「Android Studioではじめる 簡単Androidアプリ開発」正誤表

Java演習(4) -- 変数と型 --

HTTP Web Web RFC2616 HTTP/1.1 Web Apache Tomcat (Servlet ) XML Xindice Tomcat 6-2


補足資料 キーイベント処理サンプル package jp.co.keyevent; import android.app.activity; import android.os.bundle; import android.view.keyevent; import android.widget.t

新・明解Java入門

MOVERIO Pro BT-2000/2200 デベロッパーズガイド 自己診断機能&GPSアシスト

ALG ppt

日 用 用 面 示 用 用 方

untitled

そして 取得した OutputStream インスタンスを使い 文字コードは UTF-8 として PrintWriter インスタンスを生成して あとは PrintWriter.append() で書き込みたい文字 列を渡して close() で保存する というだけです ファイルの読込み方法 それで

Servlet JSP JSP Servlet/JSP における 日 本 語 の 処 理 - 1

android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> <Button android:text="go"

JAVA H13 OISA JAVA 1

1: Android 2 Android 2.1 Android 4 Activity Android Service ContentProvider BroadcastReceiver Activity ( ): Android 1 Android Service ( ): ContentProv

1: Preference Display 1 package sample. pref ; 2 3 import android. app. Activity ; 4 import android. content. Intent ; 5 import android. content. Shar

Java (9) 1 Lesson Java System.out.println() 1 Java API 1 Java Java 1

0序文‐1章.indd

Microsoft Word - BLEBluetooth Low Energy.docx

やさしいJavaプログラミング -Great Ideas for Java Programming サンプルPDF

ict7.key

Web のクライアントサーバモデル

PowerPoint Presentation

Condition DAQ condition condition 2 3 XML key value

LogisticaTRUCKServer-Ⅱ距離計算サーバ/Active-Xコントロール/クライアント 概略   

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

Android プログラム ガイド

●70974_100_AC009160_KAPヘ<3099>ーシス自動車約款(11.10).indb

Web Servlet/JSP JSP

日 力力 生 行行 入 入 力力 生 用 方

PowerPoint プレゼンテーション

untitled

5110-toku4-2c.indd

TechInstituteセキュリティ1日目.key

Part1 159 a a

Microsoft Word - Android_SQLite講座_画面800×1280

Quick Sort 計算機アルゴリズム特論 :2017 年度 只木進一

II 1 p.1 1 Servlet 1.1 Web Web WWW HTML CGI Common Gateway Interface Web HTML Web Web CGI CGI CGI Perl, PHP C JavaScript Web CGI HTML 1.2 Servlet Java

2 // TODO Auto-generated method stub float x = event.getx(); float y = event.gety(); String action = ""; switch(event.getaction()) { case MotionEvent.

インターネットマガジン2001年4月号―INTERNET magazine No.75

B 26 OS

解きながら学ぶJava入門編

コーディング基準.PDF

A B 1: Ex. MPICH-G2 C.f. NXProxy [Tanaka] 2:

HTML Java Tips dp8t-asm/java/tips/ Apache Tomcat Java if else f

Microsoft Word - _Intent.doc

Copyright 2006 Mitsui Bussan Secure Directions, Inc. All Rights Reserved. 3 Copyright 2006 Mitsui Bussan Secure Directions, Inc. All Rights Reserved.

(Eclipse\202\305\212w\202\324Java2\215\374.pdf)

CodeIgniter Con 2011, Tokyo Japan, February


コンテンツキャッシュを活用してWebサーバーの負荷を下げたい:IDCFクラウド活用マニュアル

エラー処理・分割コンパイル・コマンドライン引数

Client client = ClientBuilder.newClient(); WebTarget webtarget = client.target(" " "); Invo

java_servlet2_見本

Web 1 p.2 1 Servlet Servlet Web Web Web Apache Web Servlet JSP Web Apache Tomcat Jetty Apache Tomcat, Jetty Java JDK, Eclipse

第168回日本胸部外科学会関東甲信越地方会要旨集

変 更 履 歴 Biz メール SSO 連 携 サービス IF 仕 様 書 変 更 年 月 変 更 内 容 新 規 作 成 ii


android2.indd


ALG ppt

HTML Java Tips dp8t-asm/java/tips/ Apache Tomcat Java if else f

…l…b…g…‘†[…N…v…“…O…›…~…fi…OfiÁŸ_

コンテントネゴシエーション

1. URL (Uniform Resource Locator) n プロトコル (http, https, ftp, mailto) 2. ドメイン 名 (FQDN) ホストの 識

IIJ Technical WEEK REST API型クラウドストレージサービス「FV/S」の自社への実装

IP L09( Tue) : Time-stamp: Tue 14:52 JST hig TCP/IP. IP,,,. ( ) L09 IP (2017) 1 / 28

Exam : 1z1-809-JPN Title : Java SE 8 Programmer II Vendor : Oracle Version : DEMO Get Latest & Valid 1z1-809-JPN Exam's Question and Answers 1 from Ac

IE6 2 BMI chapter1 Java 6 chapter2 Java 7 chapter3 for if 8 chapter4 : BMI 9 chapter5 Java GUI 10 chapter6 11 chapter7 BMI 12 chap

TM-T88VI 詳細取扱説明書

Do No Track 実装ガイド

<4D F736F F D20566F F6E658C6791D FE382C582CC4A D834F E F8F4390B394C52E646F63>

アルゴリズムとデータ構造1

/ ( ) 8/7/ :21 p.2/64

About me! 足立昌彦 / +Masahiko.Adachi )! バイドゥ株式会社技術顧問 (Simeji)! 株式会社カブク Co-Founder! Google Developer Expert (Android)

226

PowerPoint Presentation

K227 Java 2

玉転がしタブレット端末の特徴の一つとして, センサを使った動作や, 指による画面操作がある. それらを活用して, 図形を動かすアプリの例を示す. 1. プロジェクトを作る Tama アプリケーションを作る,Tama プロジェクトを作る. 図 1 プロジェクト作成 プロジェクトの構成を設定する. 図

P00表紙.ai

SystemC言語概論

fp.gby

Oracle9i JDeveloperによるWebサービスの構築

B 10 : N ip2003f10.tex B : 9/12/ :02 p.1/71

Network Programming

Q&A集

!!!!!

vol.30.}...`.X...b.h

Android osの歴史 1.6から2.3まで携帯のみ 3.0 タブレットのみ 4.0 タブレットで培ったUIなど の技術を携帯でも 使えるとうにと APIなんかが統合された

授業内容 センサーとは何かおさらい MEMS フレームワークとは何か? を理理解する 演習 センサーのフレームワークを理理解する Androidで使 用できるセンサーの種類 センサーを使ってみる

TM-m30 詳細取扱説明書

ファイルを直接編集する画面を切り替えることができる. 図 3 標準のレイアウトを削除する (2) グラフィカル レイアウト画面で LinearLayout(Vertical) を追加するパレットウィンドウの レイアウト の中にある LinearLayout(Vertical) をドラッグして, 編集

Transcription:

14-1 64

14-1-1 14-1-2 65

IP(Windows) > ipconfig 6.2: IP(OSX, Linux) > ifconfig 14-1-3 66

nslookup nslookup $ nslookup tomorrowkey.jp Server: 220.159.212.200 Address: 220.159.212.200#53 Non-authoritative answer: Name: tomorrowkey.jp Address: 49.212.164.150 14-1-4 GET / HTTP/1.0 User-Agent: Mozilla/5.0 (Linux; Android 4.3; Build/LPV79) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.94 Mobile Safari/537.36 Host: tomorrowkey.jp 67

HTTP/1.1 200 OK Date: Sun, 13 Jul 2014 06:20:10 GMT Server: Apache/2.2.15 (CentOS) Last-Modified: Sat, 07 Jun 2014 14:29:18 GMT ETag: "26133e-f3-4fb3fcdaabf43" Accept-Ranges: bytes Content-Length: 243 Connection: close Content-Type: text/html <html> <head> <title>hello, Tomorrow!</title> </head> <body> <h1>hello, Tomorrow!</h1> </body> </html> 68

14-1-5 14-1-6 69

70

TelnetHTTP GET / HTTP/1.1 Host: tomorrowkey.jp User-Agent: telnet 71

TelnetHTTP HTTP/1.1 200 OK Date: Fri, 05 Sep 2014 05:24:41 GMT Server: Apache/2.2.15 (CentOS) Last-Modified: Sat, 07 Jun 2014 14:29:18 GMT ETag: "26133e-f3-4fb3fcdaabf43" Accept-Ranges: bytes Content-Length: 243 Content-Type: text/html <html> <head> <title>hello, Tomorrow!</title> </head> <body> <h1>hello, Tomorrow!</h1> </body> </html> 72

14-2 73

14-2 -1 <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.sample.network"> <uses-permission android:name="android.permission.internet" /> <application 74

14-2 -2 14-2 -3 75

14-2 -4 76

14-2 -5 77

Socket try { // Socket socket = new Socket(); 1 socket.connect(new InetSocketAddress("tomorrowkey.github.io", 80)); 2 String request = "GET / HTTP/1.1\n" + "Host: tomorrowkey.github.io\n" + "\n\n"; OutputStream outputstream = socket.getoutputstream(); outputstream.write(request.getbytes()); outputstream.flush(); 3 // InputStream inputstream = socket.getinputstream(); byte[] buffer = new byte[1024]; int length; while ((length = inputstream.read(buffer))!= -1) { Log.d("TEST", new String(buffer, 0, length)); 4 outputstream.close(); inputstream.close(); catch (UnknownHostException e) { throw new RuntimeException(e); catch (IOException e) { throw new RuntimeException(e); 5 1 2 3 78

GET GET / HTTP/1.1 Host: tomorrowkey.github.io "" "" GET / HTTP/1.1 Host: tomorrowkey.github.io 4 InputStream inputstream = socket.getinputstream(); byte[] buffer = new byte[1024]; int length; while ((length = inputstream.read(buffer))!= -1) { Log.d("TEST", new String(buffer, 0, length)); 5 79

Socket D/TEST ( 1371): HTTP/1.1 200 OK D/TEST ( 1371): Server: GitHub.com D/TEST ( 1371): Content-Type: text/html; charset=utf-8 D/TEST ( 1371): Last-Modified: Mon, 02 Jan 2012 05:54:49 GMT D/TEST ( 1371): Expires: Mon, 30 Jun 2014 11:37:13 GMT D/TEST ( 1371): Cache-Control: max-age=600 D/TEST ( 1371): Content-Length: 169 D/TEST ( 1371): Accept-Ranges: bytes D/TEST ( 1371): Date: Mon, 30 Jun 2014 12:24:02 GMT D/TEST ( 1371): Via: 1.1 varnish D/TEST ( 1371): Age: 3409 D/TEST ( 1371): Connection: keep-alive D/TEST ( 1371): X-Served-By: cache-ty66-tyo D/TEST ( 1371): X-Cache: MISS D/TEST ( 1371): X-Cache-Hits: 0 D/TEST ( 1371): X-Timer: S1404131042.773465872,VS0,VE174 D/TEST ( 1371): Vary: Accept-Encoding D/TEST ( 1371): D/TEST ( 1371): <html> D/TEST ( 1371): <!DOCTYPE html> D/TEST ( 1371): <html lang="ja"> D/TEST ( 1371): <head> D/TEST ( 1371): <title>tomorrowkey GitHub page</title> D/TEST ( 1371): <meta charset="utf-8" /> D/TEST ( 1371): </head> D/TEST ( 1371): <body> D/TEST ( 1371): <h1>hello, tomorrow!!</h1> D/TEST ( 1371): </body> D/TEST ( 1371): </html> 14-2 -6 80

HttpURLConnection try { URL url = new URL("http://tomorrowkey.github.io"); 1 HttpURLConnection connection = (HttpURLConnection) url.openconnection(); connection.setrequestmethod("get"); 3 connection.setrequestproperty("host", "tomorrowkey.github.io"); connection.connect(); 4 int responsecode = connection.getresponsecode(); 5 Log.d("TEST", "responsecode=" + responsecode); String contentlength = connection.getheaderfield("content-length"); Log.d("TEST", "Content-Length=" + contentlength); 6 String contenttype = connection.getheaderfield("content-type"); Log.d("TEST", "contenttype=" + contenttype); InputStream inputstream = connection.getinputstream(); byte[] buffer = new byte[1024]; int length; 7 while ((length = inputstream.read(buffer))!= -1) { Log.d("TEST", new String(buffer, 0, length)); inputstream.close(); catch (MalformedURLException e) { throw new RuntimeException(e); catch (IOException e) { throw new RuntimeException(e); 2 1 2 3 4 5 81

6 7 HttpURLConnection D/TEST ( 1231): responsecode=200 D/TEST ( 1231): Content-Length=null D/TEST ( 1231): contenttype=text/html; charset=utf-8 D/TEST ( 1231): body=<html> D/TEST ( 1231): <!DOCTYPE html> D/TEST ( 1231): <html lang="ja"> D/TEST ( 1231): <head> D/TEST ( 1231): <title>tomorrowkey GitHub page</title> D/TEST ( 1231): <meta charset="utf-8" /> D/TEST ( 1231): </head> D/TEST ( 1231): <body> D/TEST ( 1231): <h1>hello, tomorrow!!</h1> D/TEST ( 1231): </body> D/TEST ( 1231): </html> 14-2 - 82

HttpClient try { HttpGet httpget = new HttpGet("http://tomorrowkey.github.io"); httpget.addheader("host", "tomorrowkey.github.io"); 2 HttpClient httpclient = new DefaultHttpClient(); 3 1 HttpResponse httpresponse = httpclient.execute(httpget); 4 StatusLine statusline = httpresponse.getstatusline(); Log.d("TEST", "Status-Code=" + statusline.getstatuscode()); Header contentlengthheader = httpresponse.getfirstheader("content-length"); Log.d("TEST", "Content-Length=" + contentlengthheader.getvalue()); Header contenttypeheader = httpresponse.getfirstheader("content-type"); Log.d("TEST", "Content-Type=" + contenttypeheader.getvalue()); InputStream inputstream = httpresponse.getentity().getcontent(); String body = readtoend(inputstream); Log.d("TEST", body); inputstream.close(); catch (MalformedURLException e) { throw new RuntimeException(e); catch (IOException e) { throw new RuntimeException(e); 1 2 3 4 83

HTTP/1.1 200 OK Header contentlengthheader = httpresponse.getfirstheader("content-length"); Log.d("TEST", "Content-Length=" + contentlengthheader.getvalue()); Header contenttypeheader = httpresponse.getfirstheader("content-type"); Log.d("TEST", "Content-Type=" + contenttypeheader.getvalue()); InputStream inputstream = httpresponse.getentity().getcontent(); String body = readtoend(inputstream); Log.d("TEST", body); inputstream.close(); HttpClient D/TEST ( 1295): Status-Code=200 D/TEST ( 1295): Content-Length=169 D/TEST ( 1295): Content-Type=text/html; charset=utf-8 D/TEST ( 1295): <html> D/TEST ( 1295): <!DOCTYPE html> D/TEST ( 1295): <html lang="ja"> D/TEST ( 1295): <head> D/TEST ( 1295): <title>tomorrowkey GitHub page</title> D/TEST ( 1295): <meta charset="utf-8" /> D/TEST ( 1295): </head> D/TEST ( 1295): <body> D/TEST ( 1295): <h1>hello, tomorrow!!</h1> D/TEST ( 1295): </body> D/TEST ( 1295): </html> 84

85

14-3 14-3 -1 86

XML <?xml version="1.0" encoding="utf-8"?> <school> <count>2</count> 1 <students> <student age="18" gender="male">taro Yamada</student> 2 <student age="19" gender="female">hanako Tanaka</student> </students> </school> < > 1 < > <>< > 2 """" 87

JSON { "students":[ { "age":"18", "gender":"male", "name":"taro Yamada" 1 ], { "age":"19", "gender":"female", "name":"hnaako Tanaka" 2 1 2 14-3 -2 88

14-3 -3 http://www.social-ime.com/api/?string= 89

Social IME try { String keyword = params[0]; URL url = new URL("http://www.social-ime.com/api/?string=" + keyword); HttpURLConnection connection = (HttpURLConnection) url.openconnection(); connection.connect(); InputStream inputstream = connection.getinputstream(); StringBuilder sb = new StringBuilder(); int length; byte[] buffer = new byte[1024]; while ((length = inputstream.read(buffer))!= -1) { sb.append(new String(buffer, 0, length, "EUC-JP")); return sb.tostring(); catch (IOException e) { throw new RuntimeException(e); "" 14-3 -4 90

91

API mrequestqueue = Volley.newRequestQueue(getApplicationContext()); 1 int method = Request.Method.GET; String url = "https://raw.githubusercontent.com/techbooster/ AndroidOpenTextbook/master/code/network/assets/sample.json"; JSONObject requestbody = null; Response.Listener<JSONObject> listener = new Response.Listener<JSONObject>() { @Override public void onresponse(jsonobject jsonobject) { Log.d("TEST", jsonobject.tostring()); ; Response.ErrorListener errorlistener = new Response.ErrorListener() { @Override public void onerrorresponse(volleyerror volleyerror) { 3 String message = volleyerror.getmessage(); Log.d("TEST", message); ; 2 mrequestqueue.add(new JsonObjectRequest(method, url, requestbody, listener, errorlistener)); 1 method url requestbody listener errorlistener 92

2 @Override public void onresponse(jsonobject jsonobject) { Log.d("TEST", jsonobject.tostring()); D/TEST ( 1699): {"users":[ {"id":1,"gender":"female","name":"alice", {"id":2,"gender":"male","name":"bob"] 3 @Override public void onerrorresponse(volleyerror volleyerror) { NetworkResponse networkresponse = volleyerror.networkresponse; int statuscode = networkresponse.statuscode; Log.d("TEST", "Status-Code=" + statuscode); String contentlength = networkresponse.headers.get("content-length"); Log.d("TEST", "Content-Length=" + contentlength); String body = new String(networkResponse.data); Log.d("TEST", body); 93

D/TEST D/TEST D/TEST D/TEST ( 1654): Status-Code=404 ( 1654): Content-Length=9 ( 1654): Content-Type=null ( 1654): Not Found 94

95

14-4 96

14-4 -1 97

14-4 -2 <> 98

14-4 -3 Bluetooth BluetoothAdapter btadapter = BluetoothAdapter.getDefaultAdapter(); // btadapter nullbluetooth if(btadapter == null){ // return; if (!btadapter.isenabled()) { // BluetoothOFF // Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startactivityforresult(intent, REQUEST_BT_ENABLE); // REQUEST_BT_ENABLE"0" 99

14-4 -4 BluetoothAdapter btadapter = BluetoothAdapter.getDefaultAdapter(); if (btadapter.isdiscovering()) { // btadapter.canceldiscovery(); btadapter.startdiscovery(); BroadcastReceiver IntentFilter filter = new IntentFilter(); filter.addaction(bluetoothadapter.action_discovery_finished); filter.addaction(bluetoothdevice.action_found); // mreceiverbroadcastreceiver registerreceiver(mreceiver, filter); // BroadcastReceiveronReceive public void onreceive(context context, Intent intent) { String action = intent.getaction(); if (BluetoothDevice.ACTION_FOUND.equals(action)) { BluetoothDevice device = intent.getparcelableextra(bluetoothdevice.extra_device); // BluetoothDevice : else if(bluetoothadapter.action_discovery_finished.equals(action)) { // : ; 100

14-4 -5 "" BluetoothAdapter btadapter = BluetoothAdapter.getDefaultAdapter(); Set<BluetoothDevice> bondeddevices = btadapter.getbondeddevices(); BluetoothDevice device; for (BluetoothDevice bluetoothdevice : bondeddevices) { if (bluetoothdevice.getname().equals(sampledevice)) { device = bluetoothdevice; break; 101

14-4 -6 devicespp BluetoothSocket socket = device.createrfcommsockettoservicerecord( UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")); //SPPUUID socket.connect();// InputStream in= socket.getinputstream();// // InputStream OutputStream out= socket.getoutputstream();// // OutputStreamwrite "" 102

14-4 -7 Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE); intent.putextra(bluetoothadapter.extra_discoverable_duration, 300); startactivityforresult(intent, REQUEST_BT_DISCOVERABLE); // REQUEST_BT_DISCOVERABLE"1" 103

SCAN_MODE_CONNECTABLE_DISCOVERABLE SCAN_MODE_CONNECTABLE SCAN_MODE_NONE 14-4 -8 BluetoothAdapter btadapter = BluetoothAdapter.getDefaultAdapter(); BluetoothServerSocket serversocket = btadapter.listenusingrfcommwithservicerecord("sampleserverconn", UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")); BluetoothSocket socket = serversocket.accept(); if (socket!= null) { // // : serversocket.close() 104

14-4 -9 105

BluetoothProfile.ServiceListener private BluetoothHeadset mbluetoothheadset; // HSP private BluetoothA2dp mbluetootha2dp; // A2DP private BluetoothHealth mbluetoothhealth; // HDP private BluetoothProfile.ServiceListener mprofilelistener = new BluetoothProfile.ServiceListener() { @Override public void onserviceconnected(int profile, BluetoothProfile proxy) { // BluetoothAdapter // BluetoothProfile // if (profile == BluetoothProfile.HEADSET) { mbluetoothheadset = (BluetoothHeadset) proxy; else if (profile == BluetoothProfile.A2DP) { mbluetootha2dp = (BluetoothA2dp) proxy; else if (profile == BluetoothProfile.HEALTH) { mbluetoothhealth= (BluetoothHealth) proxy; // BluetoothDevice List<BluetoothDevice> devices = proxy.getconnecteddevices(); // BluetoothDevice // MAC @Override public void onservicedisconnected(int profile) { // BluetoothAdapter // // if (profile == BluetoothProfile.HEADSET) { mbluetoothheadset = null; else if (profile == BluetoothProfile.A2DP) { mbluetootha2dp = null; else if (profile == BluetoothProfile.HEALTH) { 106

; mbluetoothhealth = null; // BluetoothAdapterServiceListener BluetoothAdapter mbluetoothadapter = BluetoothAdapter.getDefaultAdapter(); mbluetoothadapter.getprofileproxy(this, mprofilelistener, BluetoothProfile.HEADSET); //HSP mbluetoothadapter.getprofileproxy(this, mprofilelistener, BluetoothProfile.A2DP); //A2DP mbluetoothadapter.getprofileproxy(this, mprofilelistener, BluetoothProfile.HEALTH); // HDP ACTION_AUDIO_STATE_CHANGED ACTION_CONNECTION_STATE_CHANGED HSP ACTION_VENDOR_SPECIFIC_HEADSET_EVENT 107

ACTION_CONNECTION_STATE_CHANGED ACTION_PLAYING_STATE_CHANGED IntentFilter filter = new IntentFilter(); filter.addaction(bluetootha2dp.action_connection_state_changed); filter.addaction(bluetootha2dp.action_playing_state_changed); registerreceiver(mreceiver, filter); private BroadcastReceiver mreceiver = new BroadcastReceiver() { @Override public void onreceive(context context, Intent intent) { String action = intent.getaction(); // int status = intent.getintextra(bluetoothprofile.extra_state, -1); // int prevstatus = intent.getintextra(bluetoothprofile.extra_previous_state, -1); // Bluetooth BluetoothDevice device = intent.getparcelableextra(bluetoothdevice.extra_device); ; // if (action.equals(bluetootha2dp.action_connection_state_changed)) { switch (status){ case BluetoothProfile.STATE_CONNECTED: // : case BluetoothProfile.STATE_DISCONNECTED: // : case BluetoothProfile.STATE_DISCONNECTING: // : 108

APP_CONFIG_REGISTRATION_SUCCESS APP_CONFIG_REGISTRATION_FAILURE APP_CONFIG_UNREGISTRATION_SUCCESS APP_CONFIG_UNREGISTRATION_FAILURE STATE_CHANNEL_CONNECTING STATE_CHANNEL_CONNECTED STATE_CHANNEL_DISCONNECTING STATE_CHANNEL_DISCONNECTED 109

Bluetooth private BluetoothHealthAppConfiguration mhealthconfig; private int mchannelid; private BluetoothDevice mbluetoothdevice; class MyBluetoothHealthCallback extends BluetoothHealthCallback { @Override public void onhealthappconfigurationstatuschange( BluetoothHealthAppConfiguration config, int status) { super.onhealthappconfigurationstatuschange(config, status); // mhealthconfig = config; : @Override public void onhealthchannelstatechange( BluetoothHealthAppConfiguration config, BluetoothDevice device, int prevstate, int newstate, ParcelFileDescriptor fd, int channelid) { super.onhealthchannelstatechange(config, device, prevstate, newstate, fd, channelid); ; if (newstate == BluetoothHealth.STATE_CHANNEL_CONNECTED){ // ID // ID mchannelid = channelid; // BluetoothDevice // mbluetoothdevice = device; : : private void register() { MyBluetoothHealthCallback mcallback = new MyBluetoothHealthCallback(); // mbluetoothhealth.registersinkappconfiguration("health_devices", BluetoothHealth.SINK_ROLE, mcallback); private void unregister() { // mbluetoothhealth.unregisterappconfiguration(mhealthconfig); 110

private void connect() { // Bluetooth mbluetoothhealth.connectchanneltosource(mbluetoothdevice, mhealthconfig); private void disconnect() { // Bluetooth mbluetoothhealth.disconnectchannel(mbluetoothdevice, mhealthconfig, mchannelid); 14-4 -10 111

Bluetooth SMART Bluetooth SMART READY BluetoothManager BluetoothManager manager = (BluetoothManager) getsystemservice(context.bluetooth_service); mbluetoothadapter = manager.getadapter(); 112

113

14-5 114

14-5 -1 115

14-5 -2 < > 116

14-5 -3 Wi-Fi WifiManager wm = (WifiManager) getsystemservice(context.wifi_service); if (!wm.iswifienabled()) { wm.setwifienabled(true); // Wi-Fi 14-5 -4 Wi-Fi WifiManager wm = (WifiManager) getsystemservice(context.wifi_service); wm.startscan(); // Wi-Fi BroadcastReceiver IntentFilter filter = new IntentFilter(); filter.addaction(wifimanager.scan_results_available_action); registerreceiver(mreceiver, filter); 117

Wi-Fi BroadcastReceiver mreceiver = new BroadcastReceiver() { public void onreceive(context context, Intent intent) { String action = intent.getaction(); if (WifiManager.SCAN_RESULTS_AVAILABLE_ACTION.equals(action)) { WifiManager wm = (WifiManager) getsystemservice(context.wifi_service); List<ScanResult> list = wm.getscanresults(); // ScanResult ; 14-5 -5 WEPWifiConfiguration WifiConfiguration config = new WifiConfiguration(); //SSID config.ssid = "\"" + ssid + "\""; // config.allowedkeymanagement.set(wificonfiguration.keymgmt.none); //IEEE 802.11 config.allowedauthalgorithms.set(wificonfiguration.authalgorithm.shared); // config.allowedgroupciphers.set(wificonfiguration.groupcipher.wep40); config.allowedgroupciphers.set(wificonfiguration.groupcipher.wep104); //WEP config.wepkeys[0] = "\"password\""; config.weptxkeyindex = 0; 118

WPA/WPA2-PSKWifiConfiguration WifiConfiguration config = new WifiConfiguration(); //SSID config.ssid = "\"" + ssid + "\""; // config.allowedkeymanagement.set(wificonfiguration.keymgmt.wpa_psk); //IEEE 802.11 config.allowedauthalgorithms.set(wificonfiguration.authalgorithm.open); // config.allowedprotocols.set(wificonfiguration.protocol.wpa); config.allowedprotocols.set(wificonfiguration.protocol.rsn);//wpa2 // config.allowedgroupciphers.set(wificonfiguration.groupcipher.ccmp); config.allowedgroupciphers.set(wificonfiguration.groupcipher.tkip); //WPA config.allowedpairwiseciphers.set(wificonfiguration.pairwisecipher.ccmp); config.allowedpairwiseciphers.set(wificonfiguration.pairwisecipher.tkip); //WPA config.presharedkey = "\"password\""; WifiConfiguration // if( manager.addnetwork(config) == -1 ){ // -1 return false; ; wifimanager.saveconfiguration(); // // wifimanager.updatenetwork(config); manager.enablenetwork(config.networkid, true); Wi-Fi WifiManager wm = (WifiManager) getsystemservice(context.wifi_service); wm.disconnect(); 119

14-5 -6 Wi-Fi WifiManager wm = (WifiManager) getsystemservice(wifi_service); List<WifiConfiguration> cfglist = wm.getconfigurednetworks(); for (int i = 0; i < cfglist.size(); i++) { Log.v("WifiConfiguration", "NetworkID = " + cfglist.get(i).networkid); Log.v("WifiConfiguration", "SSID = " + config_cfglistlist.get(i).ssid); Log.v(.); // : : 14-5 -7 Wi-Fi WifiManager wm = (WifiManager) getsystemservice(wifi_service); WifiInfo info = wm.getconnectioninfo(); Log.v("WifiInfo", "SSID = " + info.getssid()); Log.v("WifiInfo", "BSSID = " + info.getbssid()); Log.v("WifiInfo", "IP Address = " + info.getipaddress()); Log.v("WifiInfo", "Mac Address = " + info.getmacaddress()); Log.v("WifiInfo", "Network ID = " + info.getnetworkid()); Log.v("WifiInfo", "Link Speed = " + info.getlinkspeed()); 120

intip int ip_addr_i = w_info.getipaddress(); String ip_addr = ((ip_addr_i >> 0) & 0xFF) + "." + ((ip_addr_i >> 8) & 0xFF) + "." + ((ip_addr_i >> 16) & 0xFF) + "." + ((ip_addr_i >> 24) & 0xFF); Log.i("Sample", "IP Address:"+ip_addr); WIFI_STATE_DISABLING WIFI_STATE_DISABLED WIFI_STATE_ENABLING WIFI_STATE_ENABLED WIFI_STATE_UNKNOWN 121

14-5 -8 <> <> 122

14-5 -9 123

WifiP2pManager @Override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); // add necessary intent values to be matched. intentfilter.addaction(wifip2pmanager.wifi_p2p_state_changed_action); intentfilter.addaction(wifip2pmanager.wifi_p2p_peers_changed_action); intentfilter.addaction(wifip2pmanager.wifi_p2p_connection_changed_action); intentfilter.addaction(wifip2pmanager.wifi_p2p_this_device_changed_action); manager = (WifiP2pManager) getsystemservice(context.wifi_p2p_service); channel = manager.initialize(this, getmainlooper(), null); /** register the BroadcastReceiver with the intent values to be matched */ @Override public void onresume() { super.onresume(); receiver = new WiFiDirectBroadcastReceiver(manager, channel, this); 1 registerreceiver(receiver, intentfilter); @Override public void onpause() { super.onpause(); unregisterreceiver(receiver); 1 124

WiFiDirectBroadcastReceiver public class WiFiDirectBroadcastReceiver extends BroadcastReceiver { private WifiP2pManager mmanager; private Channel mchannel; private MyWiFiActivity mactivity; public WiFiDirectBroadcastReceiver(WifiP2pManager manager, Channel channel, MyWifiActivity activity) { super(); this.mmanager = manager; this.mchannel = channel; this.mactivity = activity; @Override public void onreceive(context context, Intent intent) { String action = intent.getaction(); if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) { // WiFi Direct/ // Wifi Direct(Setting)Toast else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) { // WiFi Direct(Peers) // 1 // else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) { // WiFi Direct // WifiP2pInfo 2 // else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) { // // WifiP2pDevice 1 2 125

WifiP2pManager.Channel initialize (Context srccontext, Looper srclooper, WifiP2pManag er.channellistener listener) connect (WifiP2pManager.Channel c, WifiP2pCon fig config, WifiP2pManager.ActionListener list ener) removegroup (WifiP2pManager.Channel c, WifiP2 pmanager.actionlistener listener) cancelconnect (WifiP2pManager.Channel c, Wifi P2pManager.ActionListener listener) 14-5 -10 manager.connect(channel, config, new ActionListener() { public void onsuccess() { // // BroadcastReceiver public void onfailure(int reason) { // Toast.makeText(WiFiDirectActivity.this, "Connect failed. Retry.", Toast.LENGTH_SHORT).show(); 126

WifiP2pConfig WifiP2pConfig config = new WifiP2pConfig(); config.deviceaddress = device.deviceaddress; // IP config.wps.setup = WpsInfo.PBC; //wps(wi-fi Protected Setup) //PBC(Push button configuration:)pin manager.removegroup(channel, new ActionListener() { public void onfailure(int reasoncode) { // // public void onsuccess() { // manager.cancelconnect(channel, new ActionListener() { public void onsuccess() { // public void onfailure(int reasoncode) { // // 127

128

129