![【移動應(yīng)用開發(fā)技術(shù)】 挑戰(zhàn)獨立開發(fā)項目能力-IT藍豹_第1頁](http://file4.renrendoc.com/view/b06584f88214df90cf532f985c2db523/b06584f88214df90cf532f985c2db5231.gif)
![【移動應(yīng)用開發(fā)技術(shù)】 挑戰(zhàn)獨立開發(fā)項目能力-IT藍豹_第2頁](http://file4.renrendoc.com/view/b06584f88214df90cf532f985c2db523/b06584f88214df90cf532f985c2db5232.gif)
![【移動應(yīng)用開發(fā)技術(shù)】 挑戰(zhàn)獨立開發(fā)項目能力-IT藍豹_第3頁](http://file4.renrendoc.com/view/b06584f88214df90cf532f985c2db523/b06584f88214df90cf532f985c2db5233.gif)
![【移動應(yīng)用開發(fā)技術(shù)】 挑戰(zhàn)獨立開發(fā)項目能力-IT藍豹_第4頁](http://file4.renrendoc.com/view/b06584f88214df90cf532f985c2db523/b06584f88214df90cf532f985c2db5234.gif)
![【移動應(yīng)用開發(fā)技術(shù)】 挑戰(zhàn)獨立開發(fā)項目能力-IT藍豹_第5頁](http://file4.renrendoc.com/view/b06584f88214df90cf532f985c2db523/b06584f88214df90cf532f985c2db5235.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
【移動應(yīng)用開發(fā)技術(shù)】
挑戰(zhàn)獨立開發(fā)項目能力--IT藍豹
做了5年的android開發(fā),今天沒事寫寫剛?cè)胄胁痪玫臅r候第一次獨立開發(fā)項目的心得體會,
當(dāng)時我剛工作8個月,由于公司運營不善倒閉了,在2011年3月份我開始準(zhǔn)備跳槽,
看了一周android筆試題和面試題后,然后就去找工作,當(dāng)時去面試的時候說自己有獨立項目開發(fā)的經(jīng)驗。
結(jié)果面上了幾家公司,后來選擇一家游戲公司,開始游戲開發(fā)的生涯。當(dāng)時我去的時候就android組就我一個人,
也沒有人帶領(lǐng),去公司一個月后公司決定要我把網(wǎng)游游戲移植到手游,那時候確實沒有獨立開發(fā)項目的經(jīng)驗。
但是又只有一個人做,沒辦法只有自己慢慢研究,那時候沒有像現(xiàn)在資源多,網(wǎng)上隨便找。
還是堅持慢慢從網(wǎng)絡(luò)框架一步一步開始搭建。當(dāng)時獨立做完項目后感覺個人技術(shù)能力瞬間提高了很多,因為不在還怕獨立承擔(dān)項目了。
希望我的感受能給同樣剛?cè)胄械呐笥涯芙o與幫助。如今本人自己做一個技術(shù)網(wǎng)站:IT藍豹()
當(dāng)時使用的網(wǎng)絡(luò)框架是HttpClient,先實現(xiàn)ReceiveDataListener接口用來接收數(shù)據(jù)返回,然后設(shè)置如下代碼調(diào)用
調(diào)用方法:
privatevoidinitHttpClient(){
if(mHttpClient==null){
mHttpClient=HttpClientFactory
.newInstance(Constants.CONNECTION_TIMEOUT);
mHttpTransport=newHttpTransport(mHttpClient);
mHttpTransport.setReceiveDataListener(this);
}
}
網(wǎng)絡(luò)請求代碼部分如下:HttpClientFactory類
importjava.io.InputStream;importjava.security.KeyManagementException;importjava.security.KeyStore;importjava.security.KeyStoreException;importjava.security.NoSuchAlgorithmException;importjava.security.UnrecoverableKeyException;importorg.apache.http.HttpVersion;importorg.apache.http.client.HttpClient;importorg.apache.http.conn.params.ConnManagerParams;importorg.apache.http.conn.scheme.PlainSocketFactory;importorg.apache.http.conn.scheme.Scheme;importorg.apache.http.conn.scheme.SchemeRegistry;importorg.apache.http.impl.client.DefaultHttpClient;importorg.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;importorg.apache.http.params.BasicHttpParams;importorg.apache.http.params.HttpConnectionParams;importorg.apache.http.params.HttpParams;importorg.apache.http.params.HttpProtocolParams;/**
*Afactoryclasstoobtainasetup{@linkHttpClient}instancetobeused
*amongmultiplethreads.Thisinstanceshouldbekeptopenthroughoutthe
*applicationslifetimeandmustonlybeclosediftheclientisnotneeded
*anymore.
*<p>
*Thisfactorywillneverreturnasingletonsuchthateachcallto
*{@linkHttpClientFactory#newInstance(int,KeyStore)}resultsinanew
*instance.Commonlyonlyonecalltothismethodisneededforanapplicaiton.
*</p>
*/publicclassHttpClientFactory{
/**
*CreatesanewHttpClientinstancesetupwiththegiven{@linkKeyStore}.
*Theinstanceusesamulti-threadedconnectionmanagerwitha
*max-connectionsizesetto10.Aconnectionisreleasedbacktothepool
*oncetheresponse{@linkInputStream}isclosedorreaduntilEOF.
*<p>
*<b>Note:</b>AndroiddoesnotsupporttheJKSkeystoreprovider.For
*androidBKSshouldbeused.See<ahref="/">
*BouncyCastle</a>fordetails.
*</p>
*
*@paramaConnectionTimeout
*
theconnectiontimeoutforthis{@linkHttpClient}
*@paramaKeyStore
*
acryptographickeystorecontainingCA-Certificatesfor
*
trustedhosts.
*@returnanew{@linkHttpClient}instance.
*@throwsKeyManagementException
*
Ifthe{@linkKeyStore}initializationthrowsanexception
*@throwsNoSuchAlgorithmException
*
ifsslsocketfactorydoesnotsupportthekeystores
*
algorithm
*@throwsKeyStoreException
*
ifthe{@linkKeyStore}cannotbeopened.
*@throwsUnrecoverableKeyException
*
Ihavenotideawhenthishappens:)
*/
publicstaticHttpClientnewInstance(intaConnectionTimeout/*
*,KeyStore
*aKeyStore
*/)
/*
*throwsKeyManagementException,NoSuchAlgorithmException,
*KeyStoreException,UnrecoverableKeyException
*/{
finalHttpParamsparams=newBasicHttpParams();
HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params,"UTF-8");
HttpConnectionParams.setConnectionTimeout(params,aConnectionTimeout);
HttpConnectionParams.setTcpNoDelay(params,false);
//finalSSLSocketFactorysocketFactory=new
//SSLSocketFactory(aKeyStore);
//socketFactory
//.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
finalSchemeRegistryregistry=newSchemeRegistry();
registry.register(newScheme("http",newPlainSocketFactory(),80));
//registry.register(newScheme("https",socketFactory,443));
//connectionpoolislimitedto20connections
ConnManagerParams.setMaxTotalConnections(params,20);
//ServoConnPerRoutelimitsconnectionsperroute/host-currently
//thisisaconstant
ConnManagerParams.setMaxConnectionsPerRoute(params,
newAndhatConnPerRoute());
finalDefaultHttpClientdefaultHttpClient=newDefaultHttpClient(
newThreadSafeClientConnManager(params,registry),params);
returndefaultHttpClient;
}}
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
HttpTransport類代碼如下:packagecom.andhat.android.http;importjava.io.ByteArrayOutputStream;importjava.io.Closeable;importjava.io.IOException;importjava.io.InputStream;import.URI;importjava.util.List;importorg.apache.http.HttpHost;importorg.apache.http.HttpRequest;importorg.apache.http.HttpResponse;importorg.apache.http.HttpStatus;importorg.apache.http.NameValuePair;importorg.apache.http.StatusLine;importorg.apache.http.client.ClientProtocolException;importorg.apache.http.client.HttpClient;importorg.apache.http.client.entity.UrlEncodedFormEntity;importorg.apache.http.client.methods.HttpGet;importorg.apache.http.client.methods.HttpPost;importorg.apache.http.conn.params.ConnRoutePNames;importtocol.HTTP;importcom.andhat.android.utils.Constants;importcom.andhat.android.utils.UserPreference;importcom.andhat.android.utils.Utils;importandroid.content.Context;importandroid.os.Handler;importandroid.util.Log;publicclassHttpTransport{
privatefinalHttpClient_client;
privateReceiveDataListenermRecListener;
publicfinalstaticintRECEIVE_DATA_MIME_STRING=0;
publicfinalstaticintRECEIVE_DATA_MIME_PICTURE=1;
publicfinalstaticintRECEIVE_DATA_MIME_AUDIO=2;
publicHttpTransport(HttpClientaClient){
_client=aClient;
}
/**
*關(guān)閉連接
*/
publicvoidshutdown(){
if(_client!=null&&_client.getConnectionManager()!=null){
_client.getConnectionManager().shutdown();
}
}
publicvoidpost(booleanproxy,Handlerhandler,Stringurl,
List<NameValuePair>params,intmime)
throwsClientProtocolException,IOException{
if(proxy){
postByCMCCProxy(url,handler,params,mime);
}else{
post(URI.create(url),handler,params,mime);
}
}
privatevoidpostByCMCCProxy(Stringurl,Handlerhandler,
List<NameValuePair>params,intmime)
throwsClientProtocolException,IOException{
Stringhost=getHostByUrl(url);
Stringport=getPortByUrl(url);
HttpHostproxy=newHttpHost("72",80,"http");
HttpHosttarget=newHttpHost(host,Integer.parseInt(port),"http");
_client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy);
HttpPostpost=newHttpPost(url);
if(params!=null&¶ms.size()>0){
post.setEntity(newUrlEncodedFormEntity(params,HTTP.UTF_8));
}
HttpResponsehttpResponse=_client.execute(target,post);
StatusLinestatusLine=httpResponse.getStatusLine();
finalintstatus=statusLine.getStatusCode();
if(status!=HttpStatus.SC_OK){
Stringmessage="HTTPResponsecode:"
+statusLine.getStatusCode()+"-"
+statusLine.getReasonPhrase();
Log.e("connectmsg",message);
thrownewIOException(message);
}
InputStreamin=httpResponse.getEntity().getContent();
longlength=httpResponse.getEntity().getContentLength();
byte[]data=receiveData(null,url,in,length);
if(mRecListener!=null){
mRecListener.receive(data,mime);
}
handler.sendEmptyMessage(Constants.MSG_THAN_FILE);
post.abort();
}
//54:8080/AnimeInterface/Interface.do
privatevoidpost(URIuri,Handlerhandler,List<NameValuePair>params,
intmime)throwsClientProtocolException,IOException{
Log.e("Goo","HttpTransportpost()");
//try{
HttpPostpost=newHttpPost(uri);
if(params!=null&¶ms.size()>0){
post.setEntity(newUrlEncodedFormEntity(params,HTTP.UTF_8));
}
HttpResponsehttpResponse=_client.execute(post);
StatusLinestatusLine=httpResponse.getStatusLine();
finalintstatus=statusLine.getStatusCode();
if(status!=HttpStatus.SC_OK){
Stringmessage="HTTPResponsecode:"
+statusLine.getStatusCode()+"-"
+statusLine.getReasonPhrase();
shutdown();
thrownewIOException(message);
}
InputStreamin=httpResponse.getEntity().getContent();
longlength=httpResponse.getEntity().getContentLength();
byte[]data=receiveData(null,uri.toString(),in,length);
if(mRecListener!=null){
mRecListener.receive(data,mime);
}
handler.sendEmptyMessage(Constants.MSG_THAN_FILE);
post.abort();
//}catch(IllegalStateExceptione){
//Log.e("Goo","程序異常");
//shutdown();
//e.printStackTrace();
//}
}
publicvoidget(booleanproxy,Contextcontext,Handlerhanlder,
Stringurl,intmime)throwsIOException{
if(proxy){
getByCMCCProxy(url,context,hanlder,mime);
}else{
get(URI.create(url),context,hanlder,mime);
}
UserPreference.ensureIntializePreference(context);
}
privateStringgetPortByUrl(Stringurl){
intstart=url.indexOf(":");
if(start<0)
return"80";
ints=url.indexOf(":",start+1);
if(s<0)
return"80";
inte=url.indexOf("/",s+1);
if(e<0){
returnurl.substring(s+1);
}else{
returnurl.substring(s+1,e);
}
}
privateStringgetHostByUrl(Stringurl){
intstart=url.indexOf(":");
if(start<0)
returnnull;
ints=url.indexOf(":",start+1);
if(s>=0)
returnurl.substring(0,s);
inte=url.indexOf("/",start+3);
if(e>=0){
returnurl.substring(0,e);
}else{
returnurl;
}
}
privatevoidgetByCMCCProxy(Stringurl,Contextcontext,Handlerhandler,
intmime)throwsClientProtocolException,IOException{
Log.e("requesturl",url);
//try{
Stringhost=getHostByUrl(url);
Stringport=getPortByUrl(url);
HttpHostproxy=newHttpHost("72",80,"http");
HttpHosttarget=newHttpHost(host,Integer.parseInt(port),"http");
_client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy);
HttpGetget=newHttpGet(url);
HttpResponsehttpResponse=_client.execute(target,get);
StatusLinestatusLine=httpResponse.getStatusLine();
finalintstatus=statusLine.getStatusCode();
Log.e("getByCMCCProxystatus",""+status);
if(status!=HttpStatus.SC_OK){
Stringmessage="HTTPResponsecode:"
+statusLine.getStatusCode()+"-"
+statusLine.getReasonPhrase();
Log.e("getByCMCCProxy",message);
thrownewIOException(message);
}
InputStreamin=httpResponse.getEntity().getContent();
longlength=httpResponse.getEntity().getContentLength();
Log.e("Goo","GetRequestEntityLength:"+String.valueOf(length));
byte[]data=receiveData(context,url.toString(),in,length);
Log.e("Goo","datalength:"+String.valueOf(data.length));
if(mRecListener!=null&&length==data.length){
mRecListener.receive(data,mime);
}
handler.sendEmptyMessage(Constants.MSG_THAN_FILE);
get.abort();
//}catch(Exceptione){
//shutdown();
//e.printStackTrace();
//}
}
privatevoidget(URIuri,Contextcontext,Handlerhandler,intmime)
throwsIOException{
//try{
finalHttpGetget=newHttpGet(uri);
HttpResponsehttpResponse=_client.execute(get);
StatusLinestatusLine=httpResponse.getStatusLine();
finalintstatus=statusLine.getStatusCode();
if(status!=HttpStatus.SC_OK){
Stringmessage="HTTPResponsecode:"
+statusLine.getStatusCode()+"-"
+statusLine.getReasonPhrase();
thrownewIOException(message);
}
InputStreamin=httpResponse.getEntity().getContent();
longdownloadLength=httpResponse.getEntity().getContentLength();
byte[]data=receiveData(context,uri.toString(),in,downloadLength);
if(mRecListener!=null){
mRecListener.receive(data,mime);
}
handler.sendEmptyMessage(Constants.MSG_THAN_FILE);
get.abort();
//}catch(IllegalStateExceptione){
//shutdown();
//e.printStackTrace();
//}
}
publicbyte[]receiveData(Contextcontext,Stringurl,InputStreamin,longlength)
throwsIOException{
ByteArrayOutputStreambos=null;
intdownloadSize=0;
byte[]retval=null;
Stringstr=url;
String[]s=str.split("/");
for(Strings1:s){
if(s1.contains(".")&&s1.endsWith(".gif")
||s1.endsWith(".amr")){
saveFailFile(context,s1);
Log.e("Goo_downLoadSize","fileName:"+s1);
}
}
try{
bos=newByteArrayOutputStream();
byte[]buf=newbyte[1024];
intlen=0;
while((len=in.read(buf))!=-1){
bos.write(buf,0,len);
downloadSize=len+downloadSize;
}
Log.e("Goo_downLoadSize","downloadSize:"+downloadSize+"");
Log.e("Goo_downLoadSize","length:"+length+"");
if(downloadSize==length&&downloadSize!=-1){
saveFailFile(context,null);
}
retval=bos.toByteArray();
}catch(Exceptione){
e.printStackTrace();
}finally{
try{
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 申請書 借東西
- 2024-2025學(xué)年高中數(shù)學(xué)第2章函數(shù)章末復(fù)習(xí)課學(xué)案北師大版必修1
- 訴求增加申請書
- 現(xiàn)代企業(yè)管理的挑戰(zhàn)與對策分析報告解讀
- 自律委員會申請書
- 2025年度家校合作學(xué)生科技創(chuàng)新活動支持合同
- 農(nóng)民工勞動標(biāo)準(zhǔn)合同范本2025年度全新版
- 2025年度國際運輸合同中過錯責(zé)任的明確約定與執(zhí)行
- 物流業(yè)信息化建設(shè)的成功案例與啟示
- 2025年度樣板房裝修施工與室內(nèi)環(huán)境檢測合同
- 水土保持方案中沉沙池的布設(shè)技術(shù)
- 安全生產(chǎn)技術(shù)規(guī)范 第25部分:城鎮(zhèn)天然氣經(jīng)營企業(yè)DB50-T 867.25-2021
- 現(xiàn)代企業(yè)管理 (全套完整課件)
- 走進本土項目化設(shè)計-讀《PBL項目化學(xué)習(xí)設(shè)計》有感
- 《網(wǎng)店運營與管理》整本書電子教案全套教學(xué)教案
- 教師信息技術(shù)能力提升培訓(xùn)課件希沃的課件
- 高端公寓住宅項目營銷策劃方案(項目定位 發(fā)展建議)
- 執(zhí)業(yè)獸醫(yī)師聘用協(xié)議(合同)書
- 第1本書出體旅程journeys out of the body精教版2003版
- [英語考試]同等學(xué)力英語新大綱全部詞匯
- 2022年肝動脈化療栓塞術(shù)(TACE)
評論
0/150
提交評論