申请怎样升级淘宝新版本成功 但是还是检测不到新版本啊啊

4264人阅读
android(51)
Android版本检测更新是每个应用升级所不可少的,以前早就做过一些,一直没有时间与大家分享,现在就跟大家来分享一下我做的版本检测更新吧。先上图
点击更新之后的
可能有人会问为啥点击更新提示框不消失啊,可以根据自己的情况而定,有的需要强制更新,也是为了方便用户看到下载的进度。我这里只是为了测试一下效果而已。真正的是点击更新以后会在通知栏里面进行显示的 效果就是这样的
也有的可能需要在桌面上面展示给用户,下面的效果
这些都是是需求而定的。不多说了上代码
package com.liuyongxiang.update.
import java.io.BufferedR
import java.io.F
import java.io.IOE
import java.io.InputS
import java.io.InputStreamR
import java.io.RandomAccessF
import java.net.HttpURLC
import java.net.MalformedURLE
import java.net.URL;
import org.apache.http.HttpR
import org.apache.http.client.HttpC
import org.apache.http.client.methods.HttpG
import org.apache.http.client.methods.HttpP
import org.apache.http.impl.client.DefaultHttpC
import org.apache.http.params.HttpConnectionP
import org.json.JSONE
import org.json.JSONO
import com.lidroid.xutils.HttpU
import com.lidroid.xutils.exception.HttpE
import com.lidroid.xutils.http.ResponseI
import com.lidroid.xutils.http.callback.RequestCallB
import com.liuyongxiang.update.R;
import com.liuyongxiang.update.bean.VersionB
import com.liuyongxiang.update.utils.MyC
import com.liuyongxiang.update.utils.SpT
import com.liuyongxiang.update.view.NumberProgressB
import com.liuyongxiang.update.view.OnProgressBarL
import android.annotation.SuppressL
import android.annotation.TargetA
import android.app.A
import android.app.AlertD
import android.app.N
import android.app.NotificationM
import android.app.PendingI
import android.content.C
import android.content.I
import android.content.SharedP
import android.content.pm.PackageI
import android.content.pm.PackageM
import android.content.pm.PackageManager.NameNotFoundE
import android.graphics.PixelF
import android.graphics.pdf.PdfD
import android.media.AudioM
import android.net.U
import android.os.B
import android.os.B
import android.os.E
import android.os.H
import android.os.M
import android.os.SystemC
import android.support.v4.app.NotificationC
import android.text.TextU
import android.text.method.ScrollingMovementM
import android.view.G
import android.view.LayoutI
import android.view.MotionE
import android.view.V
import android.view.View.OnClickL
import android.view.View.OnTouchL
import android.view.W
import android.view.WindowM
import android.view.WindowManager.LayoutP
import android.widget.B
import android.widget.ImageV
import android.widget.LinearL
import android.widget.RelativeL
import android.widget.RemoteV
import android.widget.TextV
import android.widget.T
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class SplashActivity extends Activity implements OnProgressBarListener {
private static final int LOADMAIN = 1;
private static final int SHOWUPDATEDIALOG = 2;
protected static final int ERROR = 3;
private RelativeLayout rl_
private int versionC
private String versionN
private TextView tv_versionN
private VersionBean parseJ
private long startTimeM
private NumberProgressBar pb_
private Notification.Builder mB
private NotificationManager mNotificationM
public static final int NOTIFICATION_ID = 200;
public static final int MUTE = 0;
public static final int VIBRATE = 1;
public static final int SOUND = 2;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initView();
initData();
showUpdateDialog();
* 耗时的功能封装,只要耗时的处理,都放到此方法
private void timeInitialization() {
if (SpTools.getBoolean(getApplicationContext(), MyConstants.AUTOUPDATE,
checkVerion();
private void initData() {
PackageManager pm = getPackageManager();
PackageInfo packageInfo = pm.getPackageInfo(getPackageName(), 0);
versionCode = packageInfo.versionC
versionName = packageInfo.versionN
tv_versionName.setText(versionName);
} catch (NameNotFoundException e) {
private void checkVerion() {
new Thread(new Runnable() {
public void run() {
BufferedReader bfr = null;
HttpURLConnection conn = null;
int errorCode = -1;
startTimeMillis = System.currentTimeMillis();
URL url = new URL("http://10.0.2.2:8080/guardversion.json");
conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(5000);
conn.setConnectTimeout(5000);
int code = conn.getResponseCode();
if (code == 200) {
InputStream is = conn.getInputStream();
bfr = new BufferedReader(new InputStreamReader(is));
String line = bfr.readLine();
StringBuilder json = new StringBuilder();
while (line != null) {
json.append(line);
line = bfr.readLine();
parseJson = parseJson(json);
errorCode = 404;
} catch (MalformedURLException e) {
errorCode = 4002;
e.printStackTrace();
} catch (IOException e) {
errorCode = 4001;
e.printStackTrace();
} catch (JSONException e) {
errorCode = 4003;
e.printStackTrace();
} finally {
Message msg = Message.obtain();
if (errorCode == -1) {
msg.what = isNewVersion(parseJson);
msg.what = ERROR;
msg.arg1 = errorC
long endTime = System.currentTimeMillis();
if (endTime - startTimeMillis & 3000) {
SystemClock.sleep(3000 - (endTime - startTimeMillis));
handler.sendMessage(msg);
if (bfr != null) {
bfr.close();
if (conn != null) {
conn.disconnect();
} catch (IOException e) {
e.printStackTrace();
}).start();
private Handler handler = new Handler() {
public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case LOADMAIN:
loadMain();
case ERROR:
switch (msg.arg1) {
Toast.makeText(getApplicationContext(), "404资源找不到", 0)
case 4001:
Toast.makeText(getApplicationContext(), "4001没有网络", 0)
case 4003:
Toast.makeText(getApplicationContext(), "4003json格式错误", 0)
loadMain();
case SHOWUPDATEDIALOG:
showUpdateDialog();
private AlertD
private void loadMain() {
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
protected int isNewVersion(VersionBean parseJson) {
int serverCode = 2;
System.out.println("serverCode-----&" + serverCode);
if (serverCode == versionCode) {
return LOADMAIN;
return SHOWUPDATEDIALOG;
* 显示是否更新新版本的对话框
public void showUpdateDialog() {
dialog = new AlertDialog.Builder(this).create();
dialog.setCancelable(false);
dialog.show();
Window window = dialog.getWindow();
window.setContentView(R.layout.prompt_alertdialog);
LinearLayout ll_title = (LinearLayout) window
.findViewById(R.id.ll_title);
ll_title.setVisibility(View.VISIBLE);
TextView tv_title = (TextView) window.findViewById(R.id.tv_title);
pb_download = (NumberProgressBar) window
.findViewById(R.id.pb_splash_download);
pb_download.setVisibility(View.GONE);
pb_download.setOnProgressBarListener(this);
tv_title.setText("版本更新");
TextView tv_content = (TextView) window.findViewById(R.id.tv_content);
tv_content.setMovementMethod(new ScrollingMovementMethod());
tv_content
.setText("是否更新新版本?新版本的具有如下特性:1.是否更新新版本?新版本的具有如下特性 2.是否更新新版本?新版本的具有如下特性 3.是否更新新版本?新版本的具有如下特性 4.是否更新新版本?新版本的具有如下特性 5.是否更新新版本?新版本的具有如下特性 6.是否更新新版本?新版本的具有如下特性 7.是否更新新版本?新版本的具有如下特性 8.是否更新新版本?新版本的具有如下特性");
final TextView tv_sure = (TextView) window.findViewById(R.id.tv_sure);
final TextView tv_cancle = (TextView) window
.findViewById(R.id.tv_cancle);
tv_cancle.setText("取消");
tv_cancle.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
loadMain();
dialog.cancel();
tv_sure.setText("更新");
tv_sure.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
downLoadNewApk();
createFloatView();
tv_cancle.setEnabled(false);
tv_sure.setEnabled(false);
dialog.cancel();
loadMain();
pb_download.setVisibility(View.VISIBLE);
* 新版本的下载安装
protected void downLoadNewApk() {
HttpUtils utils = new HttpUtils();
File file = new File("/mnt/sdcard/测试.apk");
file.delete();
utils.download(
"/d/file/game/qipai//HappyLordZZ_1.0.19_.apk",
"/mnt/sdcard/测试.apk", new RequestCallBack&File&() {
public void onLoading(final long total, final long current,
boolean isUploading) {
pb_download.setVisibility(View.VISIBLE);
int max = (int)
int progress = (int)
pb_download.setMax(max);
pb_download.setProgress(progress);
pb_download2.setMax(max);
pb_download2.setProgress(progress);
showNotifi(max, progress);
super.onLoading(total, current, isUploading);
public void onSuccess(ResponseInfo&File& arg0) {
Toast.makeText(getApplicationContext(), "下载新版本成功", 1)
installApk();
pb_download.setVisibility(View.GONE);
rl_notification.setVisibility(View.GONE);
public void onFailure(HttpException arg0, String arg1) {
Toast.makeText(getApplicationContext(), "下载新版本失败", 1)
pb_download.setVisibility(View.GONE);
private NumberProgressBar pb_download2;
private RelativeLayout rl_
* 安装下载的新版本
protected void installApk() {
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
String type = "application/vnd.android.package-archive";
Uri data = Uri.fromFile(new File("/mnt/sdcard/测试.apk"));
intent.setDataAndType(data, type);
startActivityForResult(intent, 0);
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
loadMain();
super.onActivityResult(requestCode, resultCode, data);
* jsonString
url的json数据
* url信息封装对象
* JSONException
protected VersionBean parseJson(StringBuilder jsonString)
throws JSONException {
VersionBean bean = new VersionBean();
JSONObject jsonO
jsonObj = new JSONObject(jsonString + "");
int versionCode = jsonObj.getInt("version");
String url = jsonObj.getString("url");
String desc = jsonObj.getString("desc");
bean.setDesc(desc);
bean.setUrl(url);
bean.setVersionCode(versionCode);
* 初始化界面
private void initView() {
setContentView(R.layout.activity_main);
rl_root = (RelativeLayout) findViewById(R.id.rl_splash_root);
tv_versionName = (TextView) findViewById(R.id.tv_splash_version_name);
public void onProgressChange(int current, int max) {
pb_download.setProgress(current);
pb_download2.setProgress(current);
private void createFloatView() {
final WindowManager.LayoutParams wmParams = new WindowManager.LayoutParams();
getApplication();
final WindowManager mWindowManager = (WindowManager) getApplication()
.getSystemService(Context.WINDOW_SERVICE);
wmParams.type = LayoutParams.TYPE_PHONE;
wmParams.format = PixelFormat.RGBA_8888;
wmParams.flags = LayoutParams.FLAG_NOT_FOCUSABLE;
wmParams.gravity = Gravity.LEFT | Gravity.TOP;
wmParams.x = 0;
wmParams.y = 0;
wmParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
wmParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
LayoutInflater inflater = LayoutInflater.from(getApplication());
final View mFloatLayout = inflater.inflate(
R.layout.activity_notification, null);
mWindowManager.addView(mFloatLayout, wmParams);
rl_notification = (RelativeLayout) mFloatLayout
.findViewById(R.id.rl_notification);
pb_download2 = (NumberProgressBar) mFloatLayout
.findViewById(R.id.pb_download);
mFloatLayout.measure(View.MeasureSpec.makeMeasureSpec(0,
View.MeasureSpec.UNSPECIFIED), View.MeasureSpec
.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
rl_notification.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
wmParams.x = (int) event.getRawX()
- rl_notification.getMeasuredWidth() / 2;
wmParams.y = (int) event.getRawY()
- rl_notification.getMeasuredHeight() / 2 - 25;
mWindowManager.updateViewLayout(mFloatLayout, wmParams);
return false;
private void showNotification(final int total, final int current) {
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mBuilder = new Notification.Builder(SplashActivity.this);
LayoutInflater inflater = LayoutInflater.from(getApplication());
View view = inflater.inflate(R.layout.activity_notification, null);
mBuilder.setContentTitle("这是测试").setContentText("下载中...")
.setSmallIcon(R.drawable.app_icon);
new Thread(new Runnable() {
@SuppressLint("NewApi")
public void run() {
mBuilder.setProgress(total, current, false);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
if (current / total == 1) {
mNotificationManager.cancel(0);
}).start();
private void showNotifi(final int total, final int current) {
NotificationManager notiM
mBuilder = new Notification.Builder(SplashActivity.this);
notiManage = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
note = new Notification();
note.flags = Notification.FLAG_AUTO_CANCEL;
RemoteViews contentView = new RemoteViews(getPackageName(),
R.layout.activity_notifi);
contentView.setTextViewText(R.id.notificationTitle, "这是测试");
String str_progress =current*100/total+"%";
contentView.setTextViewText(R.id.notificationPercent, str_progress);
contentView.setProgressBar(R.id.notificationProgress, total, current,
note.contentView = contentV
note.tickerText = "正在下载";
note.icon = R.drawable.app_
PendingIntent p = PendingIntent.getActivity(SplashActivity.this, 0,
new Intent(Intent.ACTION_VIEW), 0);
note.contentIntent =
notiManage.notify(NOTIFICATION_ID, note);
if (current / total == 1) {
notiManage.cancelAll();
这只是一些简单的代码,如果想测试一下具体效果
如果有问题请加Android交流群 或留言
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:62673次
积分:1225
积分:1225
排名:千里之外
原创:50篇
评论:103条
Android技术交流群 (已满)
Android交流群
(6)(9)(3)(3)(2)(1)(4)(1)(3)(1)(1)(10)(3)(1)(3)(1)(1)人次在我爱卡申请信用卡
人次申请贷款 255家 银行和金融机构授权合作
后使用快捷导航没有帐号?
查看: 639|回复: 1
掌上生活5.05版本每次买东西都提示升级到最新版本,购买不了,但已是最新版本了啊。
阅读权限80
在线时间1266 小时
金卡Ⅱ级, 经验值 7197, 距离下一级还需 802 经验值
在线时间1266 小时
掌上生活5.05版本每次买东西都提示升级到最新版本,购买不了,但已是最新版本了啊。
阅读权限90
在线时间4883 小时
在线时间4883 小时
我Android也遇到这个问题,卸载APP重新安装即可。
热门信用卡中心
热门信用卡申请
信用卡问答
Powered by Discuz! X3&
我爱卡客服这是最新版本吗?检测不到新的啊,怎么升级呢_华为荣耀6吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:159,140贴子:
这是最新版本吗?检测不到新的啊,怎么升级呢收藏
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或以下是我的步骤》 1.
1.png (9.54 KB, 下载次数: 0)
11:21 上传
2.jpg (163.76 KB, 下载次数: 0)
11:21 上传
3.jpg (80.76 KB, 下载次数: 1)
11:21 上传
4.jpg (73.2 KB, 下载次数: 0)
11:21 上传
检测不到新版本啊。
你发布的最新版本,一定要比用户手机上已经安装的版本高,才能提示更新,不是随便发布个版本,就要去更新。从高版本更新到低版本是没有意义的,那不叫更新,叫“更旧”。同时操作系统也不会允许你将一个比设备上目前已安装的app版本还低的app进行安装。
30分钟内迅速响应,一对一技术支持,每个问题均能获得专业解答----
UID:106506
当前测试手机中安装的应用的版本号是多少啊,打印下api.appVersion是多少
30分钟内迅速响应,一对一技术支持,每个问题均能获得专业解答----
当前测试手机中安装的应用的版本号是多少啊,打印下api.appVersion是多少
5.jpg (49.61 KB, 下载次数: 1)
15:21 上传
6.png (20.71 KB, 下载次数: 0)
15:21 上传
4.jpg (73.2 KB, 下载次数: 0)
15:22 上传
打印出是 0.1.28& && &&&更新的也是。&&但是 还是显示&&没有更新。
领导生气了。
求关注。&&
谁来关注下。&&一直不能更新。领导生气的不行。555555
当前测试手机中安装的应用的版本号是多少啊,打印下api.appVersion是多少
版本更新还是不能正常更新。
UID:106506
你手机中安装的应用的版本是0.1.28,服务器上填写0.1.25,当然不会更新了啊,只有服务器的版本大于手机中的版本才能提示更新
30分钟内迅速响应,一对一技术支持,每个问题均能获得专业解答----
(C) 2014 APICloud

我要回帖

更多关于 怎样升级淘宝新版本 的文章

 

随机推荐