use*_*154 39 android apk-expansion-files
我已经开发了应用程序并成功运行.
我在应用程序中使用了应用程序许可功能.现在我要在谷歌播放上传一个应用程序.
请让我知道步骤,如何使用应用程序许可以及如何创建APK扩展文件?
Moh*_*ikh 93
扩展文件消除了上传超过50MB apk大小的限制.上传apk时必须附加的文件.每个应用程序可以为每个APK提供高达4GB(2GB - 主,2GB - 补丁)的附加数据.
创建扩展文件时必须遵循命名约定
[main|patch].<expansion-version>.<package-name>.obb
注意:
main- 没有这个文件的那些文件你的应用程序将无法运行patch- 那些是附加的文件,没有这个你的应用程序可以运行expansion-version- 您提供给apk的版本,以便不同版本的扩展文件不会发生冲突package-name- 这是您独特的包裹名称.obb 我们没有附加,谷歌会在上传时隐含附加
假设您拥有当前目录中的所有内容,那么只需选择所有内容并将其命名为zip main.2.com.xyz.abc.zip并在上传时附加它

这全部上传部分,现在下载部分
首先,您需要通过单击SDK-Manager 下载Google额外软件包

现在从现有源创建新项目并从路径sdk-path/extras/google导入market_licensing,play_apk_expansion
请记住:免费应用程序不需要许可,但需要扩展概念,您只需要通过向您的项目提供market_licensing的参考,它将隐式管理.
play_apk_expansion包含三个项目downloader_library,zip_file,downloader_sample.
downloader_library本身具有Market_licensing的引用.
现在你只需要集中精力downloader_sample首先将包名称(用于测试)更改为packagename(packagename与上传的apk相同)
很重要
在SampleDownloaderActivity导航到...
private static final XAPKFile[] xAPKS = {
new XAPKFile(
true, // true signifies a main file
2, // the version of the APK that the file was uploaded
// against
xxxxxxxxxxxL // the length of the zipfile in bytes right click on you expansion file and get the size in bytes, size must be same as zip size
),
};
Run Code Online (Sandbox Code Playgroud)
现在,此活动将下载扩展文件,并将其存储在sdcard/Android/obb/[main|patch].<expansion-version>.<package-name>.obbignore obb中,只需将此文件解压缩到任意位置(sdcard/Android/data建议因为它会在您的应用程序卸载时删除).
有最新的设备可以直接从Play商店下载扩展文件并将其存储,sdcard/Android/obb/因此您必须非常小心地检查所有案例
记忆案例:
如果你采取任何新设备或前.micromax funbook,然后它有三个记忆
希望这能帮助您并满足您的要求.
还有一件事使用下面ZipHelper的内容解压缩内容.
ZipHelper.java
public class ZipHelper
{
boolean zipError=false;
public boolean isZipError() {
return zipError;
}
public void setZipError(boolean zipError) {
this.zipError = zipError;
}
public void unzip(String archive, File outputDir)
{
try {
Log.d("control","ZipHelper.unzip() - File: " + archive);
ZipFile zipfile = new ZipFile(archive);
for (Enumeration e = zipfile.entries(); e.hasMoreElements(); ) {
ZipEntry entry = (ZipEntry) e.nextElement();
unzipEntry(zipfile, entry, outputDir);
}
}
catch (Exception e) {
Log.d("control","ZipHelper.unzip() - Error extracting file " + archive+": "+ e);
setZipError(true);
}
}
private void unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDir) throws IOException
{
if (entry.isDirectory()) {
createDirectory(new File(outputDir, entry.getName()));
return;
}
File outputFile = new File(outputDir, entry.getName());
if (!outputFile.getParentFile().exists()){
createDirectory(outputFile.getParentFile());
}
Log.d("control","ZipHelper.unzipEntry() - Extracting: " + entry);
BufferedInputStream inputStream = new BufferedInputStream(zipfile.getInputStream(entry));
BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));
try {
IOUtils.copy(inputStream, outputStream);
}
catch (Exception e) {
Log.d("control","ZipHelper.unzipEntry() - Error: " + e);
setZipError(true);
}
finally {
outputStream.close();
inputStream.close();
}
}
private void createDirectory(File dir)
{
Log.d("control","ZipHelper.createDir() - Creating directory: "+dir.getName());
if (!dir.exists()){
if(!dir.mkdirs()) throw new RuntimeException("Can't create directory "+dir);
}
else Log.d("control","ZipHelper.createDir() - Exists directory: "+dir.getName());
}
}
Run Code Online (Sandbox Code Playgroud)
RAY*_*RAY 13
首先,假设您使用helloworld.jpg从/assets/helloworld.jpg迁移到您的扩展
`[main|patch].{expansion-version}.{package-name}.obb`Run Code Online (Sandbox Code Playgroud)
例如,如果您的pkg名称是"com.earth.helloworld"且版本= 1,
那么您的输出扩展名文件名应为:
patch.1.com.earth.helloworld.obb
这是一个zip文件,其中包含zip文件
后的helloworld.jpg
已创建,请注意文件大小:
2.然后在SD卡上创建此文件夹(如果不存在):
/ mnt/sdcard/Android/obb/{your package name}/
ie
/mnt/sdcard/Android/obb/com.earth.helloworld/
然后将您的obb文件上传到您的SD卡,例如/mnt/sdcard/Android/obb/com.earth.helloworld/patch.1.com.earth.helloworld.obb
然后创建一个获取扩展文件的方法
public ZipResourceFile getExpansionFile() {
String fileName = Helpers.getExpansionAPKFileName(this, false, 1);
int filesize = 445461159;
if (Helpers.doesFileExist(this, fileName, , false)) {
try {
return APKExpansionSupport.getAPKExpansionZipFile(
getBaseContext(), 1, 1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null; }
Run Code Online (Sandbox Code Playgroud)最后使用这两行来获取helloworld.jpg
InputStream istr = getExpansionFile().getInputStream(strName);
Bitmap bitmap = BitmapFactory.decodeStream(istr);
Run Code Online (Sandbox Code Playgroud)Jor*_*rdy 11
由于有一些事情在apk扩展工作方式发生了变化,并且如果你使用Android Studio来使图书馆工作,那么这篇文章中最终会有人提供一些helfull信息.
注1
您不能再使用草稿了,因为获取扩展文件的链接尚未激活.您必须先使用扩展文件将版本上传到Alpha或Beta.(只能从您上传的第二个apk中添加扩展文件)因此,请确保在单击APK下的开发人员发布部分中的详细信息时看到列出的apk扩展文件.
笔记2
如果您正在使用android studio并希望使用下载程序库,请不要只将程序包名称和java文件复制到您自己的应用程序src目录中.在eclipse中导入下载程序库,然后选择export => gradle build files.之后,您可以将该库作为模块导入android studio.
注3
不确定这一点,但我也认为有必要至少通过Play商店下载一次应用程序并使用您的测试设备上的帐户访问它.因此,如果您正在使用alpha创建一个谷歌+测试组并添加自己或其他测试设备.
BTW
使用这些库,实现apk扩展下载非常容易,只需确保:
您的活动(在未自动完成下载时要实现扩展包下载的活动)实现IDownloaderClient.
您设置服务和接收器并将其设置在清单中.
服务类中的BASE64_PUBLIC_KEY是正确的.在您的应用程序=>此应用程序的许可证代码下的开发者控制台中上传第一个apk =>查看服务和API.
此代码用于查看是否可以在设备上找到扩展文件:
boolean expansionFilesDelivered() {
for (XAPKFile xf : xAPKS) {
String fileName = Helpers.getExpansionAPKFileName(this, xf.mIsMain, xf.mFileVersion);
Log.i(TAG, "Expansion filename " +fileName);
if (!Helpers.doesFileExist(this, fileName, xf.mFileSize, false))
return false;
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
它使用类XAPKS代表一个扩展文件,无论是主文件还是补丁文件,具有特定的文件大小(字节)并与apk版本(最初添加的版本)相关联.
private static class XAPKFile {
public final boolean mIsMain; // true
public final int mFileVersion; //example 4
public final long mFileSize; //example 126515695L
// example => main expansion that was first introduced in apk version 4 and is 126515695 bytes in size
XAPKFile(boolean isMain, int fileVersion, long fileSize) {
mIsMain = isMain;
mFileVersion = fileVersion;
mFileSize = fileSize;
}
}
Run Code Online (Sandbox Code Playgroud)
使用谷歌提供的zip工具(com.android.vending.zipfile)直接从扩展文件中读取电影文件和其他内容也非常容易.
首先使用库中提供的方法获取扩展文件,参数是整数,代表您的主要扩展apk版本(您需要首先添加扩展包的apk版本)和补丁apk版本.
ZipResourceFile expansionFile = APKExpansionSupport.getAPKExpansionZipFile(context, APKX_MAIN_APK, APKX_PATCH_APK);
Run Code Online (Sandbox Code Playgroud)
视频
要直接从此zipresourcefile播放视频:
AssetFileDescriptor a = expansionFile.getAssetFileDescriptor(pathToFileInsideZip);
Run Code Online (Sandbox Code Playgroud)
现在从这个assetFileDescriptor你可以获得一个FileDescriptor并在你的媒体播放器中使用它,正确的语法让你的媒体播放器播放视频也需要第二个和第三个参数..无论你是从AssetFileDescriptor获得的起始时间和长度.
player.setDataSource(a.getFileDescriptor(), a.getStartOffset(), a.getLength());
Run Code Online (Sandbox Code Playgroud)
其他
对于所有其他内容(如图像),您只需获取zipresourcefile的输入流:
expansionFile.getInputStream(pathToFileInsideZip);`
Run Code Online (Sandbox Code Playgroud)
另外请确保您不压缩zip中的视频以使其正常工作!例如,不压缩.mp4文件:
zip -n .mp4 -r zipfile.zip . -x ".*" -x "*/.*"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
58477 次 |
| 最近记录: |