取消定义packageName和Capture图标

时间:2018-09-23 20:23:15

标签: java android android-package-managers

我正在尝试获取指导应用程序的数据库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) {

}

1 个答案:

答案 0 :(得分:1)

您可以通过以下方式获取应用图标及其启动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);