本文整理汇总了C++中AssetManager::addAssetPath方法的典型用法代码示例。如果您正苦于以下问题:C++ AssetManager::addAssetPath方法的具体用法?C++ AssetManager::addAssetPath怎么用?C++ AssetManager::addAssetPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AssetManager
的用法示例。
在下文中一共展示了AssetManager::addAssetPath方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: extractSplitDescriptionsFromApk
static Vector<SplitDescription> extractSplitDescriptionsFromApk(const String8& path) {
AssetManager assetManager;
Vector<SplitDescription> splits;
int32_t cookie = 0;
if (!assetManager.addAssetPath(path, &cookie)) {
return splits;
}
const ResTable& res = assetManager.getResources(false);
if (res.getError() == NO_ERROR) {
Vector<ResTable_config> configs;
res.getConfigurations(&configs, true);
const size_t configCount = configs.size();
for (size_t i = 0; i < configCount; i++) {
splits.add();
splits.editTop().config = configs[i];
}
}
AssetDir* dir = assetManager.openNonAssetDir(cookie, "lib");
if (dir != NULL) {
const size_t fileCount = dir->getFileCount();
for (size_t i = 0; i < fileCount; i++) {
splits.add();
Vector<String8> parts = AaptUtil::splitAndLowerCase(dir->getFileName(i), '-');
if (parseAbi(parts, 0, &splits.editTop()) < 0) {
fprintf(stderr, "Malformed library %s\n", dir->getFileName(i).string());
splits.pop();
}
}
delete dir;
}
return splits;
}
示例2: doDump
int doDump(Bundle* bundle)
{
status_t result = UNKNOWN_ERROR;
if (bundle->getFileSpecCount() < 1) {
fprintf(stderr, "ERROR: no dump option specified\n");
return 1;
}
if (bundle->getFileSpecCount() < 2) {
fprintf(stderr, "ERROR: no dump file specified\n");
return 1;
}
const char* option = bundle->getFileSpecEntry(0);
const char* filename = bundle->getFileSpecEntry(1);
AssetManager assets;
int32_t assetsCookie;
if (!assets.addAssetPath(String8(filename), &assetsCookie)) {
fprintf(stderr, "ERROR: dump failed because assets could not be loaded\n");
return 1;
}
// Make a dummy config for retrieving resources... we need to supply
// non-default values for some configs so that we can retrieve resources
// in the app that don't have a default. The most important of these is
// the API version because key resources like icons will have an implicit
// version if they are using newer config types like density.
ResTable_config config;
memset(&config, 0, sizeof(ResTable_config));
config.language[0] = 'e';
config.language[1] = 'n';
config.country[0] = 'U';
config.country[1] = 'S';
config.orientation = ResTable_config::ORIENTATION_PORT;
config.density = ResTable_config::DENSITY_MEDIUM;
config.sdkVersion = 10000; // Very high.
config.screenWidthDp = 320;
config.screenHeightDp = 480;
config.smallestScreenWidthDp = 320;
config.screenLayout |= ResTable_config::SCREENSIZE_NORMAL;
assets.setConfiguration(config);
const ResTable& res = assets.getResources(false);
if (res.getError() != NO_ERROR) {
fprintf(stderr, "ERROR: dump failed because the resource table is invalid/corrupt.\n");
return 1;
}
// The dynamicRefTable can be null if there are no resources for this asset cookie.
// This fine.
const DynamicRefTable* dynamicRefTable = res.getDynamicRefTableForCookie(assetsCookie);
Asset* asset = NULL;
if (strcmp("resources", option) == 0) {
#ifndef __ANDROID__
res.print(bundle->getValues());
#endif
} else if (strcmp("strings", option) == 0) {
const ResStringPool* pool = res.getTableStringBlock(0);
printStringPool(pool);
} else if (strcmp("xmltree", option) == 0) {
if (bundle->getFileSpecCount() < 3) {
fprintf(stderr, "ERROR: no dump xmltree resource file specified\n");
goto bail;
}
for (int i=2; i<bundle->getFileSpecCount(); i++) {
const char* resname = bundle->getFileSpecEntry(i);
ResXMLTree tree(dynamicRefTable);
asset = assets.openNonAsset(assetsCookie, resname, Asset::ACCESS_BUFFER);
if (asset == NULL) {
fprintf(stderr, "ERROR: dump failed because resource %s found\n", resname);
goto bail;
}
if (tree.setTo(asset->getBuffer(true),
asset->getLength()) != NO_ERROR) {
fprintf(stderr, "ERROR: Resource %s is corrupt\n", resname);
goto bail;
}
tree.restart();
printXMLBlock(&tree);
tree.uninit();
delete asset;
asset = NULL;
}
} else if (strcmp("xmlstrings", option) == 0) {
if (bundle->getFileSpecCount() < 3) {
fprintf(stderr, "ERROR: no dump xmltree resource file specified\n");
goto bail;
}
for (int i=2; i<bundle->getFileSpecCount(); i++) {
const char* resname = bundle->getFileSpecEntry(i);
//.........这里部分代码省略.........
示例3: getAppInfo
static bool getAppInfo(const String8& path, AppInfo& outInfo) {
memset(&outInfo, 0, sizeof(outInfo));
AssetManager assetManager;
int32_t cookie = 0;
if (!assetManager.addAssetPath(path, &cookie)) {
return false;
}
Asset* asset = assetManager.openNonAsset(cookie, "AndroidManifest.xml", Asset::ACCESS_BUFFER);
if (asset == NULL) {
return false;
}
ResXMLTree xml;
if (xml.setTo(asset->getBuffer(true), asset->getLength(), false) != NO_ERROR) {
delete asset;
return false;
}
const String16 kAndroidNamespace("http://schemas.android.com/apk/res/android");
const String16 kManifestTag("manifest");
const String16 kApplicationTag("application");
const String16 kUsesSdkTag("uses-sdk");
const String16 kVersionCodeAttr("versionCode");
const String16 kMultiArchAttr("multiArch");
const String16 kMinSdkVersionAttr("minSdkVersion");
ResXMLParser::event_code_t event;
while ((event = xml.next()) != ResXMLParser::BAD_DOCUMENT &&
event != ResXMLParser::END_DOCUMENT) {
if (event != ResXMLParser::START_TAG) {
continue;
}
size_t len;
const char16_t* name = xml.getElementName(&len);
String16 name16(name, len);
if (name16 == kManifestTag) {
ssize_t idx = xml.indexOfAttribute(
kAndroidNamespace.string(), kAndroidNamespace.size(),
kVersionCodeAttr.string(), kVersionCodeAttr.size());
if (idx >= 0) {
outInfo.versionCode = xml.getAttributeData(idx);
}
} else if (name16 == kApplicationTag) {
ssize_t idx = xml.indexOfAttribute(
kAndroidNamespace.string(), kAndroidNamespace.size(),
kMultiArchAttr.string(), kMultiArchAttr.size());
if (idx >= 0) {
outInfo.multiArch = xml.getAttributeData(idx) != 0;
}
} else if (name16 == kUsesSdkTag) {
ssize_t idx = xml.indexOfAttribute(
kAndroidNamespace.string(), kAndroidNamespace.size(),
kMinSdkVersionAttr.string(), kMinSdkVersionAttr.size());
if (idx >= 0) {
uint16_t type = xml.getAttributeDataType(idx);
if (type >= Res_value::TYPE_FIRST_INT && type <= Res_value::TYPE_LAST_INT) {
outInfo.minSdkVersion = xml.getAttributeData(idx);
} else if (type == Res_value::TYPE_STRING) {
String8 minSdk8(xml.getStrings().string8ObjectAt(idx));
char* endPtr;
int minSdk = strtol(minSdk8.string(), &endPtr, 10);
if (endPtr != minSdk8.string() + minSdk8.size()) {
fprintf(stderr, "warning: failed to parse android:minSdkVersion '%s'\n",
minSdk8.string());
} else {
outInfo.minSdkVersion = minSdk;
}
} else {
fprintf(stderr, "warning: unrecognized value for android:minSdkVersion.\n");
}
}
}
}
delete asset;
return true;
}