当前位置:首页 » 安卓系统 » 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"/>

热点内容
pow在c语言中什么 发布:2025-02-12 21:07:24 浏览:320
php查询mysql连接 发布:2025-02-12 21:05:45 浏览:632
linuxc当前时间 发布:2025-02-12 21:03:32 浏览:28
云锁神服务器 发布:2025-02-12 21:03:29 浏览:487
c语言int和float 发布:2025-02-12 21:03:24 浏览:20
我的世界有什么好玩的大服务器 发布:2025-02-12 21:01:59 浏览:98
方舟手游如何解锁自己的服务器 发布:2025-02-12 20:54:09 浏览:657
猫影视源码 发布:2025-02-12 20:42:05 浏览:923
局域网如何访问其他电脑 发布:2025-02-12 20:39:06 浏览:378
新平板电脑的数字密码如何知道 发布:2025-02-12 20:31:19 浏览:345