當前位置:首頁 » 安卓系統 » 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)可以使用

熱點內容
pythonstrptime 發布:2024-11-27 12:34:50 瀏覽:954
怎麼判斷組裝電腦配置真假 發布:2024-11-27 12:30:18 瀏覽:379
周鴻禕編程 發布:2024-11-27 12:30:12 瀏覽:615
索賠的腳本 發布:2024-11-27 12:30:09 瀏覽:547
什麼是淘寶資料庫 發布:2024-11-27 12:30:08 瀏覽:373
聯系輔導員重設密碼需要什麼 發布:2024-11-27 12:19:16 瀏覽:510
android刷系統 發布:2024-11-27 12:18:40 瀏覽:915
安卓什麼是id密碼 發布:2024-11-27 11:52:39 瀏覽:446
zjs解壓 發布:2024-11-27 11:33:10 瀏覽:159
sql查看用戶許可權 發布:2024-11-27 11:25:23 瀏覽:9