当前位置:  编程技术>移动开发
本页文章导读:
    ▪字体依据屏幕自动换行        字体根据屏幕自动换行 String a = "\1阿第克搜房卡死的\2gsd\3阿萨德分呵可降低首付款及空间阿萨德akjsdkfklasdklfkl\2adsfkasdfklasdfklasdklfadsgfasdg\0呵可降低首付款及阿康鸡丝豆腐阿萨德发生的广泛.........
    ▪ 经过Wifi实现设备间的通信        通过Wifi实现设备间的通信 服务器端,建立监听(方法更新,可以同时连接多个Client) public class Server extends ServerSocket { private static ArrayList<String> mUserList = new ArrayList<String>(); priva.........
    ▪ 手机上网HTTP报文搜集       手机上网HTTP报文收集 --------Server accepted Header-------------header:Host value:211.136.107.36header:User-Agent value:defaut-usergentheader:Via value:WTP/1.1 BJBJ-PS-WAP2-GW03.bj2.monternet.com (Nokia WAP Gateway 4.0/CD3/4.1.29)header:X-Nok.........

[1]字体依据屏幕自动换行
    来源: 互联网  发布时间: 2014-02-18
字体根据屏幕自动换行
String a = "\1阿第克搜房卡死的\2gsd\3阿萨德分呵可降低首付款及空间阿萨德akjsdkfklasdklfkl\2adsfkasdfklasdfklasdklfadsgfasdg\0呵可降低首付款及阿康鸡丝豆腐阿萨德发生的广泛撒的gas的广泛撒丁格\2adskjfkjaskdf呵可降低首付款及阿康速度\1aksdfklalsdklfklasdgklad是否快乐\0adsjfkjasdkjf阿奎奸杀副科级啊伤口揭开了圣诞快乐疯狂拉升";
a="阿奎讲空间阿萨德看来疯狂拉升到付款拉大手疯狂拉升德国ad搜房卡罗拉森林帝国法拉利岁的高龄拉萨ad搜房卡拉拉手断了的是卡夫卡独守空房卡死";


private Font font = Font.getDefaultFont();

private Vector contString = new Vector();

private void dealString(String string, Font font, int width) {
contString = new Vector();
int id = 0;
char temp=string.charAt(0);
if(temp!='\0'||temp!='\1'||temp!='\2'||temp!='\3'){
string="\0"+string;
}
StringBuffer sb = new StringBuffer();
while (id < string.length()) {
temp = string.charAt(id);
if (temp == '\0') {
if (sb.length() != 0) {
contString.addElement(sb.toString());
sb = new StringBuffer();
}
contString.addElement("" + 0);
} else if (temp == '\1') {
if (sb.length() != 0) {
contString.addElement(sb.toString());
sb = new StringBuffer();
}
contString.addElement("" + 1);
} else if (temp == '\2') {
if (sb.length() != 0) {
contString.addElement(sb.toString());
sb = new StringBuffer();
}
contString.addElement("" + 2);
} else if (temp == '\3') {
if (sb.length() != 0) {
contString.addElement(sb.toString());
sb = new StringBuffer();
}
contString.addElement("" + 3);
} else if (temp == '\n') {
if (sb.length() != 0) {
contString.addElement(sb.toString());
sb = new StringBuffer();
}
} else {
if (font.stringWidth(sb.toString()) < width) {
sb.append(temp);
if(id==string.length()-1){
contString.addElement(sb.toString());
}
} else {
contString.addElement(sb.toString());
sb = new StringBuffer();
sb.append(temp);
}
}
id++;
}
}

private void printString(Graphics g,int x,int y) {
g.setFont(font);
String temp="";
int count=0;
for(int i=0;i<contString.size();i++){
temp=contString.elementAt(i).toString();
if(temp=="0"){
g.setColor(0x0);
}else if(temp=="1"){
g.setColor(0xff0000);
}else if(temp=="2"){
g.setColor(0x00ff00);
}else if(temp=="3"){
g.setColor(0x0000ff);
}else{
g.drawString(temp, x, y+count*font.getHeight(), 0);
count++;
}
}
}

    
[2] 经过Wifi实现设备间的通信
    来源: 互联网  发布时间: 2014-02-18
通过Wifi实现设备间的通信
服务器端,建立监听(方法更新,可以同时连接多个Client)
public class Server extends ServerSocket {

	private static ArrayList<String> mUserList = new ArrayList<String>();
	private static ArrayList<Thread> mThreader = new ArrayList<Thread>();
	private static LinkedList<String> mMessageArray = new LinkedList<String>();
	private static int mThreadCounter = 0;
	private static boolean isClear = true;

	public Server(int port) throws IOException {

		super(port);
		new Broadcast();

		try {
			while (true) {
				Socket socket = accept();
				new CreateServerThread(socket);
			}
		} catch (IOException e) {
		} finally {
			close();
		}
	}

	// --- CreateServerThread
	class CreateServerThread extends Thread {

		private Socket client;
		private BufferedReader in;
		private PrintWriter out;
		private String username;

		public CreateServerThread(Socket s) throws IOException {
			client = s;
			in = new BufferedReader(new InputStreamReader(
					client.getInputStream(), "UTF8"));
			out = new PrintWriter(client.getOutputStream(), true);
			sendMessage("--- Welcome ---");
			sendMessage("Input your nickname:");
			start();
		}

		public void sendMessage(String msg) {
			out.println(msg);
			System.out.println(msg);
		}

		public void run() {
			try {
				int flag = 0;
				mThreadCounter++;
				String line = in.readLine();
				while (line == null || !line.equals("bye")) {
					if (line == null) {
						// sendMessage("null");
						line = in.readLine();
						continue;
					}

					if (line.equals("l")) {
						sendMessage(listOnlineUsers());
						line = in.readLine();
						continue;
					}

					if (flag++ == 0) {
						username = line;
						mUserList.add(username);
						sendMessage(listOnlineUsers());
						mThreader.add(this);
						pushMessage("[< " + username + " come on in >]");
					} else {
						pushMessage("<" + username + ">" + line);
					}

					line = in.readLine();
				}

				sendMessage("--- See you, bye! ---");
				client.close();
			} catch (IOException e) {
			} finally {
				try {
					client.close();
				} catch (IOException e) {
				}
				mThreadCounter--;
				mThreader.remove(this);
				mUserList.remove(username);
				pushMessage("[< " + username + " left>]");
			}
		}

		private String listOnlineUsers() {
			String s = "-+- Online list -+-1512";
			for (int i = 0; i < mUserList.size(); i++) {
				s += "[" + mUserList.get(i) + "]1512";
			}
			s += "-+---------------------+-";
			return s;
		}

		private void pushMessage(String msg) {
			mMessageArray.addLast(msg);
			isClear = false;
		}
	}

	// --- Broadcast
	class Broadcast extends Thread {
		public Broadcast() {
			start();
		}

		public void run() {
			while (true) {
				if (!isClear) {
					String tmp = mMessageArray.getFirst();
					for (int i = 0; i < mThreader.size(); i++) {
						CreateServerThread client = (CreateServerThread) mThreader
								.get(i);
						client.sendMessage(tmp);
					}
					mMessageArray.removeFirst();
					isClear = mMessageArray.size() > 0 ? false : true;
				}
			}
		}
	}
}

客户端,发送消息
public class Client {

	private Socket socket;
	private BufferedReader in;
	private PrintWriter out;

	public Client(String domain, int port) {
		connect(domain, port);
		get(in);
	}

	private void connect(String domain, int port) {
		try {
			socket = new Socket(domain, port);
			in = new BufferedReader(new InputStreamReader(
					socket.getInputStream()));
			out = new PrintWriter(socket.getOutputStream(), true);
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	private void get(final BufferedReader in) {

		new Thread(new Runnable() {

			public void run() {

				try {
					String line = in.readLine();
					while (true) {
						line = in.readLine();
					}
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}).start();
	}

	public void send(String msg) {
		out.println(msg);
	}

	public void disconnect() {
		try {
			out.close();
			in.close();
			socket.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

    
[3] 手机上网HTTP报文搜集
    来源: 互联网  发布时间: 2014-02-18
手机上网HTTP报文收集

--------Server accepted Header-------------
header:Host value:211.136.107.36
header:User-Agent value:defaut-usergent
header:Via value:WTP/1.1 BJBJ-PS-WAP2-GW03.bj2.monternet.com (Nokia WAP Gateway 4.0/CD3/4.1.29)
header:X-Nokia-gateway-id value:NWG/4.0/CD3/Build04
header:Connection value:close
header:Content-Length value:14
header:X-Forwarded-For value:10.14.136.43
header:X-Source-ID value:BJGGSN51BNk
header:X-Up-Bearer-Type value:GPRS
header:x-wap-profile value:defaut-uaprof
header:X-Up-Calling-Line-ID value:******
header:accept value:*/*
header:X-Nokia-CONNECTION_MODE value:TCP

--------Server accepted Header Over-----------
Header:connection;Value:Keep-Alive
Header:host;Value:wap.sjmen.cn
Header:accept;Value:application/vnd.wap.wmlscriptc, text/vnd.wap.wml, application/vnd.wap.xhtml+xml, application/xhtml+xml, text/html, multipart/mixed, */*
Header:accept-charset;Value:ISO-8859-1, US-ASCII, UTF-8; Q=0.8, ISO-10646-UCS-2;Q=0.6
Header:accept-language;Value:zh-CN
Header:via;Value:HTTP/1.1 GDGZ_WAP_GW06 (infoX-WISG, Huawei Technologies)
Header:x-up-calling-line-id;Value:861311*******
Header:x-forwarded-for;Value:10.128.109.237
Header:x-up-bear-type;Value:GPRS
Header:x-source-id;Value:uniwap
Header:user-agent;Value:Nokia6030/2.0 (5.11) Profile/MIDP-2.0 Configuration/CLDC-1.1
Header:x-wap-profile;Value:"http://nds1.nds.nokia.com/uaprof/N6030r100.xml"
Header:cookie2;Value:$Version="1"


Via: ZXWAP GateWay,ZTE Technologies
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,image/png,application/java-archive,application/java,application/x-java-archive,text/vnd.sun.j2me.app-descriptor,application/vnd.oma.drm.message,application/vnd.oma.drm.content,application/vnd.oma.dd+xml,application/vnd.oma.drm.rights+xml,application/vnd.oma.drm.rights+wbxml,application/x-nokia-widget,text/x-opml,application/vnd.nokia.headwrapper,*/*;q=0.5
Accept-Charset: iso-8859-1,utf-8;q=0.7,*;q=0.7
Accept-Encoding: gzip, deflate, x-gzip, identity; q=0.9
Accept-Language: zh-cn, zh;q=1.0,en;q=0.5,en;q=0.5,en;q=0.5
Host: wap.mzwu.com
Referer: http://nav.5k3g.com/
User-Agent: Mozilla/5.0 (SymbianOS/9.4; U; Series60/5.0 Nokia5800d-1/31.0.101; Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413
X-Nokia-MusicShop-Bearer: GPRS/3G
X-Nokia-MusicShop-Version: 11.0842.9
x-up-bear-type: GPRS/EDGE
x-forwarded-for: 10.149.235.122
x-source-id: 10.145.0.3
x-wap-profile: "http://nds1.nds.nokia.com/uaprof/Nokia5800d-1r100-2G.xml "
x-up-calling-line-id: 8613616750548
AspFilterSessionId: S(ut4a4rniu4lf2b2i2qbyvsuv)
原文链接:http://blog.csdn.net/rrrfff/article/details/6672630

    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3