編輯:高級開發
Java代碼
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.clIEnt.entity.UrlEncodedFormEntity;
import org.apache.http.clIEnt.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClIEnt;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import android.util.Base64;
import android.util.Log;
/**
* TODO FIX Check the file length, it's long not int.This may lead the
* problem.
*
* @param fileName
* @param url
* @return
*/
public static boolean httpPostBase64(String fileName, String url) {
try {
File file = new File(fileName);
FileInputStream in = new FileInputStream(file);
byte[] buffer = new byte[(int) file.length() + 100];
int length = in.read(buffer);
String data = Base64.encodeToString(buffer, 0, length,
Base64.DEFAULT);
HttpPost httpRequest = new HttpPost(url);
/*
* NameValuePair實現請求參數的封裝
*/
List params = new LinkedList();
params.add(new BasicNameValuePair("data", data));
/* 添加請求參數到請求對象 */
httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
/* 發送請求並等待響應 */
HttpResponse httpResponse = new DefaultHttpClIEnt()
.execute(httpRequest);
/* 若狀態碼為200 ok */
if (httpResponse.getStatusLine().getStatusCode() != 200) {
Log.d("Code", httpResponse.getStatusLine().toString());
return false;
}
} catch (Exception e) {
for(StackTraceElement s:e.getStackTrace())
接上頁
Log.d("Exception",s.toString());
Log.d("Exception",e.getLocalizedMessage());
return false;
}
return true;
}
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.clIEnt.entity.UrlEncodedFormEntity;
import org.apache.http.clIEnt.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClIEnt;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import android.util.Base64;
import android.util.Log;
/**
* TODO FIX Check the file length, it's long not int.This may lead the
* problem.
*
* @param fileName
* @param url
* @return
*/
public static boolean httpPostBase64(String fileName, String url) {
try {
File file = new File(fileName);
FileInputStream in = new FileInputStream(file);
byte[] buffer = new byte[(int) file.length() + 100];
int length = in.read(buffer);
String data = Base64.encodeToString(buffer, 0, length,
Base64.DEFAULT);
HttpPost httpRequest = new HttpPost(url);
/*
* NameValuePair實現請求參數的封裝
*/
List params = new LinkedList();
params.add(new BasicNameValuePair("data", data));
/* 添加請求參數到請求對象 */
httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
/* 發送請求並等待響應 */
HttpResponse httpResponse = new DefaultHttpClIEnt()
.execute(httpRequest);
/* 若狀態碼為200 ok */
if (httpResponse.getStatusLine().getStatusCode() != 200) {
Log.d("Code", httpResponse.getStatusLine().toString());
return false;
}
} catch (Exception e) {
for(StackTraceElement s:e.getStackTrace())
Log.d("Exception",s.toString());
Log.d("Exception",e.getLocalizedMessage());
return false;
}
return true;
}
框架布局是將控件組織在android程序的用戶界面中最簡單的布局類型之一。理解布局對於良好的android程序設計來說是非常重要的。在這個教程裡,你將學到所有關於框架布
編者注:本文為android的官方開發者博客發了一份幻燈片的翻譯文檔的第二部分,專門介紹了一些android UI設計的小貼士,我們在介紹這個幻燈片的第一部分《多圖詳解
android作為谷歌最重要的資本之一,盡管在智能終端上的起步較蘋果晚不少,然而面對強有力的競爭對手,從不停追趕到部分超越,已為其未來戰略目標做好了充分鋪墊。迄今,全球
在實現了android系統平台的強大性,現就將引擎的前兩個元素即攝像頭與指南針之後,下一步要做的就是確定位置,要想更好的完成這一項目,我們主要用到android的Loc