java - 如何使用 Google Play 应用程序包中的 Java 按需加载 Android 资产包?
问题描述
如何使用 Google Play 应用程序包中的 Java 按需加载 Android 资产包?
我尝试在 AssetPackManager 中传递参数并对其进行硬编码。我认为我的问题与不理解界面有关。
一些链接
https://developer.android.com/guide/playcore/asset-delivery/integrate-java
Play Core Java API 提供了 AssetPackManager 类,用于请求资产包、管理下载和访问资产。您可以根据您希望访问的资产包的交付类型来实现此 API。
我的资产包(SongsNW)结构与应用程序处于同一级别缩进
app // my app
src
main
java
AndroidManifest.xml
build.gradle
我的应用级别 build.gradle(上图)列出了我的 AssetPacks
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"
}
}
LoadAssetPack.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:Prime 未初始化,返回默认(无操作)Prime 实例,该实例将忽略所有调用。
请在使用任何 Primes API 之前调用 Primes.initialize(...)。
谷歌上述错误提供:
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 Cloud 项目?我相信答案是因为那是 Google Play 存储我的应用程序包的地方。
正确管理项目的答案可能在:
https ://cloud.google.com/resource-manager/docs/creating-managing-projects
我在
Google Play 控制台 > 设置 > 开发者帐户 > API 访问中找到了 OAuth 客户端
所以,我此时的问题是:“我需要在 Google Play 中填写初始化系统服务器的最低要求是多少。(这是我的第一个错误声明)。
解决方案
Google Play 说我无法将资产存储在 Internal storage > Android > obb 中,所以我尝试实现 Asset Packs,失败了,然后写了这个问题。我最终只是将 Play Store 上的每个资产作为应用程序安装,并将以下内容添加到我的帮助页面中。
此应用程序中没有歌曲。零。您必须从另一个应用程序加载它们。目前还有其他四个应用程序与此应用程序相关联:通过麦克风新世界观鸟,...旧世界,...大洋洲东方,和...北美共同。
这些应用程序包含各自地区的歌曲(下面称为 YourRegion),但除了向该应用程序提供它们包含的歌曲外,没有其他功能。您将需要安装其中的一个(或多个,如果需要)并将歌曲传输到此应用程序。
如果您在 Android 6.0 或更高版本上运行,请验证您的权限是否已打开:设置 > 应用程序 > 应用程序管理器 > 通过 Mic 进行观鸟 > 权限
要传输歌曲:
- 通过 Mic 应用程序安装此 Birding。
- 通过 Mic_YourRegion 应用安装 Birding。
- 通过 Mic_YourRegion 打开 Birding,点击歌曲并验证是否显示歌曲列表。
- 在这个 Birding Via Mic 应用程序中,点击路径按钮。
- 在 Path 屏幕上选择 Birding Via Mic -- YourRegion。
- 点击“立即加载”按钮。卸载 Birding Via Mic_YourRegion 应用程序以恢复内存。
推荐阅读
- feature-extraction - 如何使用 Opencv 从 Harris Corner Detector 中提取关键点
- firebase - 来自远程 REST API 的 Firebase 分析?
- python-3.x - Newb python分数计数器语法问题
- javascript - Javascript - html 图片幻灯片
- swift - UIView.animate 和 CGRect 不起作用 - Swift 4
- javascript - 构建和测试中间 spiderMonkey 签入
- laravel - 如何在 Laravel 中使用多租户配置验证?
- javascript - 在jquery中动态添加复选框
- sql - 如何按日期对列进行总和
- python-3.x - 是否有一个 Python 库可以在提供邮政编码时返回一个城市?