如何使用Java从Google Play应用bundle按需加载Android资产包



如何使用Java从Google Play应用捆绑包按需加载Android资产包
我已尝试传递参数并在AssetPack Manager中对其进行硬编码。我认为我的问题和不理解界面有关。

一些链接

https://developer.android.com/guide/playcore/asset-delivery/integrate-java
Play Core Java API提供用于请求资产包的AssetPackManager类,管理下载和访问资产。您根据要访问的资产包的交付类型来实现此API。

https://developer.android.com/reference/com/google/android/play/core/assetpacks/AssetPackManager#getpacklocation

我的资产包(SongsNW)结构与应用程序的缩进级别相同

app  // my app
src
main
java
AndroidManifest.xml
build.gradle

我的应用程序级build.gradle(上图)列出了我的AssetPack

android {
other {
...
}
dynamicFeatures = [':....X', ':SongsNW', ':.....Y', ':.....Z']
}
dependencies {
....
}

我的资产包(SongsNW)

SongsNW 
src
main
assets
NW folder with assets
AndroidManifest.xml
build.gradle

我的AndroidManifest.xml(在上面的SongsNW下)

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dist="http://schemas.android.com/apk/distribution"
package="com.companyname.songsnw">

<dist:module
dist:instant="false"
dist:title="@string/title_songsnw">
<dist:delivery>
<dist:on-demand/>
</dist:delivery>
<dist:fusing dist:include="false" />
</dist:module>
</manifest>

我的build.gradle(在上面的SongsNW下)

apply plugin: 'com.android.asset-pack'

assetPack {
packName = "SongsNW" // Directory name for the asset pack
dynamicDelivery {
deliveryType = "on-demand"
}
}

LoadAssetPackage.java(模块)

package com.companyname.appname;

import android.util.Log;
import com.google.android.play.core.assetpacks.AssetPackLocation;
import com.google.android.play.core.assetpacks.AssetPackState;
import com.google.android.play.core.assetpacks.AssetPackStates;
import com.google.android.play.core.tasks.OnCompleteListener;
import com.google.android.play.core.tasks.RuntimeExecutionException;
import com.google.android.play.core.tasks.Task;

import static android.content.ContentValues.TAG;


interface AssetPackManager {
// I am passing the assetPackName to here with this call:
// AssetPackLocation assetPackLocation = AssetPackManager.getPackLocation("SongsNW");
public static final String TAG = "LoadAssetPack";
public static final String assetPackName = "";
// public static final String assetPackName = "SongsNW";
public static final AssetPackLocation assetPacklocation = null;
public static final AssetPackLocation assetPackLocation = getPackLocation(assetPackName);
public static AssetPackLocation getPackLocation(String assetPackName) {
Log.d(TAG, "in AssetPackManager assetPackName:" + assetPackName);
AssetPackLocation assetPackLocation = getPackLocation(assetPackName);
Log.d(TAG, "assetPackName:" + assetPackName + " assetPackLocation: " + assetPackLocation );
return assetPackLocation;  // null if it isn't complete
}
// I need to run the following list, but first I need to understand what I am doing wrong.
AssetPackStates cancel (List<String> packNames)
Task<AssetPackStates> fetch (List<String> packNames)
Task<AssetPackStates> getPackStates (List<String> packNames)
void registerListener (AssetPackStateUpdateListener listener)
Task<Void> removePack (String packName)
Task<Integer> showCellularDataConfirmation (Activity activity)
void unregisterListener (AssetPackStateUpdateListener listener)
}

这不是上述问题的答案,但我相信它能更好地定义问题

首先能够看到原始错误消息
将Android Studio Logcat缓冲区大小增加到16384 KB(默认1024 KB)
文件>设置>编辑器>概述>控制台>覆盖控制台循环缓冲区大小
然后您可以在顶部看到错误

Logcat中的消息:
I/SystemServer:InitBeforeStartServices
W/YouTube:在批量初始化结束前获取Gservices密钥'disable_binder_callback_flush'
W/Primes:Primes未初始化,返回默认(无操作)Primes实例,该实例将忽略所有调用
在使用任何Primes API之前,请调用Primes.initialize(…)

Google上述错误提供:
Play Services尝试验证,过早关闭配置文件弹出窗口,失败#2362
https://github.com/playgameservices/play-games-plugin-for-unity/issues/2362

在下面的评论中,他们正在讨论Google Play服务
。。。Web客户端ID是正确的方法。一旦我把它配置好了,它就成功了。不直观的部分是redirect_uri。对于任何遇到同样问题的人来说,因为Google API控制台不是超级直观的:在凭证部分,在Oauth同意屏幕选项卡下,底部是一个";授权域";部分为了添加授权域,您需要将其键入下面的框中,上面写着example.com。

这带来了许多额外的问题:
什么是Web客户端ID?这个凭据部分在哪里?什么是redirect_uri?什么是我的授权域?真正的问题是,我为什么要创建和管理谷歌云项目?我相信,答案是因为Google Play就是在这里存储我的应用程序包的。

正确管理项目的答案可能是:
https://cloud.google.com/resource-manager/docs/creating-managing-projects

我在
Google Play控制台上找到了OAuth客户端>设置>开发人员帐户>API访问

所以,我现在的问题是:;我需要在Google Play中填写什么来初始化系统服务器。(这是我的第一个错误陈述)。

Google Play说我无法在内部存储中存储资产>安卓>obb,所以我试图实现资产包,但失败了,并写了这个问题。我最终只是将Play Store上的每个资产作为一个应用程序安装,并将以下内容添加到我的帮助页面中。

此应用程序中没有歌曲。零。你必须从另一个应用程序加载它们。目前有四个其他应用程序与此应用程序相关:Birding Via Mic New World。。。旧世界。。。东方澳大拉西亚,和。。。北美公地。

这些应用程序包含各自地区的歌曲(下面称为YourRegion),但除了向该应用程序提供它们所包含的歌曲外,没有其他功能。您需要安装其中一首(或多首,如果需要),并将歌曲传输到此应用程序。

如果您运行的是Android 6.0或更高版本,请验证您的权限是否已打开:设置>应用程序>应用程序管理器>Birding Via Mic>权限

要传输歌曲:

  1. 安装此Birding Via Mic应用程序
  2. 安装Birding Via Mic_YourRegion应用程序
  3. 打开Birding Via Mic_YourRegion,点击歌曲并验证是否显示歌曲列表
  4. 在这个Birding Via Mic应用程序中,点击Path按钮
  5. 在Path(路径)屏幕上,选择Birding Via Mic--YourRegion(通过麦克风观鸟)
  6. 点击";立即加载";按钮卸载Birding Via Mic_YourRegion应用程序以恢复内存

最新更新