當前位置:首頁 » 安卓系統 » android版本更新的代碼

android版本更新的代碼

發布時間: 2023-05-23 09:34:52

⑴ Android項目更新版本問題

之前我們團隊十五人開發一個項目,開始時沒什麼問題,一直相安無事。
後來有些人升級到了20.0,陸陸續續svn上下載的代碼會報錯,用20.0的人會報錯,而非最新版的不報錯。
原因很簡單,有些錯誤在低版本里不算錯誤,沒有檢測,但在新版本里檢測更嚴格,所以報錯。
到後來大家還是統一升到了20.0.
所以只要你們開發時沒有出現報錯,還是不用管版本問題的。
當然,統一一下是更好了。
是否可以解決您的問題?

⑵ android應用舊版本自動更新代碼未實現,用戶使用的是老版本,怎樣讓用戶更新到新版本

那就沒辦法了,看你app里有沒有通知侍陵用戶消息的桐談銷一些東西吧,如果有消息推送的局游話,可以給用戶推送新地址。

⑶ android開發應用版本升級怎麼實現

應用場景: 1、在界面中顯示應用程序的版本號; 2、用戶啟動該應用,後台判斷該應用是否是最新版本。 上述情景都需要在程序中自動獲取到應用的版本號。 思路簡介: 在Android中,應用程序的版本號是在AndroidManifest.xml文件中進行配置的,而PackageInfo類則封裝了從該配置文件中獲取的所有信息,描述了包內容的整體信息,因此,可以使用PackageInfo對象的versionName屬性獲取應用的版本號。 要怎麼獲取PackageInfo對象呢?可以通過PackageManager對象來獲取。PackageManager是一個檢索當前已安裝在設備上的相關應用程序包的各種信息的類。PackageManager對象中的getPackageInfo方法可以獲取PackageInfo對象,該方法需要傳遞兩個參數:應用包名和條件。通常情況下,應用程序的包名可以通過Activity或Context(Activity繼承自Context)的getPackageName()方法獲取,而添加可以有很多設置,通常設置為0。 最後是PackageManager對象的獲取,Context對象提供了getPackageManager()方法來獲取該對象。 綜上,模板代碼如下:(注意,此處封裝的方法位於某個Activity中,因此直接使用this來代替Context對象) /** * 獲取版本號 * @return 當前應用的版本號 */ public String getVersion() { try { PackageManager manager = this.getPackageManager(); PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0); String version = info.versionName; return this.getString(R.string.version_name) + version; } catch (Exception e) { e.printStackTrace(); return this.getString(R.string.can_not_find_version_name); } }

⑷ android版本更新的webservice怎麼實現

方法/步驟
在eclipse上安裝好android開發環境,android調用webservice使用ksoap,本經驗使用的是ksoap2-android-assembly-2.6.4-jar-with-dependencies.jar
AndroidManifest.xml中需添加相應的許可權,例子:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.camera"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="9" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.camera.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>亮蔽

</manifest>
activity_main.xml文件代碼
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<Button
android:id="@+id/button"
android:layout_width="fill_parent"高鍵辯
android:layout_height="wrap_content"
android:text="點擊啟動相機"/>
<Button
android:id="@+id/savePic"
android:layout_width="fill_parent"
android:layout_height="戚缺wrap_content"
android:text="保存圖片到伺服器"/>
<TextView
android:id="@+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>

<ImageView
android:id="@+id/imageView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#999999" />

</LinearLayout>
MainActivity具體代碼
package com.example.camera;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.kobjects.base64.Base64;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends Activity {
TextView tv = null;
String fileName = "/sdcard/myImage/my.jpg"; //圖片保存sd地址
String namespace = "http://webservice.service.com"; // 命名空間
String url = "http://192.168.200.19:8080/Web/webservices/Portal"; //對應的url
String methodName = "uploadImage"; //webservice方法

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

tv = (TextView)findViewById(R.id.textView);

//啟用相機按鈕
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 1);
}
});

//保存圖片到伺服器按鈕(通過webservice實現)
Button saveButton = (Button) findViewById(R.id.savePic);
saveButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
testUpload();
}
});
}

/**
* 拍照完成後,回掉的方法
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
String sdStatus = Environment.getExternalStorageState();
if (!sdStatus.equals(Environment.MEDIA_MOUNTED)) { // 檢測sd是否可用
Log.v("TestFile",
"SD card is not avaiable/writeable right now.");
return;
}

Bundle bundle = data.getExtras();
Bitmap bitmap = (Bitmap) bundle.get("data");// 獲取相機返回的數據,並轉換為Bitmap圖片格式
FileOutputStream b = null;
File file = new File("/sdcard/myImage/");
file.mkdirs();// 創建文件夾
try {
b = new FileOutputStream(fileName);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, b);// 把數據寫入文件
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
try {
b.flush();
b.close();
} catch (IOException e) {
e.printStackTrace();
}
}
((ImageView) findViewById(R.id.imageView)).setImageBitmap(bitmap);// 將圖片顯示在ImageView里
}
}

/**
* 圖片上傳方法
*
* 1.把圖片信息通過Base64轉換成字元串
* 2.調用connectWebService方法實現上傳
*/
private void testUpload(){
try{
FileInputStream fis = new FileInputStream(fileName);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int count = 0;
while((count = fis.read(buffer)) >= 0){
baos.write(buffer, 0, count);
}
String uploadBuffer = new String(Base64.encode(baos.toByteArray())); //進行Base64編碼
connectWebService(uploadBuffer);
Log.i("connectWebService", "start");
fis.close();
}catch(Exception e){
e.printStackTrace();
}
}

/**
* 通過webservice實現圖片上傳
*
* @param imageBuffer
*/
private void connectWebService(String imageBuffer) {
//以下就是 調用過程了,不明白的話 請看相關webservice文檔
SoapObject soapObject = new SoapObject(namespace, methodName);
soapObject.addProperty("filename", "my.jpg"); //參數1 圖片名
soapObject.addProperty("image", imageBuffer); //參數2 圖片字元串
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = false;
envelope.setOutputSoapObject(soapObject);
HttpTransportSE httpTranstation = new HttpTransportSE(url);
try {
httpTranstation.call(namespace, envelope);
Object result = envelope.getResponse();
Log.i("connectWebService", result.toString());
tv.setText(result.toString());
} catch (Exception e) {
e.printStackTrace();
tv.setText(e.getStackTrace().toString());
}
}

}
服務端webservice方法(cxf)
public String uploadImage(String filename, String image) {
FileOutputStream fos = null;
try{
String toDir = "D:\\work\\image"; //存儲路徑
byte[] buffer = new BASE64Decoder().decodeBuffer(image); //對android傳過來的圖片字元串進行解碼
File destDir = new File(toDir);
if(!destDir.exists()) {
destDir.mkdir();
}
fos = new FileOutputStream(new File(destDir,filename)); //保存圖片
fos.write(buffer);
fos.flush();
fos.close();
return "上傳圖片成功!" + "圖片路徑為:" + toDir;
}catch (Exception e){
e.printStackTrace();
}
return "上傳圖片失敗!";
}

⑸ android版本更新功能怎麼實現

服務上保存當前版本的version code值 檢升銀查更新時獲取伺服器version code和吵棗宴當前安裝版本的version code比較
服務岩笑器值大於當前值則有新版本 否則則無

⑹ android軟體的版本更新是如何實現的

l1.. 可以打開手機中的無線升級軟體 ,看是否有升級提示,若有可以升級,這是手機廠家的自動升級;2..到手機維修店去做升級系統。 3.千萬不要自己刷機升級,由於系統的不兼容性會造成變磚不能使用

⑺ 安卓app去除強制更新彈窗代碼

首先,先了解上面的信息,這些信息我們統稱為「注入"。
意思是:注入代碼到我們需要的軟體中。
看右邊的圖片,這是一款安卓應用注入器,也是今天的主角,現在看的話,是一片空白,因為我們還沒加入我們想要注入的應用程序。
(第一次進入會有應用功能介紹)

⑻ 如何更新android studio中的安卓版本號

1.獲取自己電腦上安裝的Android Studio 的Build Number

只需要增量更新即可,下載更新jar包。
查詢當前的Android Studio的版本號,Help-》About
2.查詢目前Android Studio的最新版本號
(1)訪問網站http://tools.android.com/recent可肆蘆查看最新的Build Number,或

(2)訪問https://dl.google.com/android/studio/patches/updates.xml查看最新的版本號

3.下載增量更新包型卜
獲得裂租帶版本號,下載更新包,
請根據自己的Android Studio的build number下載相應的更新包,格式為AI-$FROM-$TO-patch-win.jar,其中$FROM為當前android studio的build number,$TO為最新的android studio 的build number
4.安裝更新包
將下載的更新包拷貝至Android Studio 的安裝目錄,,將下載的jar拷貝到該目錄下
然後打開命令行提示符,鍵入如下命令

注意:最後一句命令

[java] view plain
java -classpath AI-130.745757-132.809981-patch-win.jar com.int
ellij.updater.Runner install .
最後的點"."代表當前安裝到當前目錄,安裝完畢後,可以重新啟動Android Studio,然後Help-》about查看是不是更新了!

⑼ android 怎麼檢查新版本並且更新

一、准備

1.檢測當前版本的信息AndroidManifest.xml-->manifest-->android:versionName。

2.從伺服器獲取版本號(版本號存在於xml文件中)並與當前檢測到的版本進行匹配,如果不匹配,提示用戶進行升級,如果匹配則進入程序主界面。

3.當提示用戶進行版本升級時,如果用戶點擊了確定,系統將自動從伺服器上下載並進行自動升級,如果點擊取消將進入程序主界面。

二、效果圖


三、必要說明

伺服器端存儲apk文件,同時有version.xml文件便於比對更新。

<?xml version="1.0" encoding="utf-8"?>
<info>衫寬皮
<version>2.0</version>
<url>http://192.168.1.187:8080/mobilesafe.apk</url>
<description>檢測到最新版本,請及時更新!巧手</description>
<url_server>http://192.168.1.99/version.xml</url_server>
</info>
通過一個實體類獲取上述或差信息。

package com.android;
public class UpdataInfo {
private String version;
private String url;
private String description;
private String url_server;

public String getUrl_server() {
return url_server;
}
public void setUrl_server(String url_server) {
this.url_server = url_server;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
apk和版本信息地址都放在伺服器端的version.xml里比較方便,當然如果伺服器端不變動,apk地址可以放在strings.xml里,不過版本號信息是新的,必須放在伺服器端,xml地址放在strings.xml。

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, VersionActivity!</string>
<string name="app_name">Version</string>
<string name="url_server">http://192.168.1.99/version.xml</string>
</resources>
不知道讀者發現沒有,筆者犯了個錯誤,那就是url_server地址必須放在本地,否則怎麼讀取version.xml,所以url_server不必在實體類和version里添加,畢竟是現需要version地址也就是url_server,才能夠讀取version。

三、代碼實現

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/btn_getVersion"
android:text="檢查更新"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
package com.android;
import java.io.InputStream;
import org.xmlpull.v1.XmlPullParser;
import android.util.Xml;
public class UpdataInfoParser {
public static UpdataInfo getUpdataInfo(InputStream is) throws Exception{
XmlPullParser parser = Xml.newPullParser();
parser.setInput(is, "utf-8");
int type = parser.getEventType();
UpdataInfo info = new UpdataInfo();
while(type != XmlPullParser.END_DOCUMENT ){
switch (type) {
case XmlPullParser.START_TAG:
if("version".equals(parser.getName())){
info.setVersion(parser.nextText());
}else if ("url".equals(parser.getName())){
info.setUrl(parser.nextText());
}else if ("description".equals(parser.getName())){
info.setDescription(parser.nextText());
}
break;
}
type = parser.next();
}
return info;
}
}
package com.android;
import java.io.File;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class VersionActivity extends Activity {
private final String TAG = this.getClass().getName();
private final int UPDATA_NONEED = 0;
private final int UPDATA_CLIENT = 1;
private final int GET_UNDATAINFO_ERROR = 2;
private final int SDCARD_NOMOUNTED = 3;
private final int DOWN_ERROR = 4;
private Button getVersion;
private UpdataInfo info;
private String localVersion;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
getVersion = (Button) findViewById(R.id.btn_getVersion);
getVersion.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
localVersion = getVersionName();
CheckVersionTask cv = new CheckVersionTask();
new Thread(cv).start();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
private String getVersionName() throws Exception {
//getPackageName()是你當前類的包名,0代表是獲取版本信息
PackageManager packageManager = getPackageManager();
PackageInfo packInfo = packageManager.getPackageInfo(getPackageName(),
0);
return packInfo.versionName;
}
public class CheckVersionTask implements Runnable {
InputStream is;
public void run() {
try {
String path = getResources().getString(R.string.url_server);
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url
.openConnection();
conn.setConnectTimeout(5000);
conn.setRequestMethod("GET");
int responseCode = conn.getResponseCode();
if (responseCode == 200) {
// 從伺服器獲得一個輸入流
is = conn.getInputStream();
}
info = UpdataInfoParser.getUpdataInfo(is);
if (info.getVersion().equals(localVersion)) {
Log.i(TAG, "版本號相同");
Message msg = new Message();
msg.what = UPDATA_NONEED;
handler.sendMessage(msg);
// LoginMain();
} else {
Log.i(TAG, "版本號不相同 ");
Message msg = new Message();
msg.what = UPDATA_CLIENT;
handler.sendMessage(msg);
}
} catch (Exception e) {
Message msg = new Message();
msg.what = GET_UNDATAINFO_ERROR;
handler.sendMessage(msg);
e.printStackTrace();
}
}
}
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
switch (msg.what) {
case UPDATA_NONEED:
Toast.makeText(getApplicationContext(), "不需要更新",
Toast.LENGTH_SHORT).show();
case UPDATA_CLIENT:
//對話框通知用戶升級程序
showUpdataDialog();
break;
case GET_UNDATAINFO_ERROR:
//伺服器超時
Toast.makeText(getApplicationContext(), "獲取伺服器更新信息失敗", 1).show();
break;
case DOWN_ERROR:
//下載apk失敗
Toast.makeText(getApplicationContext(), "下載新版本失敗", 1).show();
break;
}
}
};
/*
*
* 彈出對話框通知用戶更新程序
*
* 彈出對話框的步驟:
* 1.創建alertDialog的builder.
* 2.要給builder設置屬性, 對話框的內容,樣式,按鈕
* 3.通過builder 創建一個對話框
* 4.對話框show()出來
*/
protected void showUpdataDialog() {
AlertDialog.Builder builer = new Builder(this);
builer.setTitle("版本升級");
builer.setMessage(info.getDescription());
//當點確定按鈕時從伺服器上下載 新的apk 然後安裝 װ
builer.setPositiveButton("確定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Log.i(TAG, "下載apk,更新");
downLoadApk();
}
});
builer.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
//do sth
}
});
AlertDialog dialog = builer.create();
dialog.show();
}
/*
* 從伺服器中下載APK
*/
protected void downLoadApk() {
final ProgressDialog pd; //進度條對話框
pd = new ProgressDialog(this);
pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pd.setMessage("正在下載更新");
pd.show();
new Thread(){
@Override
public void run() {
try {
File file = DownLoadManager.getFileFromServer(info.getUrl(), pd);
sleep(3000);
installApk(file);
pd.dismiss(); //結束掉進度條對話框
} catch (Exception e) {
Message msg = new Message();
msg.what = DOWN_ERROR;
handler.sendMessage(msg);
e.printStackTrace();
}
}}.start();
}

//安裝apk
protected void installApk(File file) {
Intent intent = new Intent();
//執行動作
intent.setAction(Intent.ACTION_VIEW);
//執行的數據類型
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
startActivity(intent);
}
}
package com.android;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import android.app.ProgressDialog;
import android.os.Environment;
public class DownLoadManager {
public static File getFileFromServer(String path, ProgressDialog pd) throws Exception{
//如果相等的話表示當前的sdcard掛載在手機上並且是可用的
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5000);
//獲取到文件的大小
pd.setMax(conn.getContentLength());
InputStream is = conn.getInputStream();
File file = new File(Environment.getExternalStorageDirectory(), "updata.apk");
FileOutputStream fos = new FileOutputStream(file);
BufferedInputStream bis = new BufferedInputStream(is);
byte[] buffer = new byte[1024];
int len ;
int total=0;
while((len =bis.read(buffer))!=-1){
fos.write(buffer, 0, len);
total+= len;
//獲取當前下載量
pd.setProgress(total);
}
fos.close();
bis.close();
is.close();
return file;
}
else{
return null;
}
}
}
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

熱點內容
ftp匿名帳號 發布:2025-02-12 18:04:32 瀏覽:763
銳志哪個配置性價比最高 發布:2025-02-12 17:38:43 瀏覽:918
智能推送演算法 發布:2025-02-12 17:38:41 瀏覽:835
拍照上傳器 發布:2025-02-12 17:34:29 瀏覽:652
androidweb框架 發布:2025-02-12 17:32:45 瀏覽:76
安卓編程賀卡 發布:2025-02-12 17:32:44 瀏覽:838
php獲取資料庫的欄位 發布:2025-02-12 17:29:02 瀏覽:766
伺服器地址消失 發布:2025-02-12 17:23:36 瀏覽:951
後台執行php腳本 發布:2025-02-12 17:21:45 瀏覽:471
spring編程式事務 發布:2025-02-12 17:16:55 瀏覽:398