APK Expansion Files / Obb 接入介绍
APK Expansion Files / Obb 接入介绍
APK Expansion Files 是谷歌官方提供的APK分包下载策略, 依赖工程已经包含在SDK中.
官方资料
- 文档
使用方法
1. 导入依赖工程
依赖工程放在SDK文件夹中/SDK/extras/google/
文件夹下, 需要依赖market_apk_expansion
与market_licensing
.
说明1:
market_apk_expansion
对market_licensing
有依赖说明2: 如果出现
Android App crashes on Lollipop - Service Intent must be explicit: [duplicate]
类似的报错, 请参照链接修改工程代码licensing工程BUG
2. 打包OBB文件
- 官方文档-使用JOBB打包OBB文件
3. 客户端接入
OBB是通过谷歌后台public key
与包名进行资源匹配, 请确保这两项正确.
继承service, receiver
继承
BroadcastReceiver
用于在游戏运行的时候检查是否需要下载资源文件, 重写`onReceive(Context, Intent)`方法, 示例@Overridepublic void onReceive(Context context, Intent intent) {try {DownloaderClientMarshaller.startDownloadServiceIfRequired(context,intent, SampleDownloaderService.class);} catch (PackageManager.NameNotFoundException e) {e.printStackTrace();}}
继承
DownloaderService
新建一个class, 继承`DownloaderService`, 重写了里面的三个方法, * `getPublicKey()`, 需要在return中返回游戏的`public key`. * `getSALT()`, 需要在return中返回SALT需要返回一个随机字节数组, 格式如下public static final byte[] SALT = new byte[] { 1, 42, -12, -1, 54, 98, -100, -12, 43, 2, -8, -4, 9, 5, -106, -107, -33, 45, -1, 84}; * `getAlarmReceiverClassName()`返回之前继承`BroadcastReceiver`的className, 示例@Overridepublic String getAlarmReceiverClassName() {return SampleAlarmReceiver.class.getName();}
AndroidManifest.xml
相关配置声明权限:
<!-- Required to access Google Play Licensing --><uses-permission android:name="com.android.vending.CHECK_LICENSE" /><!-- Required to download files from Google Play --><uses-permission android:name="android.permission.INTERNET" /><!-- Required to keep CPU alive while downloading files(NOT to keep screen awake) --><uses-permission android:name="android.permission.WAKE_LOCK" /><!-- Required to poll the state of the network connectionand respond to changes --><uses-permissionandroid:name="android.permission.ACCESS_NETWORK_STATE" /><!-- Required to check whether Wi-Fi is enabled --><uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/><!-- Required to read and write the expansion files on shared storage --><uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" />声明service, receiver:<service android:name=".SampleDownloaderService" /><receiver android:name=".SampleAlarmReceiver" />
下载Activity的配置
onCreate
中添加初始化代码示例
@Override
protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);try{Intent notifierIntent = new Intent(this, MainActivity.class);notifierIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |Intent.FLAG_ACTIVITY_CLEAR_TOP);PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,notifierIntent, PendingIntent.FLAG_UPDATE_CURRENT);// 如果需要, 开始下载serviceint startResult =DownloaderClientMarshaller.startDownloadServiceIfRequired(this,pendingIntent, SampleDownloaderService.class);if (startResult != DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED) {// 开始下载mDownloaderClientStub = DownloaderClientMarshaller.CreateStub(this,SampleDownloaderService.class);return;}}catch(Throwable e) {e.printStackTrace();}}* 接入接口Activity中implements`IDownloaderClient`.* `onServiceConnected()`当service连接的时候会调用此方法, 请添加如下逻辑, 获得service对象mRemoteService = DownloaderServiceMarshaller.CreateProxy(m);mRemoteService.onClientUpdated(mDownloaderClientStub.getMessenger());* `onDownloadStateChanged()`下载状态发生变化的时候, 会调用此方法* `onDownloadProgress()`下载进度进行中会不断调用此方法, 用于更新下载的状态* service其他API* `requestPauseDownload()`暂停下载* `requestContinueDownload()`继续下载* `setDownloadFlags()`下载标识设置. 目前只提供一个标识, `IDownloaderService.FLAGS_DOWNLOAD_OVER_CELLULAR`, 如果设置, 玩家可以通过移动网络下载, 否则只能在WIFI状态进行下载
APK Expansion Files / Obb 接入介绍相关推荐
- bluestack模拟器测试APK,使用obb文件资源解压
最近公司需要出台湾版本的APK,谷歌包的要求是APK包大小不能超过50M,所以我们将资源打包成obb格式来进行测试.打包后手头一个APK文件一个OBB格式的资源文件包. 稍稍研究了一下obb包在blu ...
- Common Files文件夹介绍
我们经常在Program Files文件夹下看到Common Files这个文件,但是大多数人不知道它是干什么用的?这里我简单的介绍一下: Common Files是应用程序运行库文件,这个文件夹是操 ...
- Android 使用jarsigner给apk签名的方法详细介绍
工作中APP功能完成以后往往需要往应用商店提交一些内容,如商店中存在本公司别的人员提交的APP,往往需要进行认领,应用商店会让开发者下载空的APK,然后使用自己APP的签名文件进行签名,认证,这里简单 ...
- 西米支付:支付宝/微信支付/银联支付通道的接入介绍
本文以电脑网站支付为例,着重对第三方支付通道的接入进行了分析,包括支付宝支付接入.微信支付接入及银联支付接入. 1.支付宝支付接入 支付宝支付能力主要有当面付.刷脸付.App支付.手机网站支付.电脑网 ...
- android支付宝(Alipay)接入介绍
支付宝的官网地址:https://docs.open.alipay.com/204/105296/ 1.将alipaySdk-xxxxxxxx.jar包放入商户应用工程的libs目录下,如下图. 或者 ...
- 广告、广告联盟、异业联盟及广告接入介绍
https://blog.csdn.net/imxiangzi/article/details/51511188 https://baike.baidu.com/item/Adwords/988013 ...
- unity 和安卓互相交互
https://blog.csdn.net/u010407393/article/details/79423769 Unity和安卓交互 一:设置环境 1.安装Android Build Suppor ...
- java解压obb,使用 OBB 文件(Android)
OBB 和 Wwise IO 的概述 对于 Android 平台,当检查 Unity 选项 Player Settings > Publishing Settings > Split Ap ...
- Cocos2dx 使用obb扩展包
# APK Expansion Files For Cocos2dx ### 预先要了解的 <hr/> * APK扩展文件:https://developer.android.com/go ...
最新文章
- ios中的自动释放池
- vs mysql搭建_VS+mysql+EF搭建
- c语言指数pow,C语言中的指数函数pow()问题
- 面试指南|GO高性能编程精华PDF
- vue上传文件php,php文件上传 – 前端开发,JQUERY特效,全栈开发,vue开发
- css 动态生成圆形区域内扇形个数_CSS实用技巧总结
- php面试题9(看的时候就应该随手截图做笔记的)
- TYUT-A专题题解(二)
- Windows Server 2003 安全指南
- 2-15 复合类型概述
- python音频 降噪_一种基于深度神经网络的音频降噪方法技术
- 网页截图插件FireShot
- 按国家归类的海淘网站大全
- 台式计算机耗电,台式电脑和笔记本耗电量对比,分别是多少?
- Css+Jquery实现点击图片放大缩小预览 图片预览 查看大图
- delphi中Bmp转Jpeg JPG转BMP
- model java_编程中的 Model 到底是什么?
- python筛选时间范围_使用日期范围筛选模型
- 今天你《ZAO》了吗?
- idea 实时更新网页内容(修改代码同时刷新网页即可同步内同)