前言

  Google Play应用商店在上传限制100MB大小,超过该大小的应用必须将超过部分以扩展文件的形式进行上传处理。 总共可上传2个扩展文件,每个最大文件可为2GB,同时obb文件格式可自选。

官网地址:http://developer.android.com/google/play/expansion-files.html

准备

  1、在sdk Manager中下载对应的支持库,play_licensing及play_apk_expansion如下:

    

  2、生成需要的obb文件,并在上传apk包的同时选择上传扩展文件。

    obb文件生成可参考jobb工具生成(官网推荐),http://developer.android.com/tools/help/jobb.html

    也可以直接用参考stackoverflow上Sanket Kachhela的回答(个人推荐):http://stackoverflow.com/questions/14495483/read-content-from-apk-expansion-file-from-obb-file#answer-18953778,直接利用zip压缩工具选择存储模式。

  3、如果上述采用zip压缩的话,这里就还需要unzip准备,利用zipHelper直接解压下载包并正常使用。

    参考stackoverflow上Bhavesh Hirpara的回答:http://stackoverflow.com/questions/14495483/read-content-from-apk-expansion-file-from-obb-file#answer-15150977

  

链接库配置

  1、在eclipse打开需要的库工程,如下:

    

  2、如果downloader_library出现错误 AESObfuscator cannot be resolved 则说明Eclipse没有选择自动编辑,勾选下project->build automatically即可。

  3、添加游戏项目,并添加对应的依赖项目如下图:

    

项目配置

  1、添加对应的权限。

<manifest ...>
<!-- 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 connection
and respond to changes -->
<uses-permission
android: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-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
...
</manifest>

  2、从~sdk\play_apk_expansion\downloader_sample项目复制src\com\example\expansion\downloader下的sample文件到游戏目录下,并对应修改包名的引用等。

    a、将onCreate下的判断obb文件存在的注释处理添加如下:

                // otherwise, download not needed so we fall through to
// starting the movie
validateXAPKZipFiles();

    b、修改  validateXAPKZipFiles 方法,去除验证,直接添加解压方法到对应的游戏下载目录。

    // 解压到游戏下载目录
private void upzipApkExFile(){
try { ZipResourceFile expansionFile = APKExpansionSupport
.getAPKExpansionZipFile(this, VERSION_CODE, 0); ZipEntryRO[] zip = expansionFile.getAllEntries();
Log.i("upzipApkExFile", "mZipFileName : " + zip[0].mZipFileName);
String path = getApplicationContext().getFilesDir().getAbsolutePath();
File file = new File(path + "");
ZipHelper.unzip(zip[0].mZipFileName, file); if (file.exists()) {
Log.e("", "unzipped : " + file.getAbsolutePath());
} } catch (Exception e) {
e.printStackTrace();
} }
/**
* Go through each of the Expansion APK files and open each as a zip file.
* Calculate the CRC for each file and return false if any fail to match.
*
* @return true if XAPKZipFile is successful
*/
void validateXAPKZipFiles() {
upzipApkExFile();
Intent myIntent = new Intent(this, AppActivity.class); //跳转到游戏Activity
startActivity(myIntent);
this.finish();
}

    c、修改SampleDownloaderService文件下的BASE64_PUBLIC_KEY。将其改成对应的Google Play上申请的应用的Key。

 3、添加对应下载接受服务监听。

<application ...>
<service android:name="com.test123.expansion.downloader.SampleDownloaderService" />
<receiver android:name="com.test123.expansion.downloader.SampleAlarmReceiver" />
...
</application>

  4、主游戏AppActivity处理。在启动的Activity中进行判断,如果已经下载并解压了文件则进入游戏,否则跳转到下载的Activity。

    protected void onCreate(final Bundle savedInstanceState){
super.onCreate(savedInstanceState);
String path = getApplicationContext().getFilesDir().getAbsolutePath();
File boolfile = new File(path + "/downloaded");
if(!boolfile.exists())
{
Intent myIntent = new Intent(this, SampleDownloaderActivity.class);
startActivity(myIntent);
this.finish();
return;
} Log.i("upzipApkExFile", "already unziped!!");
  }

  

Cocos2dx处理

  为了让下载的扩展文件直接应用到游戏中,我们要稍微修改下cocos2dx引擎的读取文件处理。

首先,找到引擎目录下cocos2d\cocos\platform\CCFileUtils.cpp文件。

其次,对方法进行如下修改,使其先在getWritablePath目录下需找文件。

std::string FileUtils::fullPathForFilename(const std::string &filename) const
{
if (filename.empty())
{
return "";
} if (isAbsolutePath(filename))
{
return filename;
} // Already Cached ?
auto cacheIter = _fullPathCache.find(filename);
if(cacheIter != _fullPathCache.end())
{
return cacheIter->second;
} // Get the new file name.
const std::string newFilename( getNewFilename(filename) ); std::string fullpathWritablePath = getWritablePath() + newFilename;
if (isFileExistInternal(fullpathWritablePath))
{
if (fullpathWritablePath.length() > )
{
// Using the filename passed in as key.
//_fullPathCache.insert(std::make_pair(filename, fullpathWritablePath));
_fullPathCache[filename] = fullpathWritablePath;
return fullpathWritablePath;
}
} std::string fullpath;
for (const auto& searchIt : _searchPathArray)
{
for (const auto& resolutionIt : _searchResolutionsOrderArray)
{
fullpath = this->getPathForFilename(newFilename, resolutionIt, searchIt); if (fullpath.length() > )
{
// Using the filename passed in as key.
_fullPathCache.insert(std::make_pair(filename, fullpath));
return fullpath;
} }
} if(isPopupNotify()){
CCLOG("cocos2d: fullPathForFilename: No file found at %s. Possible missing file.", filename.c_str());
} // The file wasn't found, return empty string.
return "";
}

而这里getWritablePath获取的目录正是我们之前解压obb文件的目录getApplicationContext().getFilesDir().getAbsolutePath()。

因此,到这里就可以在游戏中跟使用在assert中文件一样使用obb解压出来的文件了。

GooglePlay - 文件上传限制的扩展的更多相关文章

  1. PHP图片文件上传类型限制扩展名限制大小限制与自动检测目录创建。

    程序测试网址:http://blog.z88j.com/fileuploadexample/index.html 代码分为两部分: 一部分form表单: <!doctype html> & ...

  2. laravel 文件上传

    laravel 文件上传 先开扩展 表单中能够选择图片 数据处理C层, 接图片并保存 保存图片: 设置目录 store()的第一个参数说明: 存放图片的子目录. 如何获取文件的类型 大小: $uplo ...

  3. php文件上传与下载(附封装好的函数文件)

    单文件上传前端页面 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  4. Android OkHttp文件上传与下载的进度监听扩展

    http://www.loongwind.com/archives/290.html 上一篇文章介绍了用Retrofit实现文件的上传与下载,但是我们发现没办法监听上传下载的进度,毕竟我们在做开发的时 ...

  5. PHP 文件上传之如何识别文件伪装?——PHP的fileinfo扩展可!

    问题:文件上传时候需要验证上传的文件是否合法,文件伪装如何识别? 一个简单测试:把txt文件后缀直接改成jpg;上传 <!DOCTYPE html> <html> <ti ...

  6. 一款基于uploadify扩展的多文件上传插件,完全适用于Html5

    http://www.uploadify.com/documentation/  官网里面有两个插件,一个是要使用flash插件才能文件上传的插件,另外一个是不需要使用要flash插件的文件上传插件完 ...

  7. jquery.uploadify文件上传组件

    1.jquery.uploadify简介 在ASP.NET中上传的控件有很多,比如.NET自带的FileUpload,以及SWFUpload,Uploadify等等,尤其后面两个控件的用户体验比较好, ...

  8. 11、Struts2 的文件上传和下载

    文件上传 表单准备 要想使用 HTML 表单上传一个或多个文件 须把 HTML 表单的 enctype 属性设置为 multipart/form-data 须把 HTML 表单的method 属性设置 ...

  9. Web开发安全之文件上传安全

    很长一段时间像我这种菜鸡搞一个网站第一时间反应就是找上传,找上传.借此机会把文件上传的安全问题总结一下. 首先看一下DVWA给出的Impossible级别的完整代码: <?php if( iss ...

随机推荐

  1. 命令行利用KVM创建虚拟机

    一,实验环境 OS:CENTOS6.5 X86_64 二,KVM宿主环境配置 1.cat /proc/cpuinfo | egrep 'vmx|svm'  //查看是否支持虚拟技术 2.安装KVM相关 ...

  2. 201521123009 《Java程序设计》第7周学习总结

    1. 本周学习总结 2. 书面作业 Q1:ArrayList代码分析 1.1 解释ArrayList的contains源代码 //contains()方法 public boolean contain ...

  3. 201521123073《Java程序设计》第3周学习总结

    1. 本周学习总结 2. 书面作业 1.代码阅读 public class Test1 { private int i = 1;//这行不能修改 private static int j = 2; p ...

  4. 201521123006 《java程序设计》 第11周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 本次PTA作业题集多线程 1.互斥访问与同步访问 完成题集4-4(互斥访问)与4-5(同步访问) ...

  5. (java web后端方向)如何让你的简历为你争取到更多的面试机会,内容来自java web轻量级开发面试教程

    我们在做培训时,会发现一个不合理的情况,一些程序员能力不错,在公司里也是技术牛人,但发出去的简历往往会石沉大海,没有回复.对于刚毕业的大学生或工作年限在2年之内的程序员,这个情况会更严重. 这种情况下 ...

  6. Python接口测试自动化说明及代码实例:含get、post、put、delete等方法

    一.接口说明文档 环境准备: 安装火狐 安装插件: httprequester https://addons.mozilla.org/en-US/firefox/addon/httprequester ...

  7. Oracle 修改序列的初始值

    Oracle 序列(Sequence)主要用于生成主键.但是,有时需要修改序列初始值(START WITH)时,好多人凭感觉认为:Alter Sequence SequenceName Start W ...

  8. MyEclipse用Java语言连接Oracle数据库

    在MyEclipse下Java连接Oracle数据库 第一步:新建Java项目. 填写项目名,其它设置默认,点击完成即可. 新建java类,填写包名和类名,勾选public static void m ...

  9. JVM菜鸟进阶高手之路十(基础知识开场白)

    转载请注明原创出处,谢谢! 最近没有什么实战,准备把JVM知识梳理一遍,先以开发人员的交流来谈谈jvm这块的知识以及重要性,依稀记得2.3年前用solr的时候老是经常oom,提到oom大家应该都不陌生 ...

  10. SQLServer 自动循环归档分区数据脚本

    标签:SQL SERVER/MSSQL SERVER/数据库/DBA/表分区 概述 在很多业务场景下我们需要对一些记录量比较大的表进行分区,同时为了保证性能需要将一些旧的数据进行归档.在分区表很多的情 ...