{"id":10572,"date":"2023-10-31T15:08:29","date_gmt":"2023-10-31T07:08:29","guid":{"rendered":"https:\/\/h5app.yimenapp.cn\/h5app\/?p=10572"},"modified":"2023-10-31T15:08:29","modified_gmt":"2023-10-31T07:08:29","slug":"android%e5%bc%80%e5%8f%91%e6%b7%bb%e5%8a%a0apk-%e5%ae%89%e8%a3%85%e5%b9%bf%e6%92%ad%e5%a6%82%e4%bd%95%e6%93%8d%e4%bd%9c%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/h5app.yimenapp.cn\/h5app\/2023\/appkfa\/10572\/","title":{"rendered":"android\u5f00\u53d1\u6dfb\u52a0apk \u5b89\u88c5\u5e7f\u64ad\u5982\u4f55\u64cd\u4f5c\uff1f"},"content":{"rendered":"<p>\u5728Android\u5f00\u53d1\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0APK\u5b89\u88c5\u5e7f\u64ad\u6765\u76d1\u542c\u5b89\u88c5\u5e94\u7528\u7684\u4e8b\u4ef6\u3002\u901a\u8fc7\u76d1\u542c\u5b89\u88c5\u5e7f\u64ad\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u5e94\u7528\u5b89\u88c5\u5b8c\u6210\u540e\u6267\u884c\u4e00\u4e9b\u64cd\u4f5c\uff0c\u6bd4\u5982\u663e\u793a\u5b89\u88c5\u5b8c\u6210\u7684\u63d0\u793a\u4fe1\u606f\u3001\u81ea\u52a8\u542f\u52a8\u5e94\u7528\u7b49\u3002<\/p>\n<p>\u6dfb\u52a0APK\u5b89\u88c5\u5e7f\u64ad\u7684\u8fc7\u7a0b\u5982\u4e0b\uff1a<\/p>\n<p>1. \u521b\u5efa\u5e7f\u64ad\u63a5\u6536\u5668\u7c7b<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u7ee7\u627f\u81eaBroadcastReceiver\u7684\u5e7f\u64ad\u63a5\u6536\u5668\u7c7b\u3002\u5728\u8be5\u7c7b\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u91cd\u5199onReceive()\u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u4f1a\u5728\u63a5\u6536\u5230\u5e7f\u64ad\u65f6\u88ab\u8c03\u7528\u3002<\/p>\n<p>&#8220;`java<\/p>\n<p>public class ApkInstallReceiver extends BroadcastReceiver {<\/p>\n<p>    @Override<\/p>\n<p>    public void onReceive(Context context, Intent intent) {<\/p>\n<p>        if (intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED)) {<\/p>\n<p>            \/\/ \u5e94\u7528\u5b89\u88c5\u5b8c\u6210\u540e\u7684\u64cd\u4f5c<\/p>\n<p>        }<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>2. \u6ce8\u518c\u5e7f\u64ad\u63a5\u6536\u5668<\/p>\n<p>\u5728AndroidManifest.xml\u6587\u4ef6\u4e2d\u6ce8\u518c\u5e7f\u64ad\u63a5\u6536\u5668\u3002\u5728\u6807\u7b7e\u5185\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801\uff1a<\/p>\n<p><p>&#8220;`xml<\/p>\n<p>\n<p>\n<\/p>\n<p>&#8220;`<\/p>\n<p>3. \u52a8\u6001\u7533\u8bf7\u6743\u9650<\/p>\n<p>\u4e3a\u4e86\u786e\u4fdd\u5e94\u7528\u53ef\u4ee5\u6536\u5230\u5b89\u88c5\u5e7f\u64ad\uff0c\u9700\u8981\u5728\u5e94\u7528\u8fd0\u884c\u65f6\u52a8\u6001\u7533\u8bf7\u6743\u9650\u3002\u5728Activity\u6216Fragment\u4e2d\u6dfb<\/p>\n<p><figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.cdn.yimenapp.com\/ag\/102\/apk\/67.jpg\" \/><\/figure>\n<\/p>\n<p>\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<p>&#8220;`java<\/p>\n<p>private static final int REQUEST_CODE_INSTALL_PERMISSION = 123;<\/p>\n<p>private void requestInstallPermission() {<\/p>\n<p>    if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.O) {<\/p>\n<p>        if (!getPackageManager().canRequestPackageInstalls()) {<\/p>\n<p>            Uri packageUri = Uri.parse(&#8220;package:&#8221; + getPackageName());<\/p>\n<p>            Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES, packageUri);<\/p>\n<p>            startActivityForResult(intent, REQUEST_CODE_INSTALL_PERMISSION);<\/p>\n<p>        } else {<\/p>\n<p>            \/\/ \u5df2\u7ecf\u5f00\u542f\u5141\u8bb8\u5b89\u88c5\u672a\u77e5\u6765\u6e90\u5e94\u7528\u7684\u6743\u9650<\/p>\n<p>        }<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p>@Override<\/p>\n<p>protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {<\/p>\n<p>    super.onActivityResult(requestCode, resultCode, data);<\/p>\n<p>    if (requestCode == REQUEST_CODE_INSTALL_PERMISSION) {<\/p>\n<p>        if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.O) {<\/p>\n<p>            if (getPackageManager().canRequestPackageInstalls()) {<\/p>\n<p>                \/\/ \u7528\u6237\u5df2\u7ecf\u5141\u8bb8\u5b89\u88c5\u672a\u77e5\u6765\u6e90\u5e94\u7528\u7684\u6743\u9650<\/p>\n<p>            } else {<\/p>\n<p>                \/\/ \u7528\u6237\u672a\u5141\u8bb8\u5b89\u88c5\u672a\u77e5\u6765\u6e90\u5e94\u7528\u7684\u6743\u9650<\/p>\n<p>            }<\/p>\n<p>        }<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>4. \u7533\u8bf7\u6743\u9650\u540e\u7684\u64cd\u4f5c<\/p>\n<p>\u5f53\u7528\u6237\u5728\u6743\u9650\u7533\u8bf7\u754c\u9762\u5141\u8bb8\u4e86\u5b89\u88c5\u672a\u77e5\u6765\u6e90\u5e94\u7528\u6743\u9650\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5728onActivityResult()\u65b9\u6cd5\u4e2d\u76d1\u542c\u5230\uff0c\u5e76\u53ef\u4ee5\u6267\u884c\u76f8\u5e94\u7684\u64cd\u4f5c\u3002<\/p>\n<p>&#8220;`java<\/p>\n<p>@Override<\/p>\n<p>protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {<\/p>\n<p>    super.onActivityResult(req<a href=\"https:\/\/www.anzhuoe.net\/apk-dabao-2318.html\">eclipse\u6253\u5305\u7684apk\u635f\u574f<\/a>uestCode, resultCode, data);<\/p>\n<p>    if (requestCode == REQUEST_CODE<a href=\"https:\/\/www.anzhuoe.net\/apk-dabao-5066.html\">\u8c37\u6b4c\u6d4f\u89c8\u5668\u751f\u6210apk<\/a>_INSTALL_PERMISSION) {<\/p>\n<p>        if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.O) {<\/p>\n<p>            if (getPackageManager().canRequestPackageInstalls()) {<\/p>\n<p>                \/\/ \u7528\u6237\u5df2\u7ecf\u5141\u8bb8\u5b89\u88c5\u672a\u77e5\u6765\u6e90\u5e94\u7528\u7684\u6743\u9650<\/p>\n<p>                \/\/ \u7ee7\u7eed\u6267\u884c\u5e94\u7528\u5b89\u88c5\u5b8c\u6210\u540e\u7684\u64cd\u4f5c<\/p>\n<p>            } else {<\/p>\n<p>                \/\/ \u7528\u6237\u672a\u5141\u8bb8\u5b89\u88c5\u672a\u77e5\u6765\u6e90\u5e94\u7528\u7684\u6743\u9650<\/p>\n<p>            }<\/p>\n<p>        }<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>5. \u5e94\u7528\u5b89\u88c5\u5b8c\u6210\u540e\u7684\u64cd\u4f5c<\/p>\n<p>\u4f60\u53ef\u4ee5\u5728\u5e7f\u64ad\u63a5\u6536\u5668\u7684onReceive()\u65b9\u6cd5\u4e2d\u6267\u884c\u5e94\u7528\u5b89\u88c5\u5b8c\u6210\u540e\u7684\u64cd\u4f5c\uff0c\u6bd4\u5982\u663e\u793a\u5b89\u88c5\u5b8c\u6210\u7684\u63d0\u793a\u4fe1\u606f\u6216\u81ea\u52a8\u542f\u52a8\u5e94\u7528\u7b49\u3002<\/p>\n<p>&#8220;`java<\/p>\n<p>public class ApkInstallReceiver extends BroadcastReceiver {<\/p>\n<p>    @Override<\/p>\n<p>    public void onReceive(Context context, Intent intent) {<\/p>\n<p>        if (intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED)) {<\/p>\n<p>            \/\/ \u5e94\u7528\u5b89\u88c5\u5b8c\u6210\u540e\u7684\u64cd\u4f5c<\/p>\n<p>            Toast.makeText(context, &#8220;\u5e94\u7528\u5b89\u88c5\u5b8c\u6210&#8221;, Toast.LENGTH_SHORT).show();<\/p>\n<p>        }<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u76d1\u542c\u5e94\u7528\u5b89\u88c5\u5b8c\u6210\u7684\u4e8b\u4ef6\uff0c\u5e76\u5728\u5b89\u88c5\u5b8c\u6210\u540e\u6267\u884c\u76f8\u5e94\u7684\u64cd\u4f5c\u3002\u8bf7\u6ce8\u610f\uff0c\u5728Android 8.0\u53ca\u4ee5\u4e0a\u7248\u672c\u4e2d\u9700\u8981\u52a8\u6001\u7533\u8bf7\u6743\u9650\u624d\u80fd\u6536\u5230\u5b89\u88c5\u5e7f\u64ad\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728Android\u5f00\u53d1\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0APK\u5b89\u88c5\u5e7f\u64ad\u6765\u76d1\u542c\u5b89\u88c5\u5e94\u7528\u7684\u4e8b\u4ef6\u3002\u901a\u8fc7\u76d1\u542c\u5b89\u88c5\u5e7f\u64ad\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u5e94\u7528\u5b89\u88c5\u5b8c\u6210\u540e\u6267\u884c\u4e00\u4e9b\u64cd\u4f5c\uff0c\u6bd4\u5982\u663e\u793a\u5b89\u88c5\u5b8c\u6210\u7684\u63d0\u793a\u4fe1\u606f\u3001\u81ea\u52a8\u542f\u52a8\u5e94\u7528\u7b49\u3002\u6dfb\u52a0APK\u5b89\u88c5\u5e7f\u64ad\u7684\u8fc7<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[17468,17467,17469,1314,2049],"topic":[],"class_list":["post-10572","post","type-post","status-publish","format-standard","hentry","category-appkfa","tag-flutter-apk","tag-unityapk","tag-17469","tag-1314","tag-2049"],"_links":{"self":[{"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/posts\/10572","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/comments?post=10572"}],"version-history":[{"count":0,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/posts\/10572\/revisions"}],"wp:attachment":[{"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/media?parent=10572"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/categories?post=10572"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/tags?post=10572"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/topic?post=10572"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}