gpt4 book ai didi

java - 未安装应用程序的应用程序信息

转载 作者:行者123 更新时间:2023-11-29 19:38:22 24 4
gpt4 key购买 nike

我正在尝试从未安装的应用程序中获取一些信息(名称和图标)。基本上 o 得到了 apk 文件,我还没有安装它,但我想在列表中显示它的名称和图标。

我正在尝试这样做:

public void getReceivedApps() {
packageManager = getPackageManager();
System.out.println("TRANSFER-RECORDActivityThe received filePath is : " + receivedFilePath);

PackageInfo packageInfo = packageManager.getPackageArchiveInfo(receivedFilePath, PackageManager.GET_GIDS);
System.out.println("TRANSFER RECORD ACTIVYT : O TO STRING TO PACKAGE INFO : " + packageInfo.toString());
ApplicationInfo applicationInfo = packageInfo.applicationInfo;
Log.d(this.getClass().getName(), "packaginf0 : " + applicationInfo.toString());
String appName = applicationInfo.loadLabel(packageManager).toString();

System.out.println("TRANSFER RECORD ACTIVITY : THE APPNAME IS : " + appName);
Drawable icon = packageManager.getPackageArchiveInfo(receivedFilePath, PackageManager.GET_GIDS).applicationInfo.loadIcon(packageManager);
//then add it to a list.
}

问题是它在 loadIcon 和 loadLabel 指令中给我一个 nullpointerexception。

顺便说一句,receivedFilePath 字符串具有该 apk 文件的文件路径(即

Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/"+getIntent().getStringExtra("receivedFilePath"); ) 

并且这个作为字符串发送的 receivedFilePath 具有文件的名称(不是应用程序)

最佳答案

发现了一个类似的问题,希望对你有帮助:

String APKFilePath = "mnt/sdcard/myapkfile.apk"; //For example...

PackageManager pm = getPackageManager();
PackageInfo pi = pm.getPackageArchiveInfo(APKFilePath, 0);

// the secret are these two lines....
pi.applicationInfo.sourceDir = APKFilePath;
pi.applicationInfo.publicSourceDir = APKFilePath;
//

Drawable APKicon = pi.applicationInfo.loadIcon(pm);
String AppName = (String)pi.applicationInfo.loadLabel(pm);

编号:Get apk file icon, version, name

关于java - 未安装应用程序的应用程序信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38996063/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com