Android版本提示更新下载

之前有篇博文是使用第三方蒲公英提示更新,但是蒲公英更新推荐大家内测使用,实际的开发中我们还得需要自己来编写版本更新代码,我就简单了写了一个简单demo,大致的功能就是如果有新的版本,提示更新下载到sd卡位置  不多说怼代码:


代码中用到了okhttp框架相信大家都会导入就不在这写了.


demo目录(Android studio):                                                            效果图:

                           



json数据:(versionName版本号,url是apk下载的地址,title是更新的内容)

{
    "versionName": "1.02",
    "versionCode": 1,
    "url": "http://100.100.110.1/IXCd8a8c6a3058ab4c74b4e3af99c6c2fb7/data/wisegame/

09bd127e31d541a2/weibo_3424.apk",
    "title": "1、新版本提示
2、换行测试
2、换行测试"
}



1、activity_main布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.wdl.updatedemo.MainActivity">

    <Button
        android:id="@+id/btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="检查新版本" />
</RelativeLayout>

2、创建dialog.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="wrap_content"
    android:background="#ffffff"
    android:orientation="vertical"
    >

    <TextView

        android:layout_margin="10dp"
        android:id="@+id/text_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:text="更新内容"
        android:textSize="18sp" />

    <TextView
        android:layout_marginLeft="10dp"
        android:layou
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值