{"id":285,"date":"2020-03-25T10:57:12","date_gmt":"2020-03-25T02:57:12","guid":{"rendered":"https:\/\/badgameshow.com\/fly\/?p=285"},"modified":"2021-02-17T16:01:22","modified_gmt":"2021-02-17T08:01:22","slug":"android-fileprovider%e5%9c%a8%e6%87%89%e7%94%a8%e5%85%b1%e4%ba%ab%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/fly\/android-fileprovider%e5%9c%a8%e6%87%89%e7%94%a8%e5%85%b1%e4%ba%ab%e6%96%87%e4%bb%b6\/","title":{"rendered":"Android FileProvider \u914d\u7f6e\u4f7f\u7528"},"content":{"rendered":"<h4>1.\u8a3b\u518aFileProvider(AndroidManifest.xml)<\/h4>\n<pre><code class=\"language-XML line-numbers\">&lt;provider\n    android:name=\"androidx.core.content.FileProvider\"\n    android:authorities=\"${applicationId}.provider\"\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\/provider_paths\" \/&gt;\n&lt;\/provider&gt;\n<\/code><\/pre>\n<h4>2.\u5275\u5efaresource xml file(provider_paths)<\/h4>\n<pre><code class=\"language-XML line-numbers\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;paths xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"&gt;\n    &lt;root-path name=\"myImage\" path=\".\" \/&gt;\n    &lt;files-path name=\"myImage\" path=\".\" \/&gt;\n    &lt;cache-path name=\"myImage\" path=\".\" \/&gt;\n    &lt;external-path name=\"myImage\" path=\".\" \/&gt;\n    &lt;external-files-path name=\"myImage\" path=\".\" \/&gt;\n    &lt;external-cache-path name=\"myImage\" path=\".\" \/&gt;\n&lt;\/paths&gt;\n<\/code><\/pre>\n<pre><code class=\"line-numbers\">&lt;root-path\/&gt;           =&gt; \u8a2d\u5099\u7684\u6839\u76ee\u9304new File(\"\/\");\n&lt;files-path\/&gt;          =&gt; context.getFilesDir()\n&lt;cache-path\/&gt;          =&gt; context.getCacheDir()\n&lt;external-path\/&gt;       =&gt; Environment.getExternalStorageDirectory()\n&lt;external-files-path&gt;  =&gt; context.getExternalFilesDirs()\n&lt;external-cache-path&gt;  =&gt; getExternalCacheDirs()\n<\/code><\/pre>\n<h4>3.\u7a0b\u5f0f\u78bc<\/h4>\n<pre><code class=\"language-Java line-numbers\">val outputFile = File(getFilesDir(), \"myImage\")\nval intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)\nval imgUri = FileProvider.getUriForFile(applicationContext, BuildConfig.APPLICATION_ID + \".provider\", outputFile)\nintent.putExtra(MediaStore.EXTRA_OUTPUT, imgUri)\nstartActivityForResult(intent, TAKE_PHOTO_REQUEST_CODE)\n<\/code><\/pre>\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.\u8a3b\u518aFileProvider(AndroidManifest.xml) &lt;provider andr &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,20,15],"class_list":["post-285","post","type-post","status-publish","format-standard","hentry","category-android","tag-android","tag-fileprovider","tag-kotlin"],"_links":{"self":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/285","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=285"}],"version-history":[{"count":10,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/285\/revisions"}],"predecessor-version":[{"id":1145,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/285\/revisions\/1145"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/media?parent=285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/categories?post=285"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/tags?post=285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}