zoukankan      html  css  js  c++  java
  • 获取应用图标并转为bitmap适配android10

     /**
         * 获取图标 bitmap
         *
         * @param context
         * Context.getExternalFilesDir(Environment.DIRECTORY_PICTURES)//android 10存储图片地址
         */
        public static synchronized Bitmap getBitmap(Context context) {
            PackageManager packageManager = null;
            ApplicationInfo applicationInfo = null;
            try {
                packageManager = context.getApplicationContext()
                        .getPackageManager();
                applicationInfo = packageManager.getApplicationInfo(
                        context.getPackageName(), 0);
            } catch (PackageManager.NameNotFoundException e) {
                applicationInfo = null;
            }
            Drawable d = packageManager.getApplicationIcon(applicationInfo); //xxx根据自己的情况获取drawable
    
            Bitmap APKicon;
            if(d instanceof BitmapDrawable) {
                APKicon  = ((BitmapDrawable)d).getBitmap();
            }else{
                Bitmap bitmap = Bitmap.createBitmap(d.getIntrinsicWidth(),d.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
                Canvas canvas = new Canvas(bitmap);
                d.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
                d.draw(canvas);
                APKicon = bitmap;
            }
    //        BitmapDrawable bd = (BitmapDrawable) d;
    //        Bitmap bm = bd.getBitmap();
            return APKicon;
        }
    

      

  • 相关阅读:
    Spring之Condition(二)在哪里解析的
    SpringBoot启动跟代码过程
    Spring之Condition(一)
    Kafka之 vm.max_map_count
    Redis常见面试题
    Redis为什么快
    TCP一个包多大
    场景问题
    这是一个测试
    小程序-使用django-drf开接口的步骤
  • 原文地址:https://www.cnblogs.com/wang-jingyuan/p/12173978.html
Copyright © 2011-2022 走看看