{"id":12538,"date":"2022-11-24T14:16:11","date_gmt":"2022-11-24T06:16:11","guid":{"rendered":"https:\/\/www.yimenapp.com\/kb-yimen\/?p=12538"},"modified":"2022-11-24T14:16:11","modified_gmt":"2022-11-24T06:16:11","slug":"%e5%b0%8f%e7%b1%b3%e5%85%b3%e4%ba%8e%e8%b0%83%e6%95%b4%e8%8e%b7%e5%8f%96%e5%ba%94%e7%94%a8%e5%88%97%e8%a1%a8%e6%9d%83%e9%99%90%e6%96%b0%e5%a2%9e%e8%b0%83%e8%8a%82%e5%aa%92","status":"publish","type":"post","link":"https:\/\/www.yimenapp.com\/kb-yimen\/12538\/","title":{"rendered":"\u5c0f\u7c73\u5173\u4e8e\u8c03\u6574\u201c\u83b7\u53d6\u5e94\u7528\u5217\u8868\u201d\u6743\u9650&#038;\u65b0\u589e\u201c\u8c03\u8282\u5a92\u4f53\u97f3\u91cf\u201d\u6743\u9650\u7684\u9002\u914d\u8bf4\u660e"},"content":{"rendered":"\n<p>\u5c0f\u7c73\u5173\u4e8e\u8c03\u6574\u201c\u83b7\u53d6\u5e94\u7528\u5217\u8868\u201d<span class=\"wpcom_tag_link\"><a href=\"https:\/\/www.yimenapp.com\/kb-yimen\/tag\/%e6%9d%83%e9%99%90\/\" title=\"\u6743\u9650\" target=\"_blank\">\u6743\u9650<\/a><\/span>&amp;\u65b0\u589e\u201c\u8c03\u8282\u5a92\u4f53\u97f3\u91cf\u201d\u6743\u9650\u7684\u9002\u914d\u8bf4\u660e<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_0\">1\u3001\u83b7\u53d6\u5e94\u7528\u5217\u8868\u6743\u9650\u7b80\u4ecb<\/h2>\n\n\n\n<p>\u201c\u83b7\u53d6\u5e94\u7528\u5217\u8868\u201d\u6743\u9650\u662f\u5728<span class=\"wpcom_tag_link\"><a href=\"https:\/\/www.yimenapp.com\/kb-yimen\/tag\/android\/\" title=\"Android\" target=\"_blank\">Android<\/a><\/span>\u539f\u751f QUERY_ALL_PACKAGES \u6743\u9650\u57fa\u7840\u4e0a\u989d\u5916\u7684\u6743\u9650\u7ba1\u7406\u3002<\/p>\n\n\n\n<p>\u5f71\u54cd PackageManager#getInstalledPackages\u548cPackageManager#getInstalledApplications \u4e24\u4e2a\u63a5\u53e3\u8fd4\u56de\u503c\u3002<\/p>\n\n\n\n<p>\u5e94\u7528\u6ca1\u9002\u914d\u7684\u60c5\u51b5\u4e0b\uff0c\u9ed8\u8ba4\u6dfb\u52a0\u6743\u9650\u72b6\u662f\u201c\u4ec5\u5728\u4f7f\u7528\u4e2d\u5141\u8bb8\u201d\uff08\u5e94\u7528\u4e0d\u58f0\u660e\u4e5f\u4f1a\u6dfb\u52a0\uff09\uff0c\u5373\u5e94\u7528\u5728\u524d\u53f0\u65f6\u53ef\u4ee5\u6b63\u5e38\u83b7\u53d6\u3002\u4e5f\u53ef\u4ee5\u6309\u7167\u4e0b\u9762\u65b9\u6cd5\u9002\u914d\u52a8\u6001\u7533\u8bf7\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_1\">1.1.\u9002\u914d\u65b9\u6cd5<\/h2>\n\n\n\n<p>\u6e05\u5355\u6587\u4ef6\u58f0\u660e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;uses-permission android:name=\"com.android.permission.GET_INSTALLED_APPS\"\/&gt;<\/code><\/pre>\n\n\n\n<p>\u5224\u65adMIUI \u662f\u5426\u652f\u6301\u52a8\u6001\u7533\u8bf7\u6743\u9650<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>try<\/strong> {\n    PermissionInfo permissionInfo =  getApplicationContext().getPackageManager().getPermissionInfo(\"com.android.permission.GET_INSTALLED_APPS\", 0);\n    <strong>if<\/strong> (permissionInfo != <strong>null<\/strong> &amp;&amp; permissionInfo.packageName.equals(\"com.lbe.security.miui\")) {<em>\/\/MIUI \u7cfb\u7edf\u652f\u6301\u52a8\u6001\u7533\u8bf7\u8be5\u6743\u9650<\/em>\n        <strong>if<\/strong> (ContextCompat.checkSelfPermission(getApplicationContext(), \"com.android.permission.GET_INSTALLED_APPS\") != PackageManager.PERMISSION_GRANTED) {\n            <em>\/\/\u6ca1\u6709\u6743\u9650\uff0c\u9700\u8981\u7533\u8bf7<\/em>\n            ActivityCompat.requestPermissions(MainActivity.<strong>this<\/strong>, <strong>new<\/strong> String&#91;]{\"com.android.permission.GET_INSTALLED_APPS\"}, 999);\n        }\n    }\n} <strong>catch<\/strong> (PackageManager.NameNotFoundException e) {\n    e.printStackTrace();\n}<\/code><\/pre>\n\n\n\n<p>\u63d0\u793a\uff1a\u5982\u679c\u7cfb\u7edf\u4fa7\u4e0d\u652f\u6301\u6b64\u6743\u9650\uff0c\u5e94\u7528\u4ecd\u7136\u4f1a\u4fdd\u6301\u9ed8\u8ba4\uff08\u4ec5\u5728\u4f7f\u7528\u4e2d\u5141\u8bb8\uff09\u3002<\/p>\n\n\n\n<p>\u5224\u65ad\u6743\u9650\u6388\u4e88\u7ed3\u679c\uff08\u4e0e\u666e\u901a\u8fd0\u884c\u65f6\u6743\u9650\u6ca1\u6709\u533a\u522b\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>public<\/strong> <strong>void<\/strong> <strong>onRequestPermissionsResult<\/strong>(<strong>int<\/strong> requestCode, @NonNull String&#91;] permissions, @NonNull <strong>int<\/strong>&#91;] grantResults) {\n    <strong>super<\/strong>.onRequestPermissionsResult(requestCode, permissions, grantResults);\n    <em>\/\/ do something<\/em>\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_2\">1.2.\u7279\u6b8a\u8bf4\u660e\uff1a<\/h2>\n\n\n\n<p>\u5982\u679c\u4e0d\u9700\u8981\u7cfb\u7edf\u6dfb\u52a0\u83b7\u53d6\u5e94\u7528\u5217\u8868\u7684\u6743\u9650\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e0b\u9762\u4ee3\u7801\u5b9e\u73b0\uff08\u540c\u65f6\uff0c\u6e05\u5355\u6587\u4ef6\u4e2d\u4e0d\u80fd\u7533\u8bf7\u66f4\u6539\u6743\u9650\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;meta-data\n     android:name=\"do_not_need_get_installed_apps\"\n     android:value=\"true\"\/&gt;<\/code><\/pre>\n\n\n\n<p>\u6ce8\u610f\uff1a\u5982\u679c\u58f0\u660e\u6b64meta-data\uff0c\u7b49\u4e8e\u201c\u83b7\u53d6\u5e94\u7528\u5217\u8868\u201d\u6743\u9650\u5173\u95ed\uff01<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_3\">1.3.MIUI\u751f\u6548\u7248\u672c\uff1a<\/h2>\n\n\n\n<p>MIUI 13<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_4\">2\u3001\u8c03\u8282\u5a92\u4f53\u97f3\u91cf\u6743\u9650\u8bf4\u660e<\/h2>\n\n\n\n<p>\u4e3a\u51cf\u5c11\u90e8\u5206\u5e94\u7528\u64c5\u81ea\u4fee\u6539\u5a92\u4f53\u97f3\u91cf\uff0c\u800c\u4e0d\u4e3b\u52a8\u544a\u77e5\u7528\u6237\u6216\u83b7\u5f97\u7528\u6237\u8bb8\u53ef\u7684\u884c\u4e3a\uff0c\u540c\u65f6\u5c3d\u53ef\u80fd\u907f\u514d\u5bf9\u7528\u6237\u5e26\u6765\u76f8\u5e94\u7684\u56f0\u6270\u3002\u73b0\u5728\u5355\u72ec\u8bbe\u7acb\u201c\u8c03\u8282\u5a92\u4f53\u97f3\u91cf\u201d\u7684\u6743\u9650\uff0c\u5e76\u5c06\u9ed8\u8ba4\u72b6\u6001\u8bbe\u7f6e\u4e3a\u201c\u4ec5\u5728\u4f7f\u7528\u4e2d\u5141\u8bb8\u201d\u3002\u540c\u65f6\uff0c\u201c\u5e94\u7528\u884c\u4e3a\u8bb0\u5f55\u201d\u529f\u80fd\u4e2d\u5c06\u4f1a\u5bf9\u5e94\u7528\u4fee\u6539\u5a92\u4f53\u97f3\u91cf\u7684\u884c\u4e3a\u8fdb\u884c\u8bb0\u5f55\uff0c\u7528\u6237\u53ef\u4e3b\u52a8\u8c03\u6574\u76f8\u5173\u7684\u6743\u9650\u3002\u60a8\u7684\u5e94\u7528\u5982\u6709\u8c03\u8282\u5a92\u4f53\u97f3\u91cf\u7684\u9700\u6c42\uff0c\u53ef\u80fd\u53d7\u5230\u5f71\u54cd\uff0c\u5efa\u8bae\u60a8\u81ea\u884c\u8c03\u6574\u76f8\u5173\u7684\u4ea7\u54c1\u7b56\u7565\u3002<\/p>\n\n\n\n<p>MIUI 11\u53ca\u4ee5\u4e0b\u7248\u672c\u5c06\u4e0d\u53d7\u8be5\u8c03\u6574\u7684\u5f71\u54cd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u201c\u83b7\u53d6\u5e94\u7528\u5217\u8868\u201d\u6743\u9650\u662f\u5728Android\u539f\u751f QUERY_ALL_PACKAGES \u6743\u9650\u57fa\u7840\u4e0a\u989d\u5916\u7684\u6743\u9650\u7ba1\u7406\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46,94,160],"tags":[465,5789,3887],"special":[67],"attr":[],"class_list":["post-12538","post","type-post","status-publish","format-standard","hentry","category-appsj","category-appjc","category-appcs","tag-android","tag-5789","tag-3887","special-xiaomikfpt","entry"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/posts\/12538","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/comments?post=12538"}],"version-history":[{"count":1,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/posts\/12538\/revisions"}],"predecessor-version":[{"id":12539,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/posts\/12538\/revisions\/12539"}],"wp:attachment":[{"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/media?parent=12538"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/categories?post=12538"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/tags?post=12538"},{"taxonomy":"special","embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/special?post=12538"},{"taxonomy":"attr","embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/attr?post=12538"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}