gpt4 book ai didi

java - 取消定义 packageName 并捕获图标

转载 作者:行者123 更新时间:2023-11-29 23:33:30 25 4
gpt4 key购买 nike

我正在尝试获取数据库导向应用程序的 Package Name 并缩进应用程序的包图标并将其设置在 ImageView 中

到目前为止,我能够构建的是:

try {
Cliente movieDetailsVO=myDb.getFav(0); // DB sqlite

// Erro here next line --V
Drawable icon=getPackageManager().getApplicationIcon(movieDetailsVO.getCOLPM()); // <== get ID package app banco de dados
imgIcon.setImageDrawable(icon);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}

有人可以帮助我...


整理 @aminography 帮了我,非常感谢大家的关注

我是这样的

Cliente movieDetailsVO = myDb.getFav(0);
txtMovieNameDisplay.setText(movieDetailsVO.getNAME());
String packageName = movieDetailsVO.getCOLPM();

try {

Drawable icon = getContext().getPackageManager().getApplicationIcon(packageName);
imgIcon.setImageDrawable(icon);
} catch (PackageManager.NameNotFoundException ne) {

}

最佳答案

您可以获得应用程序图标及其启动Intent,如下所示:

Cliente movieDetailsVO = myDb.getFav(0);
String packageName = movieDetailsVO.getCOLPM(); // Be sure about package name correctness

Drawable drawable = null;
try {
drawable = getPackageManager().getApplicationIcon(packageName);
} catch (Exception ignored) {
}
Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);

// Try to use glide to show images into an ImageView
Glide.with(getApplicationContext()).load(drawable).into(imgIcon);

关于java - 取消定义 packageName 并捕获图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52469954/

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