2

我有超过 50MB 的项目。我在 raw 文件夹中有一些图像和视频。如何生成扩展文件?我已经浏览了开发人员文档,但对我来说并不清楚。它令人困惑。任何人都可以在这方面帮助我。

我应该从项目中复制原始文件夹并将其粘贴到桌面上,然后使用谷歌文档中给出的名称格式压缩整个文件夹吗?例如:我的包名称为“com.my.package”,版本代码为 1 和主扩展文件。我是否必须压缩整个原始文件夹并将名称命名为“main.1.com.my.package.zip”

创建后,我需要从项目文件夹中删除原始文件夹,然后我需要更改项目中的代码以从存储位置访问文件。我怎样才能做到这一点?

我使用以下代码访问原始文件夹中的文件。如何更改此设置以访问存储在 SD 卡中的扩展文件中的文件?

String path1 = "android.resource://" + getPackageName() + "/" + R.raw.e4;
4

4 回答 4

2

尽量减小尺寸。您可以在发布模式下启用 proguard。ProGuard 工具通过删除未使用的代码并使用语义模糊名称重命名类、字段和方法来缩小、优化和混淆您的代码。结果是更难以逆向工程的更小尺寸的 .apk 文件

您可以查看下面的链接。

http://developer.android.com/google/play/expansion-files.html#ZipLib

从 ZIP 文件中读取

使用 APK 扩展 Zip 库时,从 ZIP 读取文件通常需要以下内容:

// Get a ZipResourceFile representing a merger of both the main and patch files
ZipResourceFile expansionFile = APKExpansionSupport.getAPKExpansionZipFile(appContext,
    mainVersion, patchVersion);

// Get an input stream for a known file inside the expansion file ZIPs
InputStream fileStream = expansionFile.getInputStream(pathToFileInsideZip);

http://developer.android.com/google/play/expansion-files.html#StorageLocation

http://developer.android.com/google/play/expansion-files.html

编辑:

在链接中查看教程

http://ankitthakkar90.blogspot.in/2013/01/apk-expansion-files-in-android-with.html

于 2013-04-23T05:39:48.043 回答
1

您可以将文件压缩成一个文件,如果超过 2 GB,则压缩成 2 个文件(每个文件最多 2GB)。

另一种方法是您创建自己的算法,将所有文件放在一个文件中。

于 2013-04-23T09:29:00.230 回答
0

有两种类型的扩展文件,主要和补丁。您可以将所有数据(图像/文件)放在一个文件夹中。将其命名为 main.1.com.my.package. 这里 main 表示它的主要扩展文件。如果它的补丁比名称它patch.1...
1 是清单中的版本代码而不是包名称 压缩此文件并使用 .obb 扩展名重命名该压缩文件。从末尾删除 .zip,现在您的扩展文件已准备好名称 main.1.com.my.package.obb

您必须使用市场上的虚拟应用程序上传此文件。比您必须使用编码下载该文件(您可以从下载库中获取示例sdk/extras/google/play_apk_expansion
此文件在移动设备中的位置下载mnt/sdcard/android/obb

您可以使用该文件并解压缩文件并将其保存在任何其他位置并使用它。

如果您使用的是扩展文件,您将无法再从 Raw 文件夹中获取文件。

我自己已经成功地做到了这一点。希望它可以帮助你。

于 2013-06-26T12:43:29.787 回答
0

以下是在 Android 中设置扩展文件所需的步骤:

  1. 首先,打开Android SDK Manager,展开Extras并下载:

    • Google Play 许可库包
    • Google Play APK 扩展库包
  2. 在 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 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" />  
    
  3. 集成库

    • 将下载器库的源代码复制<sdk>/extras/google/play_apk_expansion/downloader_library/src到您的项目中。
    • 将源代码复制<sdk>/extras/google/play_licensing/library/src到您的项目中。
    • 将源代码复制<sdk>/extras/google/google_market_apk_expansion/zip_file/到您的项目中。
  4. 现在,创建一个名为扩展的新包并DownloaderService.java在包内创建。

    // DownloaderService.java
    public class DownloaderService extends com.google.android.vending.expansion.downloader.impl.DownloaderService {  
        public static final String BASE64_PUBLIC_KEY = "<<YOUR PUBLIC KEY HERE>>"; // TODO Add public key
        private static final byte[] SALT = new byte[]{1, 4, -1, -1, 14, 42, -79, -21, 13, 2, -8, -11, 62, 1, -10, -101, -19, 41, -12, 18}; // TODO Replace with random numbers of your choice
    
        @Override
        public String getPublicKey() {
            return BASE64_PUBLIC_KEY;
        }
    
        @Override
        public byte[] getSALT() {
            return SALT;
        }
    
        @Override
        public String getAlarmReceiverClassName() {
            return DownloaderServiceBroadcastReceiver.class.getName();
        }
    }
    
  5. 创建DownloaderServiceBroadcastReceiver.java扩展BoradcastReceiver,如果需要下载文件,它将启动下载服务。

    // DownloaderServiceBroadcastReceiver.java
    public class DownloaderServiceBroadcastReceiver extends android.content.BroadcastReceiver {  
        @Override
        public void onReceive(Context context, Intent intent) {
            try {
                DownloaderClientMarshaller.startDownloadServiceIfRequired(context, intent, DownloaderService.class);
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
    
  6. 如果扩展文件不可用,则从您的活动开始下载

    Intent launchIntent = MainActivity.this.getIntent();
    Intent intentToLaunchThisActivityFromNotification = new Intent(MainActivity.this, MainActivity.this.getClass());
    intentToLaunchThisActivityFromNotification.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intentToLaunchThisActivityFromNotification.setAction(launchIntent.getAction());
    
    if (launchIntent.getCategories() != null) {
        for (String category : launchIntent.getCategories()) {
            intentToLaunchThisActivityFromNotification.addCategory(category);
        }
    }
    
    // Build PendingIntent used to open this activity from notification
    PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, intentToLaunchThisActivityFromNotification, PendingIntent.FLAG_UPDATE_CURRENT);
    // Request to start the download
    int startResult = DownloaderClientMarshaller.startDownloadServiceIfRequired(this, pendingIntent, DownloaderService.class);
    

有关完整的详细信息和代码,请查看如何设置 Android 应用程序以支持扩展文件

于 2015-04-26T07:02:42.173 回答