編輯:關於Android編程
客戶端代碼:
activity:
package com.example.sockettest; import java.io.*; import java.net.Socket; import java.net.UnknownHostException; import android.app.Activity; import android.os.Bundle; import android.text.TextUtils; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class main extends Activity implements OnClickListener { /** * Called when the activity is first created. */ private EditText edtmsgcontent; private Button btnSend; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.main); InitView(); } private void InitView() { setContentView(R.layout.main); edtmsgcontent = (EditText) findViewById(R.id.msgcontent); btnSend = (Button) findViewById(R.id.btnsend); btnSend.setOnClickListener(this); } public void onClick(View bt) { try { String msg = edtmsgcontent.getText().toString(); if (!TextUtils.isEmpty(msg)) SendMsg(msg); else { Toast.makeText(this, cccc, Toast.LENGTH_LONG); edtmsgcontent.requestFocus(); } } catch (Exception e) { e.printStackTrace(); } } public void SendMsg(final String msg) throws UnknownHostException, IOException { new Thread() { @Override public void run() { try { String ip = 192.168.1.155; int port = 1818; Socket socket = null; socket = new Socket(ip, port); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); writer.write(msg); writer.flush(); writer.close(); socket.close(); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }.start(); } }main.xml:
AndroidMenifest.xml文件中添加網絡訪問權限:
服務器:
不是web工程,直接run main函數就可以了。
package test; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; public class Server { public static void main(String[] args){ BufferedReader in; PrintWriter out; try{ ServerSocket ss = new ServerSocket(43211); System.out.println(1); Socket socket = ss.accept(); System.out.println(2); in = new BufferedReader(new InputStreamReader(socket.getInputStream())); out = new PrintWriter(socket.getOutputStream(),true); while(true){ String line = in.readLine(); System.out.println(line); if(line.equals(88)){ break; } out.println(hello: + line); out.flush(); } out.close(); in.close(); socket.close(); }catch(IOException e){ } } }
前面walfred已經介紹了使用apktool對apk進行逆向編譯,通過apktool我們的確可以反編譯已經序列化後的AndroidManifest.xml和資源文件等等
緒論最近一直比較忙,也沒抽出時間來寫博客,也不得不說是自己犯了懶癌,人要是一懶就什麼事都不想做了,如果不能堅持下來的話,那麼估計就廢了,??。最近自己攢了好多東西,接下來
《最近做一個小功能遇到這麼一個問題,listview 與 baseadapter結合使用,關於點贊的的時候 圖片重復問題,比如:我在第1個item 點贊然後 心型換成了紅
工具/原料JDKEclipseADTJDK的安裝和Java環境變量的設置1、JDK下載地址 JDK下載地址:http://www.or