{"id":65134,"date":"2025-05-03T15:36:41","date_gmt":"2025-05-03T07:36:41","guid":{"rendered":"https:\/\/fwq.ai\/blog\/65134\/"},"modified":"2025-05-03T15:36:41","modified_gmt":"2025-05-03T07:36:41","slug":"%e5%ae%89%e5%8d%93%e6%89%8b%e6%9c%ba%e6%97%a0%e6%b3%95%e6%89%93%e5%bc%80-word-%e6%96%87%e4%bb%b6%e6%80%8e%e4%b9%88%e5%8a%9e%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/65134\/","title":{"rendered":"\u5b89\u5353\u624b\u673a\u65e0\u6cd5\u6253\u5f00 Word \u6587\u4ef6\u600e\u4e48\u529e\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173120330683576.jpg\" class=\"aligncenter\" title=\"\u5b89\u5353\u624b\u673a\u65e0\u6cd5\u6253\u5f00 Word \u6587\u4ef6\u600e\u4e48\u529e\uff1f\u63d2\u56fe\" alt=\"\u5b89\u5353\u624b\u673a\u65e0\u6cd5\u6253\u5f00 Word \u6587\u4ef6\u600e\u4e48\u529e\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5b89\u5353\u65e0\u6cd5\u6253\u5f00 word \u6587\u4ef6<\/strong><\/p>\n<p>\u5728 android \u5e94\u7528\u4e2d\uff0c\u6253\u5f00 word \u6587\u4ef6\u65f6\u7a0b\u5e8f\u81ea\u52a8\u5173\u95ed\uff0c\u53ef\u80fd\u662f\u7531\u4e8e\u4ee5\u4e0b\u539f\u56e0\uff1a<\/p>\n<p><strong>\u6587\u4ef6 uri \u6743\u9650\u95ee\u9898<\/strong><\/p>\n<p>\u786e\u4fdd\u5e94\u7528\u5177\u6709\u8bbf\u95ee\u5916\u90e8\u5b58\u50a8\u7684\u6743\u9650\u3002\u5728 android 6.0 \u53ca\u4ee5\u4e0a\u7248\u672c\u4e2d\uff0c\u9700\u5728\u8fd0\u884c\u65f6\u8bf7\u6c42\u6743\u9650\u3002\u5728 androidmanifest.xml \u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u6743\u9650\uff1a<\/p>\n<pre>&lt;uses-permission android:name=\"android.permission.read_external_storage\" \/&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u4ee3\u7801\u4e2d\u8bf7\u6c42\u6743\u9650\uff1a<\/p>\n<pre>if (contextcompat.checkselfpermission(this, manifest.permission.read_external_storage)\n        != packagemanager.permission_granted) {\n    activitycompat.requestpermissions(this, new string[]{manifest.permission.read_external_storage}, 1);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6784\u5efa\u6253\u5f00 word \u6587\u4ef6\u7684 intent<\/strong><\/p>\n<p>intent \u6784\u5efa\u4e0d\u89c4\u8303\u6216 mime \u7c7b\u578b\u4e0d\u6b63\u786e\u4f1a\u5bfc\u81f4\u7a0b\u5e8f\u5d29\u6e83\u3002\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u6784\u5efa\u7528\u4e8e\u6253\u5f00 word \u6587\u6863\u7684 intent\uff1a<\/p>\n<pre>public intent getwordfileintent(string filepath) {\n    file file = new file(filepath);\n    uri fileuri;\n\n    if (build.version.sdk_int &gt;= build.version_codes.n) {\n        \/\/ android 7.0 \u53ca\u4ee5\u4e0a\u4f7f\u7528 fileprovider\n        fileuri = fileprovider.geturiforfile(this, getpackagename() + \".fileprovider\", file);\n    } else {\n        fileuri = uri.fromfile(file);\n    }\n\n    intent intent = new intent(intent.action_view);\n    intent.setdataandtype(fileuri, \"application\/msword\");\n    intent.addflags(intent.flag_grant_read_uri_permission); \/\/ \u6388\u4e88 uri \u8bfb\u53d6\u6743\u9650\n    return intent;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 fileprovider\uff08android 7.0 \u53ca\u4ee5\u4e0a\uff09<\/strong><\/p>\n<p>\u5982\u679c\u76ee\u6807\u7248\u672c\u662f android 7.0 \u53ca\u4ee5\u4e0a\uff0c\u9700\u4f7f\u7528 fileprovider \u6765\u5b89\u5168\u5730\u5171\u4eab\u6587\u4ef6 uri\u3002\u5728 androidmanifest.xml \u4e2d\u6dfb\u52a0\uff1a<\/p>\n<pre>&lt;provider\n    android:name=\"androidx.core.content.fileprovider\"\n    android:authorities=\"${applicationid}.fileprovider\"\n    android:exported=\"false\"\n    android:granturipermissions=\"true\"&gt;\n    &lt;meta-data\n        android:name=\"android.support.file_provider_paths\"\n        android:resource=\"@xml\/file_paths\" \/&gt;\n&lt;\/provider&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u521b\u5efa res\/xml\/file_paths.xml \u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<pre>&lt;paths xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"&gt;\n    &lt;external-path name=\"external_files\" path=\".\" \/&gt;\n&lt;\/paths&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5904\u7406\u5f02\u5e38<\/strong><\/p>\n<p>\u5c06\u542f\u52a8\u6d3b\u52a8\u7684\u4ee3\u7801\u653e\u5165 try-catch \u8bed\u53e5\u4e2d\uff0c\u4ee5\u5904\u7406\u5f02\u5e38\uff1a<\/p>\n<pre>try {\n    Intent intent = getWordFileIntent(path);\n    startActivity(intent);\n} catch (ActivityNotFoundException e) {\n    Toast.makeText(this, \"\u627e\u4e0d\u5230\u53ef\u4ee5\u6253\u5f00\u6b64\u6587\u4ef6\u7684\u5e94\u7528\", Toast.LENGTH_LONG).show();\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8df3\u8f6c\u5230 looper<\/strong><\/p>\n<p>\u81f3\u4e8e\u8df3\u8f6c\u5230 looper\uff0c\u8fd9\u662f\u4e3b\u7ebf\u7a0b\u7684\u6d88\u606f\u961f\u5217\uff0c\u4e0d\u65ad\u5904\u7406\u6d88\u606f\u548c\u4efb\u52a1\u3002\u60a8\u7684\u8df3\u8f6c\u4efb\u52a1\u53ef\u80fd\u88ab\u653e\u5165\u961f\u5217\u4e2d\uff0c\u5bfc\u81f4\u8fdb\u5165 looper\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u65e0\u6cd5\u6253\u5f00 Word \u6587\u4ef6\u600e\u4e48\u529e\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8IDCBABY\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b89\u5353\u65e0\u6cd5\u6253\u5f00 word \u6587\u4ef6 \u5728 android \u5e94\u7528\u4e2d\uff0c\u6253\u5f00 word \u6587\u4ef6\u65f6\u7a0b\u5e8f\u81ea\u52a8\u5173\u95ed\uff0c\u53ef\u80fd\u662f\u7531\u4e8e\u4ee5\u4e0b\u539f\u56e0\uff1a \u6587\u4ef6 uri \u6743\u9650\u95ee\u9898 \u786e\u4fdd\u5e94\u7528\u5177\u6709\u8bbf\u95ee\u5916\u90e8\u5b58\u50a8\u7684\u6743\u9650\u3002\u5728 android 6.0 \u53ca\u4ee5\u4e0a\u7248\u672c\u4e2d\uff0c\u9700\u5728\u8fd0\u884c\u65f6\u8bf7\u6c42\u6743\u9650\u3002\u5728 androidmanifest.xml \u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u6743\u9650\uff1a &lt;uses-permission android:name=&#8221;android.permission.read_external_storage&#8221; \/&gt; \u767b\u5f55\u540e\u590d\u5236 \u5728\u4ee3\u7801\u4e2d\u8bf7\u6c42\u6743\u9650\uff1a if (contextcompat.checkselfpermission(this, manifest.permission.read_external_storage) != packagemanager.permission_granted) { activitycompat.requestpermissions(this, new string[]{manifest.permission.read_external_storage}, 1); } \u767b\u5f55\u540e\u590d\u5236 \u6784\u5efa\u6253\u5f00 word \u6587\u4ef6\u7684 intent intent \u6784\u5efa\u4e0d\u89c4\u8303\u6216 mime \u7c7b\u578b\u4e0d\u6b63\u786e\u4f1a\u5bfc\u81f4\u7a0b\u5e8f\u5d29\u6e83\u3002\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u6784\u5efa\u7528\u4e8e\u6253\u5f00 word \u6587\u6863\u7684 intent\uff1a public intent getwordfileintent(string filepath) { file file = new file(filepath); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-65134","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65134","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=65134"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65134\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=65134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=65134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=65134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}