標籤:android http io os ar java sp 資料 art
問題描述
大家好,關於android 升級的問題想問下大家,求解答,先言謝了。。
我目前手機上的app版本的30,伺服器上的app是31.每一次app啟動的時候發送資訊區伺服器上擷取資料,其中 伺服器會給過來當前伺服器app版本,比對如果高於當前app則啟動升級程式。
升級的時候提示成功了。其實卻失敗了。情況是。應用程式列表的表徵圖和下面的字型都變化了,程式大小也變化了。但是進去之後UI內容沒變化。我實驗了很多次,卸載程式或者打成apk安裝,或者eclipse安裝,都一樣。確信的是伺服器上的Apk下載成功了。我的程式大致邏輯是:
要升級的時候啟動一個線程,下載伺服器上的apk,如下:
/** * 下載新程式 */ public void appUpdate(Context context){ HttpClient httpClient = new DefaultHttpClient();HttpGet get = new HttpGe("伺服器位址"+"/update/XXX.apk");HttpResponse response;InputStream is = null;FileOutputStream fileOutputStream = null;try {response = httpClient.execute(get);HttpEntity entity = response.getEntity();is = entity.getContent();long len = entity.getContentLength();if(is!=null){fileOutputStream = context.openFileOutput("XX.apk", Context.MODE_WORLD_READABLE+Context.MODE_WORLD_WRITEABLE);byte[] buf = new byte[1024];int ch = -1;while((ch = is.read(buf)) != -1){fileOutputStream.write(buf, 0, ch);}}fileOutputStream.flush();} catch (ClientProtocolException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{if(is != null){try {is.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}if(fileOutputStream != null) {try {fileOutputStream.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}} }
下載 完成後,在handler裡面 更新。
final Handler handler = new Handler() {@Overridepublic void handleMessage(Message msg) {try {switch (msg.what) {case 1:progressDialog.dismiss();Intent intent = new Intent(Intent.ACTION_VIEW);File file = new File("/data/data/包名/files/XXX.apk");Uri uri = Uri.fromFile(file);intent.setDataAndType(uri,"application/vnd.android.package-archive");context.startActivity(intent);break;default:break;}} catch (Exception e) {e.printStackTrace();}}
當程式啟動,android系統提示更新程式,點擊更新,彈出系統進度條,之後說安裝完成,進去之後如上面所說,裡面內容沒變化。 解決方案1
下載到SD卡上試試 解決方案2
先搞清楚你在伺服器上的31版本是不是正確 解決方案3
伺服器上的APK就是不對的感覺 解決方案4
你直接裝伺服器上的版本對不對?我自動升級沒出現過這麼扯的情況,想想也不大可能啊 解決方案5
你先確認一下 手機裡面data/app下面的odex或者apk時間和大小對不對
如果都是和伺服器上的一樣 上log吧
1.原始app啟動的log
2.下載到升級完成的log
3.新app啟動的log
filter全開 尤其是要注意packagemanager和package name的部分
android 自動更新升級的問題