一:前言

公司的app,上传到百度应用市场,然后说必须要接入百度的自动更新sdk才能上架,于是从百度官网上去下载jar包,下载的时候必须要带上数据统计,如果使用自动的jar包,还需要带上广告联盟,坑爹啊,有木有。我下载下来把其他无关的jar包根so文件删掉了.把百度的demo也进行精简了一下.只留下了自动更新必须要用到的.

二:效果图如下

三:代码如下

AutoUpdateActivity.java  代码删的就剩下整个Activity了,其实调用百度sdk还挺简单的,一句话就能搞定,然后再监听回调函数.

/**
* 百度自动更新
* @author ansen
* @create time 2015-11-07
*/
public class AutoUpdateActivity extends Activity implements View.OnClickListener {
private TextView txt_log;
private ProgressDialog dialog; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.autoupdate_main);
findViewById(R.id.btn_ui).setOnClickListener(this);
findViewById(R.id.btn_silence).setOnClickListener(this);
findViewById(R.id.btn_as).setOnClickListener(this);
findViewById(R.id.btn_noui).setOnClickListener(this);
txt_log = (TextView) findViewById(R.id.txt_log);
dialog = new ProgressDialog(this);
dialog.setIndeterminate(true);
} @Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_ui://UI更新
txt_log.setText("");
dialog.show();
BDAutoUpdateSDK.uiUpdateAction(this, new MyUICheckUpdateCallback());
break;
case R.id.btn_silence:
txt_log.setText("");
BDAutoUpdateSDK.silenceUpdateAction(this);
break;
case R.id.btn_as:
txt_log.setText("");
dialog.show();
BDAutoUpdateSDK.asUpdateAction(this, new MyUICheckUpdateCallback());
break;
case R.id.btn_noui:
txt_log.setText("");
dialog.show();
BDAutoUpdateSDK.cpUpdateCheck(this, new MyCPCheckUpdateCallback());
break;
}
} @Override
protected void onDestroy() {
dialog.dismiss();
super.onDestroy();
} private class MyUICheckUpdateCallback implements UICheckUpdateCallback {
@Override
public void onCheckComplete() {
dialog.dismiss();
}
} private class MyCPCheckUpdateCallback implements CPCheckUpdateCallback {
@Override
public void onCheckUpdateCallback(AppUpdateInfo info, AppUpdateInfoForInstall infoForInstall) {
if(infoForInstall != null && !TextUtils.isEmpty(infoForInstall.getInstallPath())) {
txt_log.setText(txt_log.getText() + "\n install info: " + infoForInstall.getAppSName() + ", \nverion=" + infoForInstall.getAppVersionName() + ", \nchange log=" + infoForInstall.getAppChangeLog());
txt_log.setText(txt_log.getText() + "\n we can install the apk file in: " + infoForInstall.getInstallPath());
BDAutoUpdateSDK.cpUpdateInstall(getApplicationContext(), infoForInstall.getInstallPath());
}else if(info != null) {
BDAutoUpdateSDK.cpUpdateDownload(AutoUpdateActivity.this, info, new UpdateDownloadCallback());
}else {
txt_log.setText(txt_log.getText() + "\n no update.");
}
dialog.dismiss();
} } private class UpdateDownloadCallback implements CPUpdateDownloadCallback {
@Override
public void onDownloadComplete(String apkPath) {
txt_log.setText(txt_log.getText() + "\n onDownloadComplete: " + apkPath);
BDAutoUpdateSDK.cpUpdateInstall(getApplicationContext(), apkPath);
} @Override
public void onStart() {
txt_log.setText(txt_log.getText() + "\n Download onStart");
} @Override
public void onPercent(int percent, long rcvLen, long fileSize) {
txt_log.setText(txt_log.getText() + "\n Download onPercent: " + percent + "%");
} @Override
public void onFail(Throwable error, String content) {
txt_log.setText(txt_log.getText() + "\n Download onFail: " + content);
} @Override
public void onStop() {
txt_log.setText(txt_log.getText() + "\n Download onStop");
}
}
}

autoupdate_main.xml   AutoUpdateActivity加载的布局文件.

<LinearLayout 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"
android:padding="10dip"
android:orientation="vertical"
android:gravity="center"
tools:context="${packageName}.${activityClass}" > <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"> <Button
android:id="@+id/btn_ui"
android:layout_width="match_parent"
android:layout_height="40dip"
android:text="UI更新"/> <Button
android:id="@+id/btn_silence"
android:layout_width="match_parent"
android:layout_height="40dip"
android:text="静默更新"
/> <Button
android:id="@+id/btn_as"
android:layout_width="match_parent"
android:layout_height="40dip"
android:text="百度助手更新"
/> <Button
android:id="@+id/btn_noui"
android:layout_width="match_parent"
android:layout_height="40dip"
android:text="无UI更新"
/>
</LinearLayout> <ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"> <TextView
android:id="@+id/txt_log"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</ScrollView> </LinearLayout>

四.注意事项

1.需要引用另外一个项目,另外一个项目里面必须有两个百度的jar包.BDAutoUpdate_APPX_SDK_20150826.jar跟need_lib.jar

2.需要在AndroidManifest.xml中配置appid,appkey,还有弹窗显示的Activity.

        <!-- 百度自动更新SDK   Appid配置,AppKey配置-->
<meta-data android:name="BDAPPID" android:value="3067515"/>
<meta-data android:name="BDAPPKEY" android:value="f3Os4GAOqxgm79GqbnkT9L8T"/>
<!-- 百度自动更新SDK -->
<activity
android:name="com.baidu.autoupdatesdk.ConfirmDialoigActivity"
android:exported="false"
android:screenOrientation="sensor"
android:theme="@style/bdp_update_dialog_style_fullscreen"/>

3.appid跟appkey是官网申请的  http://app.baidu.com/value/sdkservice?f=9

推荐下自己创建的android QQ群:202928390 欢迎大家的加入.

点击下载源码

Android接入百度自动更新SDK的更多相关文章

  1. [转]Android应用的自动更新

    软件的自动更新一般都与Splash界面绑定在一起, 由于需要维护的软件界面很复杂, 一个Activity中嵌入ViewPager, 并且逻辑比较复杂, 索性重新写一个Activity, 现在的软件都很 ...

  2. android之apk自动更新解析包失败问题

    在apk自动更新(相关问题可以看我的博客http://blog.csdn.net/caicongyang) 从服务器下载完成后,点击notification提示安装时,每次都报解析包失败错误!首先我想 ...

  3. Android App版本自动更新

    App在开发过程中,随着业务场景的不断增多,功能的不断完善,早期下载App的用户便无法体验最新的功能,为了能让用户更及时的体验App最新版本,在App开发过程加入App自动更新功能便显得尤为重要.更新 ...

  4. 【Android 应用开发】Android应用的自动更新模块

    . 作者 :万境绝尘  转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/18964835 . 软件的自动更新一般都与Splash界 ...

  5. 安卓程序代写 网上程序代写[原]Android应用的自动更新模块

    软件的自动更新一般都与Splash界面绑定在一起, 由于需要维护的软件界面很复杂, 一个Activity中嵌入ViewPager, 并且逻辑比较复杂, 索性重新写一个Activity, 现在的软件都很 ...

  6. Android应用的自动更新模块

    软件的自动更新一般都与Splash界面绑定在一起, 由于需要维护的软件界面很复杂, 一个Activity中嵌入ViewPager, 并且逻辑比较复杂, 索性重新写一个Activity, 现在的软件都很 ...

  7. 转载:Android应用的自动更新模块

    软件的自动更新一般都与Splash界面绑定在一起, 由于需要维护的软件界面很复杂, 一个Activity中嵌入ViewPager, 并且逻辑比较复杂, 索性重新写一个Activity, 现在的软件都很 ...

  8. android 数据绑定(3)自动更新UI

    1.官方文档 https://developer.android.com/topic/libraries/data-binding/observability 2.observable 属性 适合对象 ...

  9. Android(2)—Mono For Android App版本自动更新

    0.前言 公司Android查询的项目已经开始,整体采用Java后台+App前台来实现,由于项目小,App这块就我一个人开发,首先需要研究的是:Android版本的更新升级问题:本人经过近一周的学习整 ...

随机推荐

  1. 使用nose 进行Python项目的自动化测试

    一.为什么使用nose? 编写测试更容易.nose可以自动识别继承于unittest.TestCase的测试单元,并执行测试,而且,nose也可以测试非继承于unittest.TestCase的测试单 ...

  2. JS typeof与instanceof的区别

    typeof 与 instanceof 通常是用来判断一个变量的类型,二者有如下区别: typeof: 判断一个变量的类型,返回值是字符串形式,返回结果有如下几种: number,boolean,st ...

  3. 不用css3的响应式img(按比例缩小图片)

    有时候自己为了控制图片的响应式,按比例缩小放大图片,如果解决这个问题,用js吧,很麻烦.也会损失很大的加载运行速度等:所以我们还是用css来解决这个问题,用css来强制按比例压缩图片的高度或宽度,看代 ...

  4. Xamarin的不归路-生成安卓错误2

    错误提示: 解决方案:升级Andr​​oid sdk到Andr​​oid6.0即API23重新编译即可. Andr​​oid版本较低的手机如何使用? 你只需要编译和目标设定为6.0,根据需要设置最低A ...

  5. 网站中使用中文个性字库字体--@font-face解决方案探索 l(转)

    最近的项目有用到特别中文字体,最终效果如下图: 红线标记处均为字体,可选中,交互起来,比图片方便太多了. 解决思路就是将体积巨大的中文字库,取子集,只包涵要使用的那部分文字,因此体积就很小了(包含10 ...

  6. Oracle中的CHR()函数与ASCII()函数

    工作中经常会处理一些因特殊字符而导致的错误,如上周我就遇到了因为换行符和回车符导致的数据上报的错误,这种错误比较难以发现,通常是由于用户的输入习惯导致的,有可能数据极少,就那么几行错误从而导致整个数据 ...

  7. myeclipse导入项目出现jquery错误(有红叉)

    今天导入了一个项目,但是进去之后jquery出现了红叉,如图(事实上在我没调好之前两个jquery文件都有叉号) 怎么调呢?右键jquery文件,选择MyEclipse->Exclude Fro ...

  8. HTML基础篇之内嵌框架和表单

    内嵌框架: <iframe src="http://www.baidu.com" name="d"></iframe> 网页会显示一个这 ...

  9. VS快捷键总结(包括ReSharper)

    Shift+Alt+Enter 全屏显示代码Ctrl+E 最近文件列表Ctrl+B 转到定义Ctrl+Alt+B 转到继承类或接口处Ctrl+U 转到基类Ctrl+D 复制当前行或选定的块(Dupli ...

  10. 移动端手势库hammerJS 2.0.4官方文档翻译

    hammerJS是一个优秀的.轻量级的触屏设备手势库,现在已经更新到2.04版本,跟1.0版本有点天壤地别了,毕竟改写了事件名并新增了许多方法,允许同时监听多个手势.自定义识别器,也可以识别滑动方向. ...