当前位置:首页 » 安卓系统 » android上传数据

android上传数据

发布时间: 2024-04-20 05:36:43

❶ 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();
}
}
}
}

❷ 求助,Android如何定时上传数据到服务器

利用ftp定时上传log到其他服务器的方法

利用ftp定时上传log到其他服务器#!/bin/bash #时间的生成 Y=` date --date="-1 hour" +%Y` m=` date --date="-1 hour" +%m` d=`date --date="-1 hour" +%d` H=`date --date="-1 hour" +%H`

IPhone上传图片到服务器

求助:IPhone上传图片到服务器 我在网上看到 IPhone上传到服务器用的是PHP的web接收,地址: 我只会asp.net ,请问用ASP.net和IPhone怎么结合实现手机端的图片上传到服务器上? 求助!!! 重点在:if (move_uploaded_file($_FILES['u

android开发以上传图片到七牛云缓扮孙存储服务器

android开发之上传图片到七牛云缺激存储服务器 相信很多开发者会把图片存放到七牛上,我的web站点也是吧图片存储到七牛上,对于以图片为主的站点,这样可以节省很大带宽。 将图片上传到七牛服务器的重点就是获得上传凭证uploadToken,直接把AccessKey和Secret放到客户端太不安全,扰链容易被反编译。所以需要在服务器端根据AccessKey和Secret动态生成一个uploadToken,

❸ Android绋嫔簭瀹氭椂涓娄紶鏁版嵁杩愯屼竴涓灏忔椂宸﹀彸灏变笉涓娄紶鏁版嵁浜 宸茬粡瀹氭椂镣逛寒灞忓箷鍞ら啋CPU浜 杩欐槸android链哄埗镄

杩欑嶆垜鍒氩仛杩囩被浼肩殑锛屽悗鍙版湇锷¤嚜锷ㄥ畾镞朵笂浼犱綅缃锛岄挛灞忕姸镐佽繛缁宸ヤ綔10灏忔椂锛屾疮鍒嗛挓涓娄紶涓娆°备笉鐢ㄤ缭鎸佸敜阅掔姸镐佸拰镣逛寒灞忓箷锛岄潪甯哥渷鐢点

涓昏佹濊矾灏辨槸鐢ㄩ椆阍熺$悊鍣ㄦ潵淇濇寔涓涓猺epeat镄凯endingIntent銆

杩欑嶅姙娉曪纴涓嶆儳镐旷郴缁熶紤鐪狅纴涓嶉渶瑕佷缭鎸佸敜阅掋

/**

* 妫镆ラ厤缃浠ュ喅瀹氭槸钖﹀紑钖镊锷ㄦ洿鏂

*/

private void _startAutoUpdateAlarm(){

boolean autoUpdate = AppPreference.getAutoUpdate(this);

boolean isIntervalMinValid = AppPreference.isIntervalMinValid(this);

if(autoUpdate&&isIntervalMinValid&&null==_pendingIntent){

Utils.amLog("make repeat");

_pendingIntent = PendingIntent.getService(TraceService.this, 0,

new Intent(TraceService.this, TraceService.class),

Intent.FLAG_ACTIVITY_NEW_TASK);

_alarmManager.cancel(_pendingIntent);

long now = System.currentTimeMillis();

long intervalMillis = 60*1000*AppPreference.getIntervalMin(this);

_alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, now, intervalMillis, _pendingIntent);

_autoUpdateOn = true;

}else{

Utils.amLog("do not make repeat");

if(null==_pendingIntent){

_pendingIntent = PendingIntent.getService(TraceService.this, 0,

new Intent(TraceService.this, TraceService.class)

, Intent.FLAG_ACTIVITY_NEW_TASK);

}

_alarmManager.cancel(_pendingIntent);

_pendingIntent = null;

_autoUpdateOn = false;

}

}

@Override

public int onStartCommand(Intent intent, int flags, int startId) {

if(null==intent){

return super.onStartCommand(intent, flags, startId);

}

Utils.amLog("onStartCommand flags:"+intent.getFlags());

//褰撴湇锷¤钖庡彴(Alarm链嶅姟)璋幂敤镞讹纴涓娄紶浣岖疆

if(Intent.FLAG_FROM_BACKGROUND==intent.getFlags()){

_checkAndUpdateLocation();

}

return START_STICKY;

}

濡傛灉浣犻渶瑕佽繘涓姝ョ殑缁呜妭镄勮瘽锛岀暀涓闾绠辩猃鎶婅繖涓链嶅姟镄勪唬镰佺粰浣

❹ android开发,我想把手机上的数据上传到网页上

如果是数据同步,主要还是网络编程
客户端把数据打包发送到服务器,然后服务器解析数据,存储到数据库
然后就是你说的在网页上显示,这个说白了就是把查询数据,显示到前台
通信协议这一块可以使用TCP或者HTTP,使用HTTP的话还是方便一点如果使用TCP协议,难度可能会大一点,不过有开源的框架(Apache Mina)可以使用

热点内容
linux驱动开发教程 发布:2024-05-17 17:19:52 浏览:500
抖音中秋节视频脚本 发布:2024-05-17 17:19:51 浏览:193
快递柜为什么用安卓系统 发布:2024-05-17 17:17:18 浏览:906
电脑配置光纤接口怎么标注 发布:2024-05-17 17:06:56 浏览:976
如何用方向键控制安卓机 发布:2024-05-17 16:38:11 浏览:198
雨田系统源码 发布:2024-05-17 16:28:06 浏览:586
新手直播脚本 发布:2024-05-17 16:27:25 浏览:847
python双引号单引号 发布:2024-05-17 16:19:31 浏览:948
0xxc语言 发布:2024-05-17 16:17:40 浏览:700
php与java的区别 发布:2024-05-17 16:12:48 浏览:340