http://www.cnblogs.com/yangfengwu/p/8776712.html
先把源碼和資料鏈接放到這里
鏈接:https://pan.baidu.com/s/10MxI8-Q33-M_R2WEHqEi1A密碼:j1sz
先做手機的,然后做C#的
詳細點的可以看我這篇文章,請參考著這篇看這篇文章,這篇文章會解決一些細節(jié)問題
http://www.cnblogs.com/yangfengwu/p/5212570.html
咱們不做很復(fù)雜的直接越簡單越好,就做成這樣





先編譯一下






不用管,后期的話咱會用一下










最后做成這樣子








發(fā)現(xiàn)還是有點大..


把像素低的放到像素高的里面圖片顯示出來會縮小,把像素高的放到像素低的里面圖片顯示出來會放大





protectedvoid onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_main);
? ? ? ? imageViewLamp = (ImageView) findViewById(R.id.imageView1);
? ? ? ? switchLamp = (Switch) findViewById(R.id.switch1);
? ? ? ? switchLamp.setOnCheckedChangeListener(switchLamplistener);//設(shè)置SWITCH的狀態(tài)改變事件
? ? }
? ? privateOnCheckedChangeListener switchLamplistener =new OnCheckedChangeListener() {
? ? ? ? @Override
? ? ? ? publicvoid onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
? ? ? ? ? ? // TODO Auto-generated method stub//? ? ? ? ? ? Toast.makeText(getApplicationContext(), isChecked+"", 500).show();if (isChecked) {//切換圖片
? ? ? ? ? ? ? ? imageViewLamp.setImageResource(R.drawable.ledon);
? ? ? ? ? ? }
? ? ? ? ? ? else {
? ? ? ? ? ? ? ? imageViewLamp.setImageResource(R.drawable.ledoff);
? ? ? ? ? ? }
? ? ? ? }
? ? };


現(xiàn)在做點擊連接按鈕就連接服務(wù)器

?剛看到...............

有點迫不及待的想試一試騰訊云了,
下面做的是:點擊連接按鈕,連接TCP服務(wù)器,連接上以后啟動數(shù)據(jù)接收任務(wù),因為數(shù)據(jù)接收任務(wù)可以判斷是不是和服務(wù)器斷開了連接
然后按鈕顯示"斷開",如果意外斷開了連接也顯示斷開....

publicclass MainActivity extends Activity {
? ? ImageView imageViewLamp;//燈的圖片Switch switchLamp;//燈的控制開關(guān)EditText editTextIPAdress,editTextPort;//ip地址和端口號的編輯框Button buttonConnect;//連接按鈕Socket socket;//cocketboolean ConnectFlage =false;//連接標志,控制按鈕顯示連接和斷開ThreadConnectService threadConnectService =newThreadConnectService();//建立一個連接任務(wù)的變量InputStream inputStream;//獲取輸入流,可以用來判斷有沒有斷開連接ThreadReadData threadReadData =newThreadReadData();//接收數(shù)據(jù)的任務(wù)的變量boolean threadReadDataFlage =false;//接收數(shù)據(jù)任務(wù)一直運行控制byte[] ReadBuffer =newbyte[1024];//存儲接收到的數(shù)據(jù)intReadBufferLengh =0;//接收到的數(shù)據(jù)個數(shù)
? ? @Override
? ? protectedvoid onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_main);
? ? ? ? editTextIPAdress = (EditText) findViewById(R.id.editText1);
? ? ? ? editTextPort = (EditText) findViewById(R.id.editText2);
? ? ? ? buttonConnect = (Button) findViewById(R.id.button1);
? ? ? ? buttonConnect.setOnClickListener(buttonConnectClick);
? ? ? ? imageViewLamp = (ImageView) findViewById(R.id.imageView1);
? ? ? ? switchLamp = (Switch) findViewById(R.id.switch1);
? ? ? ? switchLamp.setOnCheckedChangeListener(switchLamplistener);
? ? }
? ? /*指示燈控制開關(guān)*/privateOnCheckedChangeListener switchLamplistener =new OnCheckedChangeListener() {
? ? ? ? @Override
? ? ? ? publicvoid onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
? ? ? ? ? ? if (isChecked) {
? ? ? ? ? ? ? ? imageViewLamp.setImageResource(R.drawable.ledon);
? ? ? ? ? ? }
? ? ? ? ? ? else {
? ? ? ? ? ? ? ? imageViewLamp.setImageResource(R.drawable.ledoff);
? ? ? ? ? ? }
? ? ? ? }
? ? };
? ? /*按鈕點擊連接事件*/privateOnClickListener buttonConnectClick =new OnClickListener() {
? ? ? ? @Override
? ? ? ? publicvoid onClick(View v) {
? ? ? ? ? ? if (ConnectFlage)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? try {
? ? ? ? ? ? ? ? ? ? threadConnectService.start();//啟動連接任務(wù)? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? catch(Exception e)//預(yù)防任務(wù)還沒關(guān)閉呢又點擊開始? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? threadConnectService.run();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? ConnectFlage =true;
? ? ? ? ? ? ? ? buttonConnect.setText("連接");
? ? ? ? ? ? ? ? try
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? socket.close();//關(guān)閉socketinputStream.close();//關(guān)閉數(shù)據(jù)流}catch (Exception e) {
? ? ? ? ? ? ? ? ? ? // TODO: handle exception? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? };
? ? /**
? ? * 連接服務(wù)器的任務(wù)
? ? * @author yang
? ? *
? ? */class ThreadConnectService extends Thread
? ? {
? ? ? ? publicvoid run()
? ? ? ? {
? ? ? ? ? ? InetAddress ipAddress;
? ? ? ? ? ? try
? ? ? ? ? ? {
? ? ? ? ? ? ? ? ipAddress = InetAddress.getByName(editTextIPAdress.getText().toString());//獲取IP地址intport =Integer.valueOf(editTextPort.getText().toString());//獲取端口號 socket =newSocket(ipAddress, port);//創(chuàng)建連接地址和端口inputStream = socket.getInputStream();//獲得通道的數(shù)據(jù)流變量threadReadDataFlage =true;//一直接收數(shù)據(jù)try
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? threadReadData.start();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? catch(Exception e) {//預(yù)防任務(wù)還沒關(guān)閉呢又點擊開始? ? ? ? ? ? ? ? ? ? threadReadData.run();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? runOnUiThread(newRunnable() {//修改界面的UI最好用Handle,這里力求簡單,下幾節(jié)再用publicvoid run() {
? ? ? ? ? ? ? ? ? ? ? ? ConnectFlage =false;
? ? ? ? ? ? ? ? ? ? ? ? buttonConnect.setText("斷開");
? ? ? ? ? ? ? ? ? ? ? ? Toast.makeText(getApplicationContext(), "連接成功",500).show();
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? });
? ? ? ? ? ? }
? ? ? ? ? ? catch (Exception e)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? e.printStackTrace();
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? /**
? ? * 接收數(shù)據(jù)的任務(wù)
? ? * @author yang
? ? *
? ? */class ThreadReadData extends Thread
? ? {
? ? ? ? publicvoid run()
? ? ? ? {
? ? ? ? ? ? while (threadReadDataFlage)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? try
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ReadBufferLengh = inputStream.read(ReadBuffer);//服務(wù)器斷開會返回-1if(ReadBufferLengh == -1) {
? ? ? ? ? ? ? ? ? ? ? ? threadReadDataFlage =false;
? ? ? ? ? ? ? ? ? ? ? ? runOnUiThread(newRunnable() {//修改界面的UI最好用Handle,這里力求簡單,下幾節(jié)再用publicvoid run() {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ConnectFlage =true;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? buttonConnect.setText("連接");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Toast.makeText(getApplicationContext(), "與服務(wù)器斷開連接",500).show();
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? });
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? catch (Exception e)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? // TODO Auto-generated catch blockLog.e("error", ReadBufferLengh+"");
? ? ? ? ? ? ? ? ? ? e.printStackTrace();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? /** 當活動(界面)不再可見時調(diào)用 */? ? @Override
? ? protectedvoid onStop()
? ? {
? ? ? ? threadReadDataFlage =false;//結(jié)束接收數(shù)據(jù)任務(wù)? ? ? ? super.onStop();
? ? }
? ? @Override
? ? public boolean onCreateOptionsMenu(Menu menu) {
? ? ? ? getMenuInflater().inflate(R.menu.main, menu);
? ? ? ? returntrue;
? ? }
? ? @Override
? ? public boolean onOptionsItemSelected(MenuItem item) {
? ? ? ? intid = item.getItemId();
? ? ? ? if(id == R.id.action_settings) {
? ? ? ? ? ? returntrue;
? ? ? ? }
? ? ? ? return super.onOptionsItemSelected(item);
? ? }
}



?忘了說一件事情....加權(quán)限



? ? ? ? ? ? ? "? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? android:minSdkVersion="17"? ? ? ? android:targetSdkVersion="21"/>? ?
? ? ? ? android:allowBackup="true"? ? ? ? android:icon="@drawable/ic_launcher"? ? ? ? android:label="@string/app_name"? ? ? ? android:theme="@style/AppTheme">

我把上面做的打包了

好現(xiàn)在接著寫發(fā)數(shù)據(jù)(控制燈的亮滅)

publicclass MainActivity extends Activity {
? ? ImageView imageViewLamp;//燈的圖片Switch switchLamp;//燈的控制開關(guān)EditText editTextIPAdress,editTextPort;//ip地址和端口號的編輯框Button buttonConnect;//連接按鈕Socket socket;//cocketboolean ConnectFlage =true;//連接標志,控制按鈕顯示連接和斷開ThreadConnectService threadConnectService =newThreadConnectService();//建立一個連接任務(wù)的變量InputStream inputStream;//獲取輸入流,可以用來判斷有沒有斷開連接OutputStream outputStream;//獲得輸出流ThreadReadData threadReadData =newThreadReadData();//接收數(shù)據(jù)的任務(wù)ThreadSendData threadSendData =newThreadSendData();//發(fā)送數(shù)據(jù)的任務(wù)boolean threadReadDataFlage =false;//接收數(shù)據(jù)任務(wù)一直運行控制boolean threadSendDataFlage =false;//接收數(shù)據(jù)任務(wù)一直運行控制byte[] ReadBuffer =newbyte[1024];//存儲接收到的數(shù)據(jù)byte[] SendBuffer =newbyte[1024];//存儲發(fā)送的數(shù)據(jù)intReadBufferLengh =0;
? ? intSendDataCnt =0;//控制發(fā)送數(shù)據(jù)的個數(shù)? ? @Override
? ? protectedvoid onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_main);
? ? ? ? editTextIPAdress = (EditText) findViewById(R.id.editText1);
? ? ? ? editTextPort = (EditText) findViewById(R.id.editText2);
? ? ? ? buttonConnect = (Button) findViewById(R.id.button1);
? ? ? ? buttonConnect.setOnClickListener(buttonConnectClick);
? ? ? ? imageViewLamp = (ImageView) findViewById(R.id.imageView1);
? ? ? ? switchLamp = (Switch) findViewById(R.id.switch1);
? ? ? ? switchLamp.setOnCheckedChangeListener(switchLamplistener);
? ? }
? ? /*指示燈控制開關(guān)*/privateOnCheckedChangeListener switchLamplistener =new OnCheckedChangeListener() {
? ? ? ? @Override
? ? ? ? publicvoid onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
? ? ? ? ? ? if (isChecked) {
? ? ? ? ? ? ? ? imageViewLamp.setImageResource(R.drawable.ledon);
? ? ? ? ? ? ? ? SendBuffer[0] = (byte)0xaa;
? ? ? ? ? ? ? ? SendBuffer[1] =0x55;
? ? ? ? ? ? ? ? SendBuffer[2] =0x02;
? ? ? ? ? ? ? ? SendBuffer[3] = (byte)0xff;
? ? ? ? ? ? }
? ? ? ? ? ? else {
? ? ? ? ? ? ? ? imageViewLamp.setImageResource(R.drawable.ledoff);
? ? ? ? ? ? ? ? SendBuffer[0] = (byte)0xaa;
? ? ? ? ? ? ? ? SendBuffer[1] =0x55;
? ? ? ? ? ? ? ? SendBuffer[2] =0x02;
? ? ? ? ? ? ? ? SendBuffer[3] =0x00;
? ? ? ? ? ? }
? ? ? ? ? ? SendDataCnt =4;//控制發(fā)送數(shù)據(jù)的個數(shù)? ? ? ? }
? ? };
? ? /*按鈕點擊連接事件*/privateOnClickListener buttonConnectClick =new OnClickListener() {
? ? ? ? @Override
? ? ? ? publicvoid onClick(View v) {
? ? ? ? ? ? if (ConnectFlage)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? try
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? threadConnectService.start();//啟動連接任務(wù)? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? catch(Exception e)//預(yù)防任務(wù)還沒關(guān)閉呢又點擊開始? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? threadConnectService.run();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? ConnectFlage =true;
? ? ? ? ? ? ? ? threadSendDataFlage =false;//關(guān)掉發(fā)送任務(wù),預(yù)防產(chǎn)生多的任務(wù)threadReadDataFlage =false;//關(guān)掉接收任務(wù),預(yù)防產(chǎn)生多的任務(wù)buttonConnect.setText("連接");
? ? ? ? ? ? ? ? try
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? socket.close();//關(guān)閉socketinputStream.close();//關(guān)閉數(shù)據(jù)流}catch (Exception e) {
? ? ? ? ? ? ? ? ? ? // TODO: handle exception? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? };
? ? /**
? ? * 連接服務(wù)器的任務(wù)
? ? * @author yang
? ? *
? ? */class ThreadConnectService extends Thread
? ? {
? ? ? ? publicvoid run()
? ? ? ? {
? ? ? ? ? ? InetAddress ipAddress;
? ? ? ? ? ? try
? ? ? ? ? ? {
? ? ? ? ? ? ? ? ipAddress = InetAddress.getByName(editTextIPAdress.getText().toString());//獲取IP地址intport =Integer.valueOf(editTextPort.getText().toString());//獲取端口號 socket =newSocket(ipAddress, port);//創(chuàng)建連接地址和端口inputStream = socket.getInputStream();//獲得通道的數(shù)據(jù)流outputStream = socket.getOutputStream();//獲得通道的輸出流threadReadDataFlage =true;//一直接收數(shù)據(jù)threadSendDataFlage =true;//一直循環(huán)的判斷是否發(fā)送數(shù)據(jù)try
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? threadReadData.start();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? catch(Exception e) {//預(yù)防任務(wù)還沒關(guān)閉呢又點擊開始? ? ? ? ? ? ? ? ? ? threadReadData.run();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? try {
? ? ? ? ? ? ? ? ? ? threadSendData.start();
? ? ? ? ? ? ? ? } catch (Exception e) {
? ? ? ? ? ? ? ? ? ? threadSendData.run();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? runOnUiThread(newRunnable() {//修改界面的UI最好用Handle,這里力求簡單,下幾節(jié)再用publicvoid run() {
? ? ? ? ? ? ? ? ? ? ? ? ConnectFlage =false;
? ? ? ? ? ? ? ? ? ? ? ? buttonConnect.setText("斷開");
? ? ? ? ? ? ? ? ? ? ? ? Toast.makeText(getApplicationContext(), "連接成功",500).show();
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? });
? ? ? ? ? ? }
? ? ? ? ? ? catch (Exception e)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? e.printStackTrace();
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? /**
? ? * 接收數(shù)據(jù)的任務(wù)
? ? * @author yang
? ? *
? ? */class ThreadReadData extends Thread
? ? {
? ? ? ? publicvoid run()
? ? ? ? {
? ? ? ? ? ? while (threadReadDataFlage)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? try
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ReadBufferLengh = inputStream.read(ReadBuffer);//服務(wù)器斷開會返回-1if(ReadBufferLengh == -1) {
? ? ? ? ? ? ? ? ? ? ? ? threadSendDataFlage =false;//關(guān)掉發(fā)送任務(wù),預(yù)防產(chǎn)生多的任務(wù)threadReadDataFlage =false;//關(guān)掉接收任務(wù),預(yù)防產(chǎn)生多的任務(wù)SendDataCnt =0;//清零發(fā)送的個數(shù)ConnectFlage =true;
? ? ? ? ? ? ? ? ? ? ? ? runOnUiThread(newRunnable() {//修改界面的UI最好用Handle,這里力求簡單,下幾節(jié)再用publicvoid run() {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? buttonConnect.setText("連接");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Toast.makeText(getApplicationContext(), "與服務(wù)器斷開連接",500).show();
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? });
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? catch (Exception e)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? // TODO Auto-generated catch blockLog.e("error", ReadBufferLengh+"");
? ? ? ? ? ? ? ? ? ? e.printStackTrace();
? ? ? ? ? ? ? ? ? ? runOnUiThread(newRunnable() {//修改界面的UI最好用Handle,這里力求簡單,下幾節(jié)再用publicvoid run() {
? ? ? ? ? ? ? ? ? ? ? ? ? ? buttonConnect.setText("連接");
? ? ? ? ? ? ? ? ? ? ? ? ? ? Toast.makeText(getApplicationContext(), "與服務(wù)器斷開連接",500).show();
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? });
? ? ? ? ? ? ? ? ? ? ConnectFlage =true;
? ? ? ? ? ? ? ? ? ? threadSendDataFlage =false;//關(guān)掉發(fā)送任務(wù),預(yù)防產(chǎn)生多的任務(wù)threadReadDataFlage =false;//關(guān)掉接收任務(wù),預(yù)防產(chǎn)生多的任務(wù)SendDataCnt =0;//清零發(fā)送的個數(shù)? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? /**
? ? * 發(fā)送數(shù)據(jù)任務(wù)
? ? * @author yang
? ? *
? ? */class ThreadSendData extends Thread
? ? {
? ? ? ? publicvoid run()
? ? ? ? {
? ? ? ? ? ? while (threadSendDataFlage)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if(SendDataCnt>0)//要發(fā)送的數(shù)據(jù)個數(shù)大于0? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? try
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? outputStream.write(SendBuffer,0,SendDataCnt);//發(fā)送數(shù)據(jù)SendDataCnt =0;//清零發(fā)送的個數(shù)? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? catch (Exception e)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? runOnUiThread(newRunnable() {//修改界面的UI最好用Handle,這里力求簡單,下幾節(jié)再用publicvoid run() {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? buttonConnect.setText("連接");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Toast.makeText(getApplicationContext(), "與服務(wù)器斷開連接",500).show();
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? });
? ? ? ? ? ? ? ? ? ? ? ? ConnectFlage =true;
? ? ? ? ? ? ? ? ? ? ? ? threadSendDataFlage =false;//關(guān)掉發(fā)送任務(wù),預(yù)防產(chǎn)生多的任務(wù)threadReadDataFlage =false;//關(guān)掉接收任務(wù),預(yù)防產(chǎn)生多的任務(wù)SendDataCnt =0;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? /** 當活動(界面)不再可見時調(diào)用 */? ? @Override
? ? protectedvoid onStop()
? ? {
? ? ? ? threadReadDataFlage =false;//結(jié)束接收數(shù)據(jù)任務(wù)threadSendDataFlage =false;//結(jié)束發(fā)送數(shù)據(jù)任務(wù)SendDataCnt =0;
? ? ? ? super.onStop();
? ? }
? ? @Override
? ? public boolean onCreateOptionsMenu(Menu menu) {
? ? ? ? getMenuInflater().inflate(R.menu.main, menu);
? ? ? ? returntrue;
? ? }
? ? @Override
? ? public boolean onOptionsItemSelected(MenuItem item) {
? ? ? ? intid = item.getItemId();
? ? ? ? if(id == R.id.action_settings) {
? ? ? ? ? ? returntrue;
? ? ? ? }
? ? ? ? return super.onOptionsItemSelected(item);
? ? }
}

發(fā)送數(shù)據(jù)是寫在了一個任務(wù)里面





整體的源碼
本來想這一節(jié)也寫好C#的,不過感覺寫的夠多的了,所以C#的放到下一節(jié)
下一篇