- Jan 08 Tue 2019 23:41
[VoiceTube] 整天都藍瘦香菇?教你如何變快樂! (8 Scientific Tricks to Become Perfectly Happy)
- Jan 07 Mon 2019 23:12
[VoiceTube] 就算去掉「發霉」部分也不能吃! (Never Eat The ‘Clean’ Part Of Moldy Bread)
- Jan 05 Sat 2019 23:35
[VoiceTube] 如何停止過度思考? (How to Stop Overthinking | The Easy Way!)
- Aug 02 Thu 2018 01:23
[VoiceTube] 怎麼讀書才有效?13 個科學家證實的小撇步! (13 Study Tips)
- Jul 23 Mon 2018 22:59
[VoiceTube] Fix Your Bad English
- Mar 09 Fri 2018 00:08
[VoiceTube] 如何提高你的英語口語能力 (How to improve your English speaking skills (by yourself))
- Mar 08 Thu 2018 23:35
[VoiceTube] 你不能不知道:面試成功的五大秘訣(English Language Learning Tips - Job Interviews in English)
- Mar 08 Thu 2018 00:35
[VoiceTube] 為什麼日本的街頭巷尾都是販賣機? (Why Japan has so many vending machines)
- Feb 27 Tue 2018 10:18
[Android] get apk icon and get adaptive icon
public static Bitmap getApkIcon(Context context, String path) {
Bitmap icon = null;
PackageManager pm = context.getPackageManager();
PackageInfo packageInfo = pm.getPackageArchiveInfo(path, 0);
// if the apk file is broken, then packageInfo will be null
if (packageInfo == null) {
return null;
}
ApplicationInfo appInfo = packageInfo.applicationInfo;
//icon = pm.getApplicationLogo(appInfo);
AssetManager assetMgr = reflectionApis.getAssetManagerWithPath(path); // 拿到別的APK的AssetManager
if (null != assetMgr) {
Resources r = context.getResources(); // 取得一個實作Resource介面的實例後,可使用getFile()、getInputStream()等方式來操作或取得資源檔案的相關資源
Resources res = new Resources(assetMgr, r.getDisplayMetrics(), r.getConfiguration());
if (appInfo.icon > 0) {
Drawable drawable = ResourcesCompat.getDrawable(res, appInfo.icon, context.getTheme()); // 從appInfo中要icon並套用目前主題
if (drawable instanceof BitmapDrawable) { // 若是BitmapDrawable,直接getBitmap
icon = ((BitmapDrawable) drawable).getBitmap();
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
&& drawable instanceof AdaptiveIconDrawable) {// 先判斷是否為8.0後版本,以免前面版本不認得AdaptiveIconDrawable造成Crash
drawable為切成圓形的adaptive icon,若要自己切形狀則用layerDrawable疊起來在處理
int width = drawable.getIntrinsicWidth();
int height = drawable.getIntrinsicHeight();
icon = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(icon);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
} else {
icon = BitmapFactory.decodeResource(res, appInfo.icon);
}
}
assetMgr.close();
}
return icon;
}
}
getIntrinsicWidth用途:
http://lp43.blogspot.tw/2012/03/android.html
- Feb 08 Thu 2018 00:46
[VoiceTube] 要怎麼做才能早起? (How to Wake Up Early)