{"id":1635,"date":"2016-07-18T11:51:04","date_gmt":"2016-07-18T03:51:04","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=1635"},"modified":"2026-08-18T12:58:50","modified_gmt":"2026-08-18T04:58:50","slug":"android-%e5%bf%ab%e9%80%9f%e5%ae%9e%e7%8e%b0%e6%96%87%e4%bb%b6%e4%b8%8b%e8%bd%bd%ef%bc%88%e5%8f%aa%e6%9c%894%e8%a1%8c%e4%bb%a3%e7%a0%81%ef%bc%89","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=1635","title":{"rendered":"Android \u5feb\u901f\u5b9e\u73b0\u6587\u4ef6\u4e0b\u8f7d\uff08\u53ea\u67094\u884c\u4ee3\u7801\uff09"},"content":{"rendered":"<section id=\"wenyan\" style=\"font-family: system-ui, 'Apple Color Emoji', 'Segoe UI', 'Segoe UI Symbol', 'Noto Sans', Roboto, sans-serif; line-height: 1.75; font-size: 16px; color: #000000; caret-color: #000000;\" data-provider=\"WenYan\">\n<blockquote style=\"margin: 20px 0px; display: block; font-size: 0.9em; overflow: auto; border-left: 3px solid #ef7060; color: #6a737d; padding: 10px 10px 10px 20px; background: #fff9f9;\">\n<p style=\"margin: 1em 0px;\">\u5b8c\u6210\u4e00\u4e2a\u4e0b\u8f7d\u4efb\u52a1\u53ea\u9700\u8981 4 \u884c\u4ee3\u7801\u3002\u65ad\u70b9\u7eed\u4f20\u3001\u5927\u6587\u4ef6\u3001\u901a\u77e5\u680f\u8fdb\u5ea6\uff0c\u90fd\u53ef\u4ee5\u4ea4\u7ed9\u7cfb\u7edf <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">DownloadManager<\/code>\uff08API 9 \u8d77\u5c31\u6709\uff09\uff0c\u4e0d\u5fc5\u81ea\u5df1\u7ef4\u62a4\u8fde\u63a5\u3002<\/p>\n<\/blockquote>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u4e00\u3001\u7b80\u5355\u4f7f\u7528\uff1a\u56db\u884c\u5165\u961f<\/span><\/h2>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">\/\/\u521b\u5efa\u4e0b\u8f7d\u4efb\u52a1,downloadUrl\u5c31\u662f\u4e0b\u8f7d\u94fe\u63a5\nDownloadManager.Request request = new DownloadManager.Request(Uri.parse(downloadUrl));\n\/\/\u6307\u5b9a\u4e0b\u8f7d\u8def\u5f84\u548c\u4e0b\u8f7d\u6587\u4ef6\u540d\nrequest.setDestinationInExternalPublicDir(\"\/download\/\", fileName);\n\/\/\u83b7\u53d6\u4e0b\u8f7d\u7ba1\u7406\u5668\nDownloadManager downloadManager= (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);\n\/\/\u5c06\u4e0b\u8f7d\u4efb\u52a1\u52a0\u5165\u4e0b\u8f7d\u961f\u5217\uff0c\u5426\u5219\u4e0d\u4f1a\u8fdb\u884c\u4e0b\u8f7d\ndownloadManager.enqueue(request);<\/code><\/pre>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u4e8c\u3001\u9ad8\u7ea7\u7528\u6cd5\uff1aRequest \u4e0e Manager<\/span><\/h2>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section>\u4e0a\u9762\u7528\u7684\u662f\u7cfb\u7edf\u4e0b\u8f7d\u7ba1\u7406\u5668\uff0c\u4ece API 9 \u5f00\u59cb\u652f\u6301\uff0c\u517c\u5bb9\u6027\u4e0d\u7528\u989d\u5916\u64cd\u5fc3\u3002<\/section>\n<\/li>\n<li>\n<section>\u7cfb\u7edf\u63d0\u4f9b\u7684\u80fd\u529b\u6bd4\u56db\u884c\u5165\u961f\u66f4\u5168\uff0c\u53ef\u4ee5\u770b\u6e90\u7801\u91cc\u7684\u65b9\u6cd5\u5217\u8868\u3002<\/section>\n<\/li>\n<\/ul>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2016\/07\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200415222137.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2835\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2016\/07\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200415222137.png\" alt=\"\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200415222137\" width=\"695\" height=\"493\" \/><\/a><\/p>\n<p style=\"margin: 1em 0px;\">DownloadManager \u7684\u65b9\u6cd5<\/p>\n<p style=\"margin: 1em 0px;\">DownloadManager.Request \u7684\u65b9\u6cd5\u4e5f\u5df2\u7ecf\u6bd4\u8f83\u5168\uff0c\u80fd\u8986\u76d6\u7edd\u5927\u90e8\u5206\u573a\u666f\u3002<\/p>\n<table style=\"border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; text-align: left; overflow: auto; display: table; overflow-wrap: break-word; word-break: break-all;\" width=\"817\">\n<thead>\n<tr>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top; font-weight: bold; background-color: #fff9f9; color: #ef7060;\">\u6b65\u9aa4<\/th>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top; font-weight: bold; background-color: #fff9f9; color: #ef7060;\">API<\/th>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top; font-weight: bold; background-color: #fff9f9; color: #ef7060;\">\u4f5c\u7528<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u5efa\u4efb\u52a1<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">new Request(Uri)<\/code><\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u6307\u5b9a\u4e0b\u8f7d\u5730\u5740<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u843d\u76d8<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">setDestinationInExternalPublicDir<\/code><\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u5fc5\u987b\u8bbe\u7f6e\u4fdd\u5b58\u76ee\u5f55\u548c\u6587\u4ef6\u540d<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u5165\u961f<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">enqueue(request)<\/code><\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u8fd4\u56de long \u578b taskId\uff0c\u53ef\u53d6\u6d88\/\u67e5\u8be2<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u6536\u5c3e<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">ACTION_DOWNLOAD_COMPLETE<\/code><\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u5e7f\u64ad\u91cc\u518d\u67e5\u72b6\u6001\u3001\u88c5 APK<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u4e09\u3001\u5b9e\u9645\u4f7f\u7528\uff1a\u5e94\u7528\u5185\u66f4\u65b0<\/span><\/h2>\n<p style=\"margin: 1em 0px;\">\u4ee5 APP \u5e94\u7528\u5185\u66f4\u65b0\u4e3a\u4f8b\uff0c\u5148\u68b3\u7406\u6d41\u7a0b\uff1a<\/p>\n<p style=\"margin: 1em 0px;\"><img decoding=\"async\" class=\"imagebubble-image\" src=\"http:\/\/upload-images.jianshu.io\/upload_images\/960283-a736c903bf5839dc.png?imageMogr2\/auto-orient\/strip%7CimageView2\/2\/w\/1240\" alt=\"\" data-original-src=\"http:\/\/upload-images.jianshu.io\/upload_images\/960283-a736c903bf5839dc.png?imageMogr2\/auto-orient\/strip%7CimageView2\/2\" \/><\/p>\n<p style=\"margin: 1em 0px;\">APP \u5e94\u7528\u5185\u66f4\u65b0<\/p>\n<h3 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\">1. \u7528\u7cfb\u7edf\u4e0b\u8f7d\u5668\u62c9 APK<\/h3>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">\/\/\u4f7f\u7528\u7cfb\u7edf\u4e0b\u8f7d\u5668\u4e0b\u8f7d\nprivate void downloadAPK(String versionUrl, String versionName) {\n        \/\/\u521b\u5efa\u4e0b\u8f7d\u4efb\u52a1\n        DownloadManager.Request request = new DownloadManager.Request(Uri.parse(versionUrl));\n        request.setAllowedOverRoaming(false);\/\/\u6f2b\u6e38\u7f51\u7edc\u662f\u5426\u53ef\u4ee5\u4e0b\u8f7d\n\n        \/\/\u8bbe\u7f6e\u6587\u4ef6\u7c7b\u578b\uff0c\u53ef\u4ee5\u5728\u4e0b\u8f7d\u7ed3\u675f\u540e\u81ea\u52a8\u6253\u5f00\u8be5\u6587\u4ef6\n        MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();\n        String mimeString = mimeTypeMap.getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(versionUrl));\n        request.setMimeType(mimeString);\n\n        \/\/\u5728\u901a\u77e5\u680f\u4e2d\u663e\u793a\uff0c\u9ed8\u8ba4\u5c31\u662f\u663e\u793a\u7684\n        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);\n        request.setVisibleInDownloadsUi(true);\n\n        \/\/sdcard\u7684\u76ee\u5f55\u4e0b\u7684download\u6587\u4ef6\u5939\uff0c\u5fc5\u987b\u8bbe\u7f6e\n        request.setDestinationInExternalPublicDir(\"\/download\/\", versionName);\n        \/\/request.setDestinationInExternalFilesDir(),\u4e5f\u53ef\u4ee5\u81ea\u5df1\u5236\u5b9a\u4e0b\u8f7d\u8def\u5f84\n\n        \/\/\u5c06\u4e0b\u8f7d\u8bf7\u6c42\u52a0\u5165\u4e0b\u8f7d\u961f\u5217\n        downloadManager = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);\n        \/\/\u52a0\u5165\u4e0b\u8f7d\u961f\u5217\u540e\u4f1a\u7ed9\u8be5\u4efb\u52a1\u8fd4\u56de\u4e00\u4e2along\u578b\u7684id\uff0c\n        \/\/\u901a\u8fc7\u8be5id\u53ef\u4ee5\u53d6\u6d88\u4efb\u52a1\uff0c\u91cd\u542f\u4efb\u52a1\u7b49\u7b49\uff0c\u770b\u4e0a\u9762\u6e90\u7801\u4e2d\u6846\u8d77\u6765\u7684\u65b9\u6cd5\n        mTaskId = downloadManager.enqueue(request);\n\n        \/\/\u6ce8\u518c\u5e7f\u64ad\u63a5\u6536\u8005\uff0c\u76d1\u542c\u4e0b\u8f7d\u72b6\u6001\n        mContext.registerReceiver(receiver,\n                new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));\n    }<\/code><\/pre>\n<h3 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\">2. \u5e7f\u64ad\u63a5\u6536\u5668<\/h3>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">    \/\/\u5e7f\u64ad\u63a5\u53d7\u8005\uff0c\u63a5\u6536\u4e0b\u8f7d\u72b6\u6001\n    private BroadcastReceiver receiver = new BroadcastReceiver() {\n        @Override\n        public void onReceive(Context context, Intent intent) {\n            checkDownloadStatus();\/\/\u68c0\u67e5\u4e0b\u8f7d\u72b6\u6001\n        }\n    };<\/code><\/pre>\n<h3 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\">3. \u68c0\u67e5\u4e0b\u8f7d\u72b6\u6001<\/h3>\n<p style=\"margin: 1em 0px;\">\u539f\u6587 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">STATUS_SUCCESSFUL<\/code> \u5206\u652f\u6f0f\u4e86\u5192\u53f7\uff0c\u4e0b\u9762\u6309\u53ef\u7f16\u8bd1\u5199\u6cd5\u8865\u4e0a\uff1b\u6682\u505c\/\u5ef6\u8fdf\u4ecd\u6309\u539f\u6587\u843d\u5230\u300c\u6b63\u5728\u4e0b\u8f7d\u300d\u65e5\u5fd7\u3002<\/p>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\"> \/\/\u68c0\u67e5\u4e0b\u8f7d\u72b6\u6001\n    private void checkDownloadStatus() {\n        DownloadManager.Query query = new DownloadManager.Query();\n        query.setFilterById(mTaskId);\/\/\u7b5b\u9009\u4e0b\u8f7d\u4efb\u52a1\uff0c\u4f20\u5165\u4efb\u52a1ID\uff0c\u53ef\u53d8\u53c2\u6570\n        Cursor c = downloadManager.query(query);\n        if (c.moveToFirst()) {\n            int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));\n            switch (status) {\n                case DownloadManager.STATUS_PAUSED:\n                    MLog.i(\"&gt;&gt;&gt;\u4e0b\u8f7d\u6682\u505c\");\n                case DownloadManager.STATUS_PENDING:\n                    MLog.i(\"&gt;&gt;&gt;\u4e0b\u8f7d\u5ef6\u8fdf\");\n                case DownloadManager.STATUS_RUNNING:\n                    MLog.i(\"&gt;&gt;&gt;\u6b63\u5728\u4e0b\u8f7d\");\n                    break;\n                case DownloadManager.STATUS_SUCCESSFUL:\n                    MLog.i(\"&gt;&gt;&gt;\u4e0b\u8f7d\u5b8c\u6210\");\n                    \/\/\u4e0b\u8f7d\u5b8c\u6210\u5b89\u88c5APK\n                    \/\/downloadPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + File.separator + versionName;\n                    installAPK(new File(downloadPath));\n                    break;\n                case DownloadManager.STATUS_FAILED:\n                    MLog.i(\"&gt;&gt;&gt;\u4e0b\u8f7d\u5931\u8d25\");\n                    break;\n            }\n        }\n    }<\/code><\/pre>\n<h3 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\">4. \u5b89\u88c5 APK<\/h3>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">    \/\/\u4e0b\u8f7d\u5230\u672c\u5730\u540e\u6267\u884c\u5b89\u88c5\n    protected void installAPK(File file) {\n        if (!file.exists()) return;\n        Intent intent = new Intent(Intent.ACTION_VIEW);\n        Uri uri = Uri.parse(\"file:\/\/\" + file.toString());\n        intent.setDataAndType(uri, \"application\/vnd.android.package-archive\");\n        \/\/\u5728\u670d\u52a1\u4e2d\u5f00\u542factivity\u5fc5\u987b\u8bbe\u7f6eflag,\u540e\u9762\u89e3\u91ca\n        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);\n        mContext.startActivity(intent);\n    }<\/code><\/pre>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u56db\u3001\u5e0c\u671b\u4f60\u53ef\u4ee5\u770b\u5230\u6700\u540e\u8fd9\u51e0\u53e5\uff0c\u4e0d\u7136\u4f60\u4e5f\u4f1a\u88ab\u5751\u7684\uff01<\/span><\/h2>\n<ol style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: decimal;\">\n<li>\n<section>\u4e0b\u8f7d\u867d\u4e0d\u7528\u81ea\u5df1\u64cd\u5fc3\uff0c\u4ecd\u5efa\u8bae\u628a\u4e0a\u9762\u56db\u6bb5\u653e\u8fdb Service\u3002\u653e\u5728 Activity \u91cc\u65f6\uff0c\u7528\u6237\u6309 Home \u540e\u5373\u4f7f\u4e0b\u5b8c\u4e5f\u4e0d\u4f1a\u5f39\u51fa\u5b89\u88c5\u754c\u9762\u3002<\/section>\n<\/li>\n<li>\n<section>\u5efa\u8bae <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">startService<\/code> \u542f\u52a8 Service\uff0c\u4e0d\u8981\u8ddf Activity \u751f\u547d\u5468\u671f\u7ed1\u6b7b\uff0c\u4fdd\u8bc1\u4e0b\u5b8c\u80fd\u987a\u5229\u5b89\u88c5\u3002<\/section>\n<\/li>\n<li>\n<section>Service \u7528\u5b8c\u8981\u53ca\u65f6\u505c\u6389\u3002<\/section>\n<\/li>\n<\/ol>\n<p style=\"margin: 1em 0px;\">\u539f\u6587\u94fe\u63a5\uff1ahttp:\/\/www.jianshu.com\/p\/46fd1c253701<\/p>\n<blockquote style=\"margin: 20px 0px; display: block; font-size: 0.9em; overflow: auto; border-left: 3px solid #ef7060; color: #6a737d; padding: 10px 10px 10px 20px; background: #fff9f9;\">\n<p style=\"margin: 1em 0px;\"><strong>\u4e00\u53e5\u8bdd\u603b\u7ed3\uff1aDownloadManager \u56db\u884c\u5165\u961f\u5c31\u80fd\u4e0b\u6587\u4ef6\uff1b\u5e94\u7528\u5185\u66f4\u65b0\u518d\u52a0 MIME\u3001\u901a\u77e5\u680f\u3001\u5b8c\u6210\u5e7f\u64ad\u548c\u5b89\u88c5 Intent\uff0c\u6574\u6bb5\u653e\u8fdb startService \u624d\u7a33\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u5b8c\u6210\u4e00\u4e2a\u4e0b\u8f7d\u4efb\u52a1\u53ea\u9700\u8981 4 \u884c\u4ee3\u7801\u3002\u65ad\u70b9\u7eed\u4f20\u3001\u5927\u6587\u4ef6\u3001\u901a\u77e5\u680f\u8fdb\u5ea6\uff0c\u90fd\u53ef\u4ee5\u4ea4\u7ed9\u7cfb\u7edf DownloadManage [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3498,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[45],"tags":[202],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1635"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1635"}],"version-history":[{"count":3,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1635\/revisions"}],"predecessor-version":[{"id":3768,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1635\/revisions\/3768"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/media\/3498"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}