未安装应用程序的应用程序信息
Application Info of a non installed app
我正在尝试从未安装的应用程序中获取一些信息(名称和图标)。基本上 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 指令中出现空指针异常。
顺便说一句,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);
REF:Get apk file icon, version, name
我正在尝试从未安装的应用程序中获取一些信息(名称和图标)。基本上 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 指令中出现空指针异常。
顺便说一句,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);
REF:Get apk file icon, version, name