gpt4 book ai didi

android - 获取资源值时没有包标识符

转载 作者:行者123 更新时间:2023-11-30 01:44:26 26 4
gpt4 key购买 nike

我正在尝试获取设备 ThirdParty 和系统上所有应用程序的列表,我在 AsyncTask 中运行此操作,当应用程序打开任务运行时,我在获取此列表期间看到了一个很长的操作此操作我看到警告打印在 Logcat 中,我认为这是长时间操作背后的原因:

11-26 09:51:23.720 1739-1846/com.example.AppList W/ResourceType: No package identifier when getting value for resource number 0x00000000
11-26 09:51:23.720 1739-1846/com.example.AppList W/PackageManager: Failure retrieving resources for com.google.android.onetimeinitializer: Resource ID #0x0
11-26 09:51:23.870 1739-1846/com.example.AppList W/ResourceType: No package identifier when getting value for resource number 0x00000000
11-26 09:51:23.870 1739-1846/com.example.AppList W/PackageManager: Failure retrieving resources for com.qualcomm.shutdownlistner: Resource ID #0x0
11-26 09:51:23.994 1739-1846/com.example.AppList W/ResourceType: No package identifier when getting value for resource number 0x00000000
11-26 09:51:23.994 1739-1846/com.example.AppList W/PackageManager: Failure retrieving resources for com.android.wallpapercropper: Resource ID #0x0
11-26 09:51:24.744 1739-1846/com.example.AppList W/ResourceType: No package identifier when getting value for resource number 0x00000000
11-26 09:51:24.744 1739-1846/com.example.AppList W/PackageManager: Failure retrieving resources for com.android.documentsui: Resource ID #0x0
11-26 09:51:24.873 1739-1846/com.example.AppList W/ResourceType: No package identifier when getting value for resource number 0x00000000
11-26 09:51:24.874 1739-1846/com.example.AppList W/PackageManager: Failure retrieving resources for com.android.externalstorage: Resource ID #0x0
....
....
/**
* I got all installed and system apps on the device
* listed as the above in the logcat as Warning.
*/
....
.... to the end.

这是 doInBackground 代码:

@Override
protected final List<App> doInBackground(List<App>... params) {

PackageManager pm = getActivity().getPackageManager();
List<ApplicationInfo> appsList = pm.getInstalledApplications(0);
List<PackageInfo> packList = pm.getInstalledPackages(0);
List<App> userApps = new ArrayList<>();
int totalApp = appsList.size();

for (int i = 0; i < totalApp; i++) {
ApplicationInfo info = appsList.get(i);
final App app = new App();

app.setIcon(info.loadIcon(getActivity().getPackageManager()));
app.setName(info.loadLabel(getActivity().getPackageManager()).toString());
app.setPackageName(info.packageName);

if ((info.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
userApps.add(app);
}
}
return userApps;
}

那么如何解决这个问题,或者只是如何解决长时间操作?


编辑

我试图从列表中删除应用程序图标功能,它的加载速度比附加图像时快,所以问题在图像中

@David Corsalini 在 comments 中告诉我这个:

Load the bitmap in a background thread, call this background thread from the holder.bind() method. I don't have the code for this one.

我正在使用带有 ViewHolderListView 但不知道 holder.bind(),请问如何实现? !

最佳答案

加载应用程序图标需要很长时间,因为您将所有应用程序图标作为可绘制对象存储在一个大列表中 - 这不是一个好主意,除非您必须这样做。相反,我建议在您的 App 类中删除该“图标”变量并在您的列表适配器中加载该图标。在列表适配器的 getView 方法中,您可以如下设置图标可绘制对象:

    Drawable icon;
try {
icon = context.getPackageManager().getApplicationIcon(packageName);
} catch (PackageManager.NameNotFoundException ex) {
Log.e(TAG, "Error", ex);
icon = context.getResources().getDrawable(R.drawable.icon_default);
}

holder.imageview.setImageDrawable(icon);

我不知道你是如何实现你的适配器的,但我的建议是提供你在后台任务中收集的 App 对象的列表,并提供这些 App 对象的包名称。希望对您有所帮助。

关于android - 获取资源值时没有包标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33933374/

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