新聞中心
安卓機(jī)如何獲取另一部安卓手機(jī)數(shù)據(jù)?
同品牌的手機(jī),可以通過備份到官方的云盤來做到一鍵換機(jī)。不同的,可以從云盤下載數(shù)據(jù)。
創(chuàng)新互聯(lián)服務(wù)項目包括宣威網(wǎng)站建設(shè)、宣威網(wǎng)站制作、宣威網(wǎng)頁制作以及宣威網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,宣威網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到宣威省份的部分城市,未來相信會繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
android怎么直接獲取數(shù)據(jù)庫數(shù)據(jù)
android讀取數(shù)據(jù)庫可以使用sqlite一些api進(jìn)行讀取,實例如下:
/**
* 查找一條數(shù)據(jù)
* @param uid
*/
public User find(Integer uid){
SQLiteDatabase db=dbOpenHelper.getReadableDatabase(); //創(chuàng)建數(shù)據(jù)庫輔助類
Cursor cursor =db.rawQuery("select * from user where uid=?", new String[]{uid.toString()}); //創(chuàng)建一個游標(biāo)
if(cursor.moveToFirst()){ //循環(huán)遍歷查找數(shù)組
int uid2=cursor.getInt(cursor.getColumnIndex("uid"));
String uname=cursor.getString(cursor.getColumnIndex("uname"));
String uaddress=cursor.getString(cursor.getColumnIndex("uaddress"));
User user=new User();
user.setUid(uid2);
user.setUname(uname);
user.setUaddress(uaddress);
return user;
}
cursor.close();
return null;
}
android 怎樣獲取后臺的數(shù)據(jù)?
可使用android自帶的httpclient框架,向后臺發(fā)起請求,獲取數(shù)據(jù)。\x0d\x0a\x0d\x0a1. GET 方式傳遞參數(shù)\x0d\x0a//先將參數(shù)放入List,再對參數(shù)進(jìn)行URL編碼\x0d\x0aList params = new LinkedList();\x0d\x0aparams.add(new BasicNameValuePair("param1", "數(shù)據(jù)")); //增加參數(shù)1\x0d\x0aparams.add(new BasicNameValuePair("param2", "value2"));//增加參數(shù)2\x0d\x0aString param = URLEncodedUtils.format(params, "UTF-8");//對參數(shù)編碼\x0d\x0aString baseUrl = "服務(wù)器接口完整URL";\x0d\x0aHttpGet getMethod = new HttpGet(baseUrl + "?" + param);//將URL與參數(shù)拼接\x0d\x0aHttpClient httpClient = new DefaultHttpClient();\x0d\x0atry {\x0d\x0a HttpResponse response = httpClient.execute(getMethod); //發(fā)起GET請求\x0d\x0a Log.i(TAG, "resCode = " + response.getStatusLine().getStatusCode()); //獲取響應(yīng)碼\x0d\x0a Log.i(TAG, "result = " + EntityUtils.toString(response.getEntity(), "utf-8"));//獲取服務(wù)器響應(yīng)內(nèi)容\x0d\x0a} catch (ClientProtocolException e) {\x0d\x0a e.printStackTrace();\x0d\x0a} catch (IOException e) {\x0d\x0a e.printStackTrace();\x0d\x0a}\x0d\x0a\x0d\x0a2. POST方式 方式傳遞參數(shù)\x0d\x0a//和GET方式一樣,先將參數(shù)放入List\x0d\x0aparams = new LinkedList();\x0d\x0aparams.add(new BasicNameValuePair("param1", "Post方法"));//增加參數(shù)1\x0d\x0aparams.add(new BasicNameValuePair("param2", "第二個參數(shù)"));//增加參數(shù)2\x0d\x0atry {\x0d\x0a HttpPost postMethod = new HttpPost(baseUrl);//創(chuàng)建一個post請求\x0d\x0a postMethod.setEntity(new UrlEncodedFormEntity(params, "utf-8")); //將參數(shù)填入POST Entity中\(zhòng)x0d\x0a HttpResponse response = httpClient.execute(postMethod); //執(zhí)行POST方法\x0d\x0a Log.i(TAG, "resCode = " + response.getStatusLine().getStatusCode()); //獲取響應(yīng)碼\x0d\x0a Log.i(TAG, "result = " + EntityUtils.toString(response.getEntity(), "utf-8")); //獲取響應(yīng)內(nèi)容\x0d\x0a} catch (UnsupportedEncodingException e) {\x0d\x0a e.printStackTrace();\x0d\x0a} catch (ClientProtocolException e) {\x0d\x0a e.printStackTrace();\x0d\x0a} catch (IOException e) {\x0d\x0a e.printStackTrace();\x0d\x0a}
android怎么獲取服務(wù)器數(shù)據(jù)
一:基于Http協(xié)議獲取數(shù)據(jù)方法。二:基于SAOP協(xié)議獲取數(shù)據(jù)方法,
這篇文章主要是將關(guān)于使用Http協(xié)議獲取服務(wù)器端數(shù)據(jù),這里我們采取的服務(wù)器端技術(shù)為java,框架為Struts2,或者可以有Servlet,又或者可直接從JSP頁面中獲取數(shù)據(jù)。
那么,接下來我們便開始這一路程:
首先:編寫服務(wù)器端方法,我這里采用的MVC框架是Struts2,目的很單純,就是為了以后做個完整的商業(yè)項目,技術(shù)配備為:android+SSH。當(dāng)然,篇幅有限,我這里就直接用Strtus2而已。
服務(wù)器端:新建WebProject ,選擇Java ee 5.0.
為了給項目添加Struts2的支持,我們必須導(dǎo)入Struts2的一些類庫,如下即可(有些jar包是不必的,但是我們后來擴(kuò)展可能是要使用到的,就先弄進(jìn)去):
1: xwork-core-2.2.1.1.jar
2: struts2-core-2.2.1.1.jar
3: commons-logging-1.0.4.jar
4: freemarker-2.3.16.jar
5: ognl-3.0.jar
6: javassist-3.7.ga.jar
7:commons-ileupload.jar
8:commons-io.jar
9:json-lib-2.1-jdk15.jar 處理JSON格式數(shù)據(jù)要使用到
10:struts2-json-plugin-2.2.1.1.jar 基于struts2的json插件
以上的jar包,需要放在WebRoot/WEB-INF/lib目錄下
然后在web.xml文件中敲下:
View Code
?xml version="1.0" encoding="UTF-8"?
web-app version="2.5"
xmlns=""
xmlns:xsi=""
xsi:schemaLocation="
"
!-- 定義Struts2的核心控制器:FilterDispatcher --
filter
!-- 定義核心Filter的名稱 --
filter-namestruts2/filter-name
!-- 定義Filter的實現(xiàn)類 --
filter-classorg.apache.struts2.dispatcher.FilterDispatcher/filter-class
/filter
filter-mapping
filter-namestruts2/filter-name
url-pattern/*/url-pattern
/filter-mapping
welcome-file-list
welcome-fileindex.jsp/welcome-file
/welcome-file-list
/web-app
然后編寫struts.xml文件,并放在WebRoot/WEB-INF/lib目錄下:如下代碼:
View Code
?xml version="1.0" encoding="UTF-8"?
!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
""
struts
!-- setting encoding,DynamicMethod,language
constant name="struts.custom.i18n.resources" value="messageResource"/constant
--
constant name="struts.i18n.encoding" value="UTF-8"/constant
constant name="struts.enable.DynamicMethodInvocation" value="true"/constant
!-- add package here extends="struts-default"--
package name="dongzi" extends="json-default" !--需要將struts-default改為json-default--
!-- setting action --
action name="login" class="com.dongzi.action.loginAction" method="login"
result type="json"/result !--返回值類型設(shè)置為json,不設(shè)置返回頁面--
/action
/package
/struts
配置好后,我們再根據(jù)action標(biāo)簽內(nèi)容來編寫action。方法為method對應(yīng)的login,類名為loginAction,
注意:包繼承為:json-default ,輸出結(jié)果類型為json
如下:
View Code
public class loginAction extends ActionSupport implements
ServletRequestAware,ServletResponseAware {
/**
*
*/
private static final long serialVersionUID = 1L;
HttpServletRequest request;
HttpServletResponse response;
public void setServletRequest(HttpServletRequest request) {
this.request=request;
}
public void setServletResponse(HttpServletResponse response) {
this.response=response;
}
public void login(){
try {
//HttpServletRequest request =ServletActionContext.getRequest();
// HttpServletResponse response=ServletActionContext.getResponse();
this.response.setContentType("text/html;charset=utf-8");
this.response.setCharacterEncoding("UTF-8");
if(this.request.getParameter("username").equals("123456")){
this.response.getWriter().write("真的很奇怪,日本人!");
}else if(this.request.getParameter("username").equals("zhd")){
this.response.getWriter().write("沒有錯,我就是東子哥!");
}else{
this.response.getWriter().write("我就是東子哥!");
}
//將要返回的實體對象進(jìn)行json處理
// JSONObject json=JSONObject.fromObject(this.getUsername());
//輸出格式如:{"id":1, "username":"zhangsan", "pwd":"123"}
// System.out.println(json);
// this.response.getWriter().write(json.toString());
/**
JSONObject json=new JSONObject();
json.put("login", "login");
response.setContentType("text/html;charset=utf-8");
System.out.println(json);
byte[] jsonBytes = json.toString().getBytes("utf-8");
response.setContentLength(jsonBytes.length);
response.getOutputStream().write(jsonBytes);
**/
/**
JSONObject json=new JSONObject();
json.put("login", "login");
byte[] jsonBytes = json.toString().getBytes("utf-8");
response.setContentType("text/html;charset=utf-8");
response.setContentLength(jsonBytes.length);
response.getOutputStream().write(jsonBytes);
response.getOutputStream().flush();
response.getOutputStream().close();
**/
} catch (Exception e) {
e.printStackTrace();
}
// return null;
}
}
android中在怎么獲取數(shù)據(jù)庫數(shù)據(jù)
android讀取數(shù)據(jù)庫可以使用sqlite一些api進(jìn)行讀取,實例如下:
/**
* 查找一條數(shù)據(jù)
* @param uid
*/
public User find(Integer uid){
SQLiteDatabase db=dbOpenHelper.getReadableDatabase(); //創(chuàng)建數(shù)據(jù)庫輔助類
Cursor cursor =db.rawQuery("select * from user where uid=?", new String[]{uid.toString()}); //創(chuàng)建一個游標(biāo)
if(cursor.moveToFirst()){ //循環(huán)遍歷查找數(shù)組
int uid2=cursor.getInt(cursor.getColumnIndex("uid"));
String uname=cursor.getString(cursor.getColumnIndex("uname"));
String uaddress=cursor.getString(cursor.getColumnIndex("uaddress"));
User user=new User();
user.setUid(uid2);
user.setUname(uname);
user.setUaddress(uaddress);
return user;
}
cursor.close();
return null;
}
網(wǎng)站欄目:android數(shù)據(jù)獲取,android通過api獲取數(shù)據(jù)
文章網(wǎng)址:http://ef60e0e.cn/article/phjhcp.html