éå§ãã
ããã¯ãã¹ãŠãå°è»ãç§ã«é»è©±ããããŠããé»è©±ãèŠããŸããïŒ ããã«ãã¿ã³ãå¿ èŠã§ããããã¯ãªãã¯ãããšãã©ãããããã§æ ç»ããªã³ã«ãªããŸãã å¥ã®ãã¿ã³ãæŒããšãé³æ¥œãæµããŸããããšåœŒã¯å€ãã®ããšãèšã£ããèŠããŠããªãã ãã¿ã¹ã¯ã¯æ確ã§ããïŒã ãã©ããŒïŒããªã圌ã«ãã®ãããªããŒãºããã£ãã®ãããããŸããã æããã®è§åºŠã«ç«ã£ãŠããªããããªããŠå€¢ãã èŠããã«ãããªãã¯ãããã®éæã¡ãç解ããŠããŸãã...ãŸãã倧äžå€«ã
æåã«ã圌ã¯é©åãªããã°ã©ã ãæ¢ããŠã°ãŒã°ã«ã«ç»ããŸããããããŠã圌ã¯èããŸãã-äžäœäœã ïŒ èªåã§æžããŸãã ããã«ããã®ã¿ã¹ã¯ã¯é£ããã¯ãªãããã§ããã³ãŒãã®åŒã³åºããã¯æ¢ã«æããããŸããïŒããçš®ã®ããã®it-breakingïŒã ããã§ãç§ã¯èªåã§WindowsãšAndroidãæ¥ç¶ããããšã«ããŸããã
圌ãå°ãããã®ãç§ã¯æ°æ¥ã§ãã£ãã ããããããã§ã¯ãå€ãã®ã³ãŒãããã§ãã¯ãäŸå€åŠçãªã©ããã§ã³ã¹ããããããŸããã èšäºã¯ããããåºç€ãšããŠæå°ã®ãã®ãæå³ããŠãããããã«åºã¥ããŠããã倧ããªãã®ãæ§ç¯ããããšãå¯èœã§ãã ç§ã¯ãªãªãžãã«ã®ãµããããŠã¯ãããŸãããæããã«èª°ãã䌌ããããªãã®ãæžããã®ã§ãèªåã®ããŒãžã§ã³ãæäŸããŠããŸãã äžè¬çã«ãããã¯èå³ã®ãããã¹ãŠã®äººã«æ§ããããŠããŸãã
äœããããŸãã
ããã§ãã äžæ¹ã§ã¯ãAndroidæèŒã®æºåž¯é»è©±ããããä»æ¹ã§ã¯ãããã°ã©ã ãã€ã³ã¹ããŒã«ãããWindowsãããããããã®ããã°ã©ã ã®äžéšã¯ãæºåž¯é»è©±ããã³ãã³ããçºè¡ããŠå®è¡ããå¿ èŠããããŸãã
é»è©±ãšã³ã³ãã¥ãŒã¿ãŒãããŒã«ã«ãããã¯ãŒã¯çµç±ã§æ¥ç¶ããŸããããã§ã¯ãªãã·ã§ã³ã¯ãããŸããïŒSMSãéä¿¡ããªãã§ãã ããïŒã ãããã£ãŠã2ã€ã®ããã°ã©ã ãäœæããŸãã 1ã€ã¯ã³ã³ãã¥ãŒã¿ãŒã§å®è¡ãããŠãããµãŒããŒã§ãããã®ããã°ã©ã ã®ã¿ã¹ã¯ã¯ãããŒããéããŠãªãã¹ã³ããããšã§ãã ãã®ããŒãã«äœã圹ã«ç«ã€ãã®ãããã°ãèšå®ããã¢ã¯ã·ã§ã³ãå®è¡ããŸãã 2çªç®ã®ããã°ã©ã ã¯ãé»è©±ã§å®è¡ãããŠããã¯ã©ã€ã¢ã³ãã§ãããã®ã¿ã¹ã¯ã¯ããŠãŒã¶ãŒã¢ã¯ã·ã§ã³ã®åŠçããµãŒããŒãžã®æ¥ç¶ãããã³æ å ±ã®éä¿¡ã§ãã
ãœã±ããã«ã€ããŠå°ã
ãœã±ããã®ããã°ã©ãã³ã°ã®ãããã¯ã¯ãã§ã«ããã¯ãããŠããŸãããããã¯ç¹å¥ãªããšã§ã¯ãããŸããã ãããããªã³ã¯ããã©ãã®ã奜ãã§ãªã人ã®ããã«ããŸã ç°¡åã«èšãã°ã
ãœã±ããã¯ãtcp / ipãããã³ã«ã䜿çšããŠ2ã€ã®ããã»ã¹éã®éä¿¡ã確ç«ã§ãããœãããŠã§ã¢ã€ã³ã¿ãŒãã§ã€ã¹ã§ãã ãœã±ããã¯ãIPã¢ãã¬ã¹ãšããŒããšãã2ã€ã®åŽé¢ã«é¢é£ä»ããããŠããŸãã IPã¢ãã¬ã¹ããããã¯ãŒã¯äžã®ãã¹ãïŒã³ã³ãã¥ãŒã¿ãŒïŒã®ã¢ãã¬ã¹ã§ããå ŽåãIPãããã³ã«ã¯ããã䜿çšããŸãã ããŒãã¯ãæ¥ç¶ã®å®å ãšãªãã¢ããªã±ãŒã·ã§ã³ã®èå¥åã§ãããããã§ã¯TCPãããã³ã«ãæ©èœããŸãã ããŒãã¯TCPãŸãã¯UDPã®ããããã§ãããã®èšäºã§ã¯ãTCPã®ã¿ã䜿çšããŸãã IPã¢ãã¬ã¹ã¯ã€ã³ã¿ãŒããããšããŒã«ã«ãããã¯ãŒã¯ã®äž¡æ¹ã§äžæã§ãããããéä¿¡è ã®ã¢ãã¬ã¹ãšåä¿¡è ã®ã¢ãã¬ã¹ãäžæã«æ±ºå®ããŸãã ããŒãã¯ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã å ã§äžæã§ãããããåãããã¢ããªã±ãŒã·ã§ã³ãå®çŸ©ããŸãã ããŒãã¯æšæºã§ããããšãã°ã80ãHTTPã«å²ãåœãŠããã3389ãRDPã«ãããã§ããŸãã 空ããŠããããŒãã§ããã°ã©ãã§ã䜿çšã§ããŸãããæšæºã®ããŒãã¯ãã®ãŸãŸã«ããŠããã®ãæåã§ãã éåžžã«ããããœã±ããã«é¢ããäŸãšãšãã«ã ããã«æžãããŠããŸã ã
ãµãŒã㌠ããŒãªã¬ã³ãéå§
AimpãWindows Media Playerãªã©ãèµ·åããŸãã é»è©±ããã§ã-é¢çœããããŸããããã®èšäºã«åºã¥ããŠãã³ãŒããå°ãããçŽãããšã§ç°¡åã«å®è£ ã§ããŸãã ãã£ãšè¯ãããŸãããã å¿ èŠã«å¿ããŠã¢ãã¿ãŒç»é¢ããã€ã¹ããã€ã¹ãããããäºæããªãã¡ãã»ãŒãžïŒäžæ¹åã®å°çã®ã¡ãã»ã³ãžã£ãŒïŒã衚瀺ããŸããææªã®äºæ ã¯ã³ã³ãã¥ãŒã¿ãŒã®é»æºãåãããšã§ãïŒ ç¢ºãã«ããã®ããã«åœŒãã¯ãã©ãŒã¯ã眮ãããšãã§ããŸãã ãŸããæåã«æãŸããŸãããã
ããã§ã¯å§ããŸãããã Visual Studioã§ãFunnyJokeãªã©ã®ååã§æ°ããWindowsãã©ãŒã ã¢ããªã±ãŒã·ã§ã³ãäœæããŸãã Program.csãã¡ã€ã«ãéããMainé¢æ°ã®æ¬äœå ã®ãã¹ãŠã®ã³ãŒããåé€ããŸãã ãã®ã³ãŒãã¯ã¢ããªã±ãŒã·ã§ã³ã®ã¡ã€ã³ãã©ãŒã ãåæåããŸãããµãŒããŒã«ã¯ãŠã£ã³ããŠã¯å¿ èŠãããŸãããéãã«åº§ã£ãŠã³ãã³ããåŸ ã€å¿ èŠããããŸãã
Programã¯ã©ã¹ã§ã次ã®å€æ°ãå®çŸ©ããŸãã
// static int port = 10000; // static IPAddress ipAddress = IPAddress.Parse("0.0.0.0"); // const byte codeMsg = 1; // const byte codeRotate = 2; // const byte codePoff = 3;
ããŒã10000ãååŸããŸãããããã¯ããµãŒããŒããªãã¹ã³ãããã®ã§ãã0.0.0.0ã«èšå®ããIPã¢ãã¬ã¹ã®ä»£ããã«ã䜿çšå¯èœãªãã¹ãŠã®ãããã¯ãŒã¯ã€ã³ã¿ãŒãã§ã€ã¹ãåŠçãããŸãã ããã¯å®å šã«æ£ããããã§ã¯ãããŸããããåå¿è ã«ã¯åœ¹ç«ã¡ãŸãã 次ã«ãã¯ã©ã€ã¢ã³ãããéä¿¡ãããã³ãã³ãã³ãŒããæå®ãã3ã€ã®å®æ°ãå®çŸ©ããŸããã ãããžã§ã¯ãã®éå§æã«ãæ¥ç¶ããããšãå¿ããªãã§ãã ããïŒ
using System.Net; using System.Net.Sockets;
ããã§ãMainé¢æ°ã®ãªã¢ãŒãã³ãŒãã®ä»£ããã«ã次ãæ¿å ¥ããŸãã
ã¡ã€ã³
static void Main() { // IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, port); // Socket socket = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); try { // socket.Bind(ipEndPoint); // "" socket.Listen(1); while (true) { // . Socket Socket handler = socket.Accept(); // , . byte[] recBytes = new byte[1024]; int nBytes = handler.Receive(recBytes); switch (recBytes[0]) // { case codeMsg: // nBytes = handler.Receive(recBytes); // if (nBytes != 0) { // String msg = Encoding.UTF8.GetString(recBytes, 0, nBytes); MessageBox.Show(msg, " !"); } break; case codeRotate: // RotateScreen(); break; case codePoff: // System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo.FileName = "shutdown.exe"; p.StartInfo.Arguments = "-s -t 00"; p.Start(); socket.Close(); break; } // handler.Shutdown(SocketShutdown.Both); handler.Close(); } } catch (Exception ex) { } }
äŸã¯ããã³ã¡ã³ããããŠããŸãã ããããããã§ã説æããŸãã ãŸããããŒã«ã«ãšã³ããã€ã³ããäœæãããããIPã¢ãã¬ã¹ãšããŒãã«é¢é£ä»ããŸãã 次ã«ãã¡ã€ã³ãœã±ãããå®çŸ©ãããšã³ããã€ã³ãã«ãã€ã³ãããŠããªã¹ãã³ã°ã¢ãŒãã«ããŸãã ãã®åŸãç¡éã«ãŒãã«å ¥ãã次ã®è¡ããéå§ããŸãã
Socket handler = socket.Accept();
ãµãŒããŒã¯æ¥ç¶åŸ æ©ç¶æ ã«ãªããŸãã æ¥ç¶ã«æåãããšãSocketã®æ°ããã€ã³ã¹ã¿ã³ã¹ãäœæããããããéããŠã¯ã©ã€ã¢ã³ããšéä¿¡ããŸãã æ¥ç¶ã確ç«ãããåŸãããŒã¿ã®èªã¿åããéå§ããŸãã
int nBytes = handler.Receive(recBytes
ã¯ã©ã€ã¢ã³ãã³ãã³ãã¯ã·ã³ã°ã«ãã€ãã³ãŒãïŒããã°ã©ã ã®åé ã§èª¬æïŒã§ãšã³ã³ãŒãããããµãŒããŒã¯ã³ãã³ãã³ãŒãã解èªããŠå®è¡ãéå§ãããã®åŸã¹ã¿ã³ãã€ã¢ãŒãã«æ»ããŸãã äŸå€ã¯codeMsgã§ã ã ãã®åŸãã¡ãã»ãŒãžæååãå«ããã€ãã®ã»ãããæåŸ ãããŸãã ãããã£ãŠããã®ã³ãã³ããåä¿¡ãããšããµãŒããŒã¯åã³ãœã±ããããããŒã¿ãèªã¿åããŸãã
nBytes = handler.Receive(recBytes); if (nBytes != 0) { String msg = Encoding.UTF8.GetString(recBytes, 0, nBytes); MessageBox.Show(msg, " !"); }
ã¯ã©ã€ã¢ã³ãããå°çããè¡ã«ã¯UTF-8æåãšã³ã³ãŒãã䜿çšãããŠãããããäžå¹žãªãŠãŒã¶ãŒã«è¡šç€ºããåã«ãæšæºåœ¢åŒã«ããå¿ èŠããããŸãã
ããã°ã©ã ãåçŽåããäžèŠãªãã€ã¢ãã°ãäœæããªãããã«ãæšæºã®MessageBoxã¯ã©ã¹ã䜿çšããŸãããããã®ã¢ãããŒãã«ã¯1ã€ã®æ¬ ç¹ããããŸãã MessageBoxã¯ãã¢ããªã±ãŒã·ã§ã³å šäœã®ãããŒããããã¯ããã¢ãŒãã«ãŠã£ã³ããŠãäœæããŸãã ã€ãŸããã¡ãã»ãŒãžããã¯ã¹ãéããŠããéããµãŒããŒã¯äœãããŸããã ãã¡ãããã€ãã¹ã§ãããã·ã³ãã«ããç ç²ã«ããªããã°ãªããŸããã
æé ããã€ã³ãããã«ãç»é¢ã®åããå€æŽããŸããMicrosoftãããã§æšå¥šããŠããããã«ãã³ãŒããå®æãããŸãã ã .NETã䜿çšããŠç»é¢ãå転ãããæ¹æ³ã¯èŠã€ãããŸããã§ããã ããã¯ã¢ãã€ã«ãã©ãããã©ãŒã ã§ã¯ç°¡åã«å®è¡ã§ããŸãããéåžžã®PCã§ã¯è§£æ±ºã§ããªãåé¡ã§ããããšãå€æããŸããã ããããå€ãè¯ãWINAPIãå©ãã«ãªãããã¹ãŠãå°ç¡ãã«ããŸããã
é©åãªãã©ã°ãä»ããŠshutdownã³ãã³ããåŒã³åºãããšã«ãããéåžžã®WindowsããŒã«ã䜿çšããŠã³ã³ãã¥ãŒã¿ãŒã®é»æºããªãã«ããŸãã
ãµãŒããŒãããã°ãããããããã ãã§ãã èšäºã®æåŸã«ãããžã§ã¯ãã®ãœãŒã¹ã³ãŒããæ·»ä»ããŸãã
ã客æ§
Eclipseããããã®IDEã奜ããªã®ã§ãAndroid Studioã§ã¯ã©ã€ã¢ã³ããäœæããŸãã åŸè ã®æ奜家ã¯ããããžã§ã¯ããããçŽãããšã¯ããã»ã©é£ãããªããšæããŸãã ãããã°ã«ã¯ãAndroidã®ä»®æ³ãã·ã³ãã€ã³ã¹ããŒã«ããç¶æ ã§VirtualBoxã䜿çšããŸãããããã¯ããã€ãã£ããšãã¥ã¬ãŒã¿ãŒãéåžžã«äœéã§ãããããã䜿çšããŠãããã°ããã®ã«ååãªå¯¿åœããªãããã§ãã ãŸããå®æçã«ãã©ã€ããé»è©±ã§ãã§ãã¯ããŸããã ããã§ãFunnyJokeãšãããããžã§ã¯ããäœæããã䜿ãã®æºåž¯é»è©±ããã«ã§ããAPIã®æå°ããŒãžã§ã³ïŒ16åãããŸãïŒãèšå®ããEmpty ActivityãéžæããŸãã ãã以å€ã¯ãã¹ãŠããã©ã«ãã§ãã ãã¬ãŒã³ããŒã·ã§ã³ã®ããŒã¯ã¢ãããäœæããŸãã çŸãããã¿ã³ãæãããã颚氎ã«çœ®ãããããå¿ èŠã®ãããã¶ã€ã³ã«ã€ããŠã¯ãç§ã¯ããŸãå€è³ªããŸããã§ããã EditTextã¿ã€ãã®2ã€ã®ãã£ãŒã«ããå¶åŸ¡ãããã³ã³ãã¥ãŒã¿ãŒã®IPã¢ãã¬ã¹ãå ¥åããããã®æåã®ãã£ãŒã«ããã¡ãã»ãŒãžã®ããã¹ãã®ããã®2çªç®ã®ãã£ãŒã«ããããã³ãã¹ã¯ããããå転ããããã¿ã³ã ããããã·ã£ããããŠã³ãã¿ã³ã¯å€§ãããŠæãããèµ€ã«ãªããŸããã ããã¯ã誀ã£ãŠã¯ãªãã¯ããªãããã«ããããã§ãã
activity_main.xmlïŒ
<?xml version="1.0" encoding="utf-8"?> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:weightSum="1" android:layout_marginTop="20dp"> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="20dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="IP address:" android:id="@+id/textView" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/edIPaddress" android:digits="0123456789." /> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="top" > <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/etMsg" android:layout_gravity="center_vertical" android:layout_weight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Send Msg" android:layout_weight="0" android:id="@+id/btnSMsg" android:layout_gravity="center_vertical" android:onClick="onClick" /> </LinearLayout> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Rotate Screen" android:id="@+id/btnRotate" android:layout_weight="0" android:layout_gravity="center_horizontal" android:layout_marginBottom="20dp" android:layout_marginTop="20dp" android:onClick="onClick" /> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/btnPowerOff" android:layout_gravity="center" android:src="@drawable/button_img" android:background="@null" android:onClick="onClick" /> </LinearLayout>
ããã§ã¯ã edIPaddressãã£ãŒã«ãã«æ³šæãæã䟡å€ããããŸããæ°å€ã®ã¿ãå ¥åãããã£ã«ã¿ãªã³ã°ããããŸãã ïŒããªãªãïŒããã£ãŒã«ãã¯IPã¢ãã¬ã¹ãå ¥åããããã®ãã®ã§ãã ããã¯å ¥åãããããŒã¿ã®æ£ç¢ºæ§ã«é¢ããå¯äžã®ãã§ãã¯ã§ãããä»ã®ãã¹ãŠã¯ãŠãŒã¶ãŒã®è¯å¿ã«ãšã©ãŸããšèšããªããã°ãªããŸããã ãŸãã btnPowerOffãã¿ã³ã«ã€ããŠã説æããŸãããã®ã»ã¬ã¯ã¿ãŒã¯ç¶æ ãç£èŠããæŒãããŠãããã©ããã«å¿ããŠç»åãå€æŽããŸãïŒããã§ãªãå Žåããã¿ã³ãæŒããããã©ããã¯äžæã§ããã¿ã³ã¯éçãªç»åã®ããã«èŠããŸãïŒã button_img.xmlã»ã¬ã¯ã¿ã³ãŒãã¯æ¬¡ã®ãšããã§ãã
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/poweroffs"/> <item android:drawable="@drawable/poweroff"/> </selector>
ãããã£ãŠããªãœãŒã¹ã«ã¯2ã€ã®ç»åãå¿ èŠã§ãã1ã€ã¯æŒãããç¶æ ããã1ã€ã¯éåžžã®ç¶æ ã§ãã 次ã®ç»é¢ã衚瀺ãããŸãã
ãããããŒã¯ã¢ããã§çµäºããŸãã MainActivity.javaãã¡ã€ã«ã«ç§»åããŸãã ãŸãããµãŒããŒãšåæ§ã«ãã³ãã³ãã³ãŒããšããã€ãã®å€æ°ã決å®ããŸãã
String serIpAddress; // int port = 10000; // String msg; // final byte codeMsg = 1; // final byte codeRotate = 2; // final byte codePoff = 3; // byte codeCommand;
次ã«ããã¿ã³ã¯ãªãã¯ãã³ãã©ãŒã«ç§»åããŸãã ãã³ãã©ãŒã¯1ã€ã ãã§ãããæŒãããæãæã¯ãã®èå¥åã«ãã£ãŠèå¥ãããããšã«æ³šæããŠãã ããã ãŸãã edIPaddressãã£ãŒã«ãããè¡ãååŸããŸãããã£ãŒã«ãã«å ¥åãããŠããªãå Žåã¯ãIPã¢ãã¬ã¹ãå ¥åããå¿ èŠãããããšã瀺ãã¡ãã»ãŒãžã衚瀺ãããã以å€ã¯äœãããŸããã
public void onClick (View v) { // ip EditText etIPaddress = (EditText)findViewById(R.id.edIPaddress); serIpAddress = etIPaddress.getText().toString(); // , if (serIpAddress.isEmpty()){ Toast msgToast = Toast.makeText(this, " ip ", Toast.LENGTH_SHORT); msgToast.show(); return; } . . . . }
Androidã§ã¯ãã¡ã€ã³ã¹ã¬ããã§é·æéå®è¡ãããããã»ã¹ãäœæããããšã¯ãå§ãããŸãããããã¯ãããã°ã©ã ããããªãŒãºãããå¯èœæ§ãããããŠãŒã¶ãŒãŸãã¯ã·ã¹ãã ãå¿çãåŸ ããã«ã¢ããªã±ãŒã·ã§ã³ãåçŽã«éããããšãã§ããããã§ãã ãã®ãããªé·æã«ãããããã»ã¹ã«ã¯ããããã¯ãŒãã³ã°ãå«ãŸããŸãã ãã®å Žåããé·ããã³ãŒããå®è¡ããè¿œå ã®ã¹ããªãŒã ãäœæããå¿ èŠããããŸãã Javaã«ã¯ã ã¹ã¬ãããå¶åŸ¡ã§ããæšæºã®Threadã¯ã©ã¹ããããŸããã䜿çšããŸããã Androidã«ã¯ããã®ããã«ç¹å¥ã«èšèšãããAsyncTaskã¯ã©ã¹ããããŸãã 詳现ã¯ãã¡ããŸãã¯ãã¡ããã芧ãã ããã
ã¡ãã»ãŒãžãéä¿¡ãã AsyncTaskã芪ã«ããã¡ã€ã³ã³ãŒããé 眮ãããdoInBackgroundã¡ãœãããåå®çŸ©ããã¯ã©ã¹ãäœæããŸãã
ã»ã³ãã¹ã¬ãã
class SenderThread extends AsyncTask <Void, Void, Void> { @Override protected Void doInBackground(Void... params) { try { // ip InetAddress ipAddress = InetAddress.getByName(serIpAddress); // Socket socket = new Socket(ipAddress, port); // / OutputStream outputStream = socket.getOutputStream(); DataOutputStream out = new DataOutputStream(outputStream); switch (codeCommand) { // case codeMsg: // out.write(codeMsg); // UTF-8 byte[] outMsg = msg.getBytes("UTF8"); out.write(outMsg); break; case codeRotate: // out.write(codeRotate); break; case codePoff: // out.write(codePoff); break; } } catch (Exception ex) { ex.printStackTrace(); } return null; } }
æåã«ãIPãµãŒããŒãå«ãInetAddressã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ãäœæããŸãã 次ã«ããœã±ãããäœæãããªã¢ãŒãã¢ãã¬ã¹ãšããŒãã«ãã€ã³ãããæšæºã®å ¥å/åºåã¹ããªãŒã ãèŠæ±ããŸãïŒã¯ã©ã€ã¢ã³ãã¯äœãåä¿¡ããªããããåºåã®ã¿ãèŠæ±ããŸãïŒã ãããŠæåŸã«ã codeCommandå€æ°ã®å€ã«å¿ããŠããµãŒããŒã«ã¡ãã»ãŒãžãéä¿¡ããŸãã
次ã«ããã¿ã³ã¯ãªãã¯ãã³ãã©ã«æ»ãã SenderThreadã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ãäœæããæŒããããã¿ã³ã«å¿ããŠcodeCommandå€æ°ãåæåãã ããããã¹ããªãŒã ã決å®ããŸãã æåŸã«ã executeïŒïŒã¡ãœãããåŒã³åºããŠã¢ã¯ãã£ãåããŸãã
. . . SenderThread sender = new SenderThread(); // switch (v.getId()) // id { case R.id.btnSMsg: // if (!msg.isEmpty()) { codeCommand = codeMsg; sender.execute(); } else { // , Toast msgToast = Toast.makeText(this, " ", Toast.LENGTH_SHORT); msgToast.show(); } break; case R.id.btnRotate: // codeCommand = codeRotate; sender.execute(); break; case R.id.btnPowerOff: // codeCommand = codePoff; sender.execute(); break; } }
ã¢ããªã±ãŒã·ã§ã³ãããã§ã¹ããå°ãä¿®æ£ãããããã¯ãŒã¯ãšWi-Fiã䜿çšããèš±å¯ãäžããŸãããããªãã§ã¯äœãæ©èœããŸããã
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
ããã ãã§ãïŒ åéããŠç¢ºèªã§ããŸãã çµæã¯æ¬¡ã®ãšããã§ãã