Created
October 12, 2018 09:30
-
-
Save mattermon/b8c358e018215a37ba4e2f12c8d8f00d to your computer and use it in GitHub Desktop.
获取应用名/Label
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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