Skip to content

Instantly share code, notes, and snippets.

@mattermon
Created October 12, 2018 09:30
Show Gist options
  • Save mattermon/b8c358e018215a37ba4e2f12c8d8f00d to your computer and use it in GitHub Desktop.
Save mattermon/b8c358e018215a37ba4e2f12c8d8f00d to your computer and use it in GitHub Desktop.
获取应用名/Label
private AppInfo getAppInfo() {
int INVALID_TEXTURE_ID = -1;
AppInfo appInfo = new AppInfo();
PackageManager pm = context.getPackageManager();
PackageInfo pi = pm.getPackageArchiveInfo(path, PackageManager.GET_ACTIVITIES);
pi.applicationInfo.sourceDir = path;
pi.applicationInfo.publicSourceDir = path;
int textureId = INVALID_TEXTURE_ID;
Bitmap bitmap = drawableToBitmap(pi.applicationInfo.loadIcon(pm));
if (!bitmap.isRecycled()) {
textureId = TextureGenerator.generateTextureId();
TextureGenerator.createTexture(bitmap, textureId);
}
appInfo.setTextureId(textureId);
appInfo.setAppName(pi.applicationInfo.loadLabel(pm).toString());
appInfo.setPackageName(pi.packageName);
return appInfo;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment