Android access to HD App icon code sharing _android

Source: Internet
Author: User

Android Gets the HD app icon in one way, as follows

Public synchronized static drawable Geticonfrompackagename (String PackageName, Context context) {Packagemanager pm = C
  Ontext.getpackagemanager (); if (Build.VERSION.SDK_INT >= build.version_codes.
    ICE_CREAM_SANDWICH_MR1) {try {packageinfo pi = pm.getpackageinfo (packagename, 0);
    Context Otherappctx = Context.createpackagecontext (PackageName, context.context_ignore_security); int displaymetrics[] = {Displaymetrics.density_xxxhigh,displaymetrics.density_xxhigh,displaymetrics.density_xhigh
    , Displaymetrics.density_high, DISPLAYMETRICS.DENSITY_TV}; for (int displaymetric:displaymetrics) {try {drawable d = otherappctx.getresources (). Getdrawablefordensity (
      Pi.applicationInfo.icon, Displaymetric);
      if (d!= null) {return D;
     The catch (Resources.notfoundexception e) {continue;
  The catch (Exception e) {//Handle Error here}} applicationinfo appInfo = null; try {appInfo = Pm.getapplicationinfO (packagename, 0);
  catch (Packagemanager.namenotfoundexception e) {return null;
 Return Appinfo.loadicon (PM); }

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.