{"id":732,"date":"2020-08-06T16:04:35","date_gmt":"2020-08-06T08:04:35","guid":{"rendered":"https:\/\/badgameshow.com\/fly\/?p=732"},"modified":"2020-08-06T16:08:25","modified_gmt":"2020-08-06T08:08:25","slug":"android-%e5%8f%96%e5%be%97%e6%89%8b%e6%a9%9f%e5%85%a7%e5%b7%b2%e5%ae%89%e8%a3%9d%e7%9a%84app%e8%b3%87%e8%a8%8a","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/fly\/android-%e5%8f%96%e5%be%97%e6%89%8b%e6%a9%9f%e5%85%a7%e5%b7%b2%e5%ae%89%e8%a3%9d%e7%9a%84app%e8%b3%87%e8%a8%8a\/","title":{"rendered":"Android \u53d6\u5f97\u624b\u6a5f\u5167\u5df2\u5b89\u88dd\u7684APP\u8cc7\u8a0a"},"content":{"rendered":"<h3>1.\u5148\u6488\u53d6APP\u6240\u6709\u7684PackgeName<\/h3>\n<pre><code class=\"language-Kotlin line-numbers\">val intent = Intent(Intent.ACTION_MAIN)\nintent.addCategory(Intent.CATEGORY_LAUNCHER)\nval resolveInfoList = packageManager.queryIntentActivities(intent, 0)\n<\/code><\/pre>\n<h3>2.\u628a\u6240\u6709app\u7684\u8cc7\u8a0a\u6488\u51fa\u4f86<\/h3>\n<pre><code class=\"language-Kotlin line-numbers\">for (resolveInfo in resolveInfoList) {\n    val appPackageName = resolveInfo.activityInfo.applicationInfo.packageName\n    if (resolveInfo.activityInfo.applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM == 0) {\n         Log.d(\"appInfo\",\"<span class=\"katex math inline\">appPackageName\\t<\/span>{getAppName(appPackageName)}\\t<span class=\"katex math inline\">{getFirstInstalled(appPackageName)}\\t<\/span>{getLastUpdated(appPackageName)}\\t<span class=\"katex math inline\">{getAppVersion(appPackageName)}\\t<\/span>{getAppIconURI(appPackageName)}\" )\n    }\n}\n<\/code><\/pre>\n<h3>3.\u53d6\u5f97APP\u540d\u7a31<\/h3>\n<pre><code class=\"language-Kotlin line-numbers\">private fun getAppName(ApkPackageName: String) = packageManager.getApplicationLabel(\n    packageManager.getApplicationInfo(\n        ApkPackageName,\n        0\n    )\n) as String\n<\/code><\/pre>\n<h3>4.\u53d6\u5f97APP\u7248\u672c<\/h3>\n<pre><code class=\"language-Kotlin line-numbers\">private fun getAppVersion(ApkPackageName: String) = packageManager.getPackageInfo(ApkPackageName, 0).versionName\n<\/code><\/pre>\n<h3>5.\u53d6\u5f97\u5b89\u88dd\u7684\u6642\u9593<\/h3>\n<pre><code class=\"language-Kotlin line-numbers\">private fun getFirstInstalled(ApkPackageName: String) = \"\u5b89\u88dd:${getDate(packageManager.getPackageInfo(ApkPackageName, 0).firstInstallTime)}\"\n<\/code><\/pre>\n<h3>6.\u53d6\u5f97\u6700\u5f8c\u66f4\u65b0\u7684\u6642\u9593<\/h3>\n<pre><code class=\"language-Kotlin line-numbers\">private fun getLastUpdated(ApkPackageName: String) =  \"\u6700\u5f8c\u66f4\u65b0:${getDate(packageManager.getPackageInfo(ApkPackageName, 0).lastUpdateTime)}\"\n<\/code><\/pre>\n<h3>7.\u6642\u9593\u8f49\u63db\u70ba\u897f\u5143\u5e74<\/h3>\n<pre><code class=\"language-Kotlin line-numbers\">@SuppressLint(\"SimpleDateFormat\")\nprivate fun getDate(milliSeconds: Long): String {\n   val formatter = SimpleDateFormat(\"yyyy\/MM\/dd\")\n   val calendar = Calendar.getInstance()\n   calendar.timeInMillis = milliSeconds\n   return formatter.format(calendar.time)\n}\n<\/code><\/pre>\n<h3>8.\u53d6\u5f97APP ICON URI<\/h3>\n<pre><code class=\"language-Kotlin line-numbers\">private fun getAppIconURI(ApkTempPackageName: String): Uri {\n   var resUri = Uri.EMPTY\n   val appInfo = packageManager.getApplicationInfo(ApkTempPackageName, 0)\n   if (appInfo.icon != 0) {\n       resUri = Uri.parse(\"android.resource:\/\/\" + ApkTempPackageName + \"\/\" + appInfo.icon)\n   }\n        return resUri\n}\n<\/code><\/pre>\n<h3>9.\u53d6\u5f97\u7d50\u679c<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/badgameshow.com\/fly\/wp-content\/uploads\/2020\/08\/getAppInfo.jpg\" alt=\"\" \/><\/p>\n\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>1.\u5148\u6488\u53d6APP\u6240\u6709\u7684PackgeName val intent = Intent(Intent.ACTION &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[5],"tags":[13,116,15],"class_list":["post-732","post","type-post","status-publish","format-standard","hentry","category-android","tag-android","tag-appinfo","tag-kotlin"],"_links":{"self":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/732","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/comments?post=732"}],"version-history":[{"count":2,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/732\/revisions"}],"predecessor-version":[{"id":736,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/732\/revisions\/736"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/media?parent=732"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/categories?post=732"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/tags?post=732"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}