- 浏览: 229349 次
- 性别:
- 来自: 广州
最新评论
-
Janne:
你好 有源代码?可以发到我的邮箱里学学吗?2731049993 ...
achartengine画出动态折线图的效果 -
anbo724:
我的邮箱 anbo724@gmail.com谢谢@
achartengine画出动态折线图的效果 -
anbo724:
你好 请问有源码没《?谢谢
achartengine画出动态折线图的效果 -
weiday123:
额,觉得这个会不会占堆内存?
AdapterView、Adapter优化 -
wen742538485:
为什么没有呢?权限没加还是发创建了给你删了再想创建?是不允许重 ...
Android中为你的应用程序添加桌面快捷方式
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Test extends Activity implements Runnable{
/** Called when the activity is first created. */
private Button btn_get = null;
private Button btn_post = null;
private TextView tv_rp = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn_get = (Button) this.findViewById(R.id.Button01);
btn_post = (Button) this.findViewById(R.id.Button02);
tv_rp = (TextView) this.findViewById(R.id.TextView);
btn_get.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
String httpUrl = "http://192.168.0.132:8080/Android/httpreq.jsp?par=request-get";
HttpGet request = new HttpGet(httpUrl);
HttpClient httpClient = new DefaultHttpClient();
try {
HttpResponse response = httpClient.execute(request);
if(response.getStatusLine().getStatusCode()==HttpStatus.SC_OK){
String str = EntityUtils.toString(response.getEntity());
tv_rp.setText(str);
}else{
tv_rp.setText("请求错误");
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
btn_post.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
String httpUrl = "http://192.168.0.132:8080/Android/httpreq.jsp";
HttpPost request = new HttpPost(httpUrl);
List<namevaluepair> params = new ArrayList<namevaluepair>();
params.add(new BasicNameValuePair("par","request-post"));
try {
HttpEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
request.setEntity(entity);
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(request);
if(response.getStatusLine().getStatusCode()==HttpStatus.SC_OK){
String str = EntityUtils.toString(response.getEntity());
tv_rp.setText(str);
}else{
tv_rp.setText("请求错误");
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
new Thread(this).start();
}
public void refresh(){
String httpUrl = "http://192.168.0.132:8080/Android/httpreq.jsp";
try {
URL url = new URL(httpUrl);
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
urlConn.connect();
InputStream input = urlConn.getInputStream();
InputStreamReader inputreader = new InputStreamReader(input);
BufferedReader reader = new BufferedReader(inputreader);
String str = null;
StringBuffer sb = new StringBuffer();
while((str = reader.readLine())!= null){
sb.append(str).append("\n");
}
if(sb != null){
tv_rp.setText(sb.toString());
}else{
tv_rp.setText("NULL");
}
reader.close();
inputreader.close();
input.close();
reader = null;
inputreader = null;
input = null;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public Handler handler = new Handler(){
public void handleMessage(Message msg){
super.handleMessage(msg);
refresh();
}
};
public void run() {
// TODO Auto-generated method stub
while(true){
try {
Thread.sleep(1000);
handler.sendMessage(handler.obtainMessage());
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
</namevaluepair></namevaluepair>
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Test extends Activity implements Runnable{
/** Called when the activity is first created. */
private Button btn_get = null;
private Button btn_post = null;
private TextView tv_rp = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn_get = (Button) this.findViewById(R.id.Button01);
btn_post = (Button) this.findViewById(R.id.Button02);
tv_rp = (TextView) this.findViewById(R.id.TextView);
btn_get.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
String httpUrl = "http://192.168.0.132:8080/Android/httpreq.jsp?par=request-get";
HttpGet request = new HttpGet(httpUrl);
HttpClient httpClient = new DefaultHttpClient();
try {
HttpResponse response = httpClient.execute(request);
if(response.getStatusLine().getStatusCode()==HttpStatus.SC_OK){
String str = EntityUtils.toString(response.getEntity());
tv_rp.setText(str);
}else{
tv_rp.setText("请求错误");
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
btn_post.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
String httpUrl = "http://192.168.0.132:8080/Android/httpreq.jsp";
HttpPost request = new HttpPost(httpUrl);
List<namevaluepair> params = new ArrayList<namevaluepair>();
params.add(new BasicNameValuePair("par","request-post"));
try {
HttpEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
request.setEntity(entity);
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(request);
if(response.getStatusLine().getStatusCode()==HttpStatus.SC_OK){
String str = EntityUtils.toString(response.getEntity());
tv_rp.setText(str);
}else{
tv_rp.setText("请求错误");
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
new Thread(this).start();
}
public void refresh(){
String httpUrl = "http://192.168.0.132:8080/Android/httpreq.jsp";
try {
URL url = new URL(httpUrl);
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
urlConn.connect();
InputStream input = urlConn.getInputStream();
InputStreamReader inputreader = new InputStreamReader(input);
BufferedReader reader = new BufferedReader(inputreader);
String str = null;
StringBuffer sb = new StringBuffer();
while((str = reader.readLine())!= null){
sb.append(str).append("\n");
}
if(sb != null){
tv_rp.setText(sb.toString());
}else{
tv_rp.setText("NULL");
}
reader.close();
inputreader.close();
input.close();
reader = null;
inputreader = null;
input = null;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public Handler handler = new Handler(){
public void handleMessage(Message msg){
super.handleMessage(msg);
refresh();
}
};
public void run() {
// TODO Auto-generated method stub
while(true){
try {
Thread.sleep(1000);
handler.sendMessage(handler.obtainMessage());
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
</namevaluepair></namevaluepair>
发表评论
-
Android Tween动画之RotateAnimation实现图片不停旋转
2012-11-26 22:38 1044本文主要介绍Android中如何使用rotate实现图片不停旋 ... -
Android实现widget定时更新
2012-11-04 20:20 887在开发Android的widget时,第一个需要解决的问题就是 ... -
来自腾讯、谷歌、百度等名企的精选面试五十题
2012-10-07 23:08 907http://www.apkway.com/thread-90 ... -
Android 中Parcelable的作用
2012-09-24 09:53 841android提供了一种新的类型:Parcel。本类被用作封装 ... -
[Android算法] 【eoeAndroid索引】史上最牛最全android开发知识汇总
2012-09-13 09:33 1096http://www.eoeandroid.com/threa ... -
安卓航班推荐70个具有商业实战性的精品Android源码
2012-08-01 00:00 919http://www.apkway.com/thread-58 ... -
Android测试教程汇总
2012-08-02 14:51 1071http://www.apkway.com/thread-67 ... -
Service 与 Thread 的区别
2012-07-26 00:10 884Service 与 Thread 的区别 很多时候,你可能 ... -
android 使用百度地图画轨迹
2012-07-26 00:08 2586import android.content.Context ... -
android百度地图半径画圆
2012-07-26 00:07 2718Java代码 import android.content ... -
Android下获取开机时间
2012-07-26 00:05 1301我的思路是:程序里注册个广播接收器,接收开机启动的广播,当程序 ... -
android 高仿【优酷】圆盘旋转菜单 的实现
2012-07-26 00:03 1341MyAnimation.java Java代码 pack ... -
android 3D 转盘效果(附源码)
2012-07-25 23:41 1782一个仿3D的转盘效果,有倒影特效,旋转图标还可自动放大缩小。由 ... -
Android Thread
2012-07-23 10:47 1015创建新线程的常用方式: 1. 直接使用Thread创建 ... -
Android 通过手说tts中文语音包实现中文朗读
2012-07-22 17:09 1782Android 通过手说tts中文语音包实现中文朗读 ... -
Android 使用HTTPClient调用Web请求(查询手机号码区域)
2012-07-21 00:33 1205Android通过Apache HttpClient调用网上提 ... -
Android+struts2+JSON方式的手机开发
2012-07-21 00:14 1141http://topmanopensource.iteye.c ... -
android九宫格实现
2012-07-21 00:03 946android九宫格实现,开始以为很复杂,其实只要知道了如何布 ... -
Android ListView圆角实现
2012-07-20 23:59 1183在android上开发项目,如 ... -
Android 将一个Activity转化为View显示出来
2012-07-19 10:27 2067最近看到好多opengl牛人写了些立方体,卷页之类的华丽的代码 ...
相关推荐
适合基础巩固学习 解析服务器json数据 ListView列表上拉加载 下拉刷新 自己做的程序 解释很全 经过验证 绝对运行成功 学习的好例子 希望对您有绝对的好帮助
android 商品列表上拉加载数据下拉刷新数据,直接导入eclipse 可运行,没有访问数据库可根据代码进行修改
Android请求服务器和解析数据,包含8个实例代码:android_json,android访问网络返回的XML数据并且进行解析,httpclient获取到JSON数据并展示到ListView,Json数据解析服务器端加客户端代码等等。
Android客户端和服务器端数据交互Demo01.zip,欢迎下载
android 实现listview动态下拉刷新,动态加载数据 可以避免一次数据加载过多
JSON从服务器下载数据到Android客户端 包括web端和Android手机端 注意修改ip和mySQL用户名 密码 详情见 http://blog.csdn.net/u011109881/article/details/40110613
android客户端与服务器进行数据交互,客户端上传数据至服务器,服务器返回值给客户端
主要介绍了Android中使用的定时针(刷新页面请求服务器)详解的相关资料,需要的朋友可以参考下
在Android Studio实现MQTT对主题的订阅和数据的收发,以及将数据封装成对象传回MainActivity,方便进行数据处理,其操作信息在TextView中展示相关的数据。对相关的数据一目了然,同时,在页面中为物联网的开发提供了...
实现从android客户端向php服务器传送数据,自己做的一个小demo,和大家分享
android定时开关机服务,通过广播设置重启/开关机服务,在国内某大型公司设备中有应用
AndroidUDP数据刷新ListView 友友们我会更新更多的源码和大家分享 希望大家喜欢.
android客户端从服务器端获取json数据并解析
Android 客户端与服务器端进行数据交互Demo(包含服务器端和客户端) 实现了基本的数据交互及验证
本程序是用Android手机去访问用java开发的服务器的数据,并让服务器 从数据库中访问数据库以JSON格式返回数据,在Android手机端将返回的数据 以JSON的格式解析出来。 本文件中的mysql.sql是我测试是的数据库,在...
android httpclient 访问服务器 获取json数据,里面有需要载入的外部jar包,添加源代码后再加入外部包就可。
TimerTask结合Handler实现了定时任务,可以定时刷新,定时验证短信等
Android客户端与服务器端的json数据交互(内含大量知识点),包含文件的上传,文件浏览器等。
Android如何从服务器获取图片
Android Socket编程实现服务器数据读取