{"id":1100,"date":"2021-01-27T17:51:22","date_gmt":"2021-01-27T09:51:22","guid":{"rendered":"https:\/\/badgameshow.com\/fly\/?p=1100"},"modified":"2021-01-27T18:02:42","modified_gmt":"2021-01-27T10:02:42","slug":"storage-access-frameworksaf-%e5%8f%96%e5%be%97%e6%89%8b%e6%a9%9f%e8%88%87%e9%9b%b2%e7%ab%afpdf%e6%aa%94","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/fly\/storage-access-frameworksaf-%e5%8f%96%e5%be%97%e6%89%8b%e6%a9%9f%e8%88%87%e9%9b%b2%e7%ab%afpdf%e6%aa%94\/","title":{"rendered":"Storage Access Framework(SAF) \u53d6\u5f97\u624b\u6a5f\u8207\u96f2\u7aefPDF\u6a94"},"content":{"rendered":"<h1>Storage Access Framework(SAF) \u53d6\u5f97\u624b\u6a5f\u8207\u96f2\u7aefPDF\u6a94<\/h1>\n<ul>\n<li>\u6587\u7ae0\u76ee\u9304<br \/>\n<\/p>\n<ul>\n<li><a href=\"https:\/\/badgameshow.com\/fly\/storage-access-frameworksaf-\u53d6\u5f97\u624b\u6a5f\u8207\u96f2\u7aefpdf\u6a94\/fly\/android\/#a\">\u8a2d\u7f6eIntent \u6307\u5b9a\u9078\u53d6PDF<\/a><br \/>\n<\/li>\n<li><a href=\"https:\/\/badgameshow.com\/fly\/storage-access-frameworksaf-\u53d6\u5f97\u624b\u6a5f\u8207\u96f2\u7aefpdf\u6a94\/fly\/android\/#b\">\u53d6\u5f97\u56de\u50b3\u7684\u6a94\u6848<\/a><br \/>\n<\/li>\n<li><a href=\"https:\/\/badgameshow.com\/fly\/storage-access-frameworksaf-\u53d6\u5f97\u624b\u6a5f\u8207\u96f2\u7aefpdf\u6a94\/fly\/android\/#c\">\u6548\u679c\u5c55\u793a<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2><\/h2>\n<p><a id=\"a\"><\/a><\/p>\n<h3>1.\u8a2d\u7f6eIntent \u6307\u5b9a\u9078\u53d6PDF<\/h3>\n<pre><code class=\"language-Kotlin line-numbers\">val PICK_PDF_REQUEST = 40\nlateinit var binding: ActivityMainBinding\n\noverride fun onCreate(savedInstanceState: Bundle?) {\n    super.onCreate(savedInstanceState)\n    binding = ActivityMainBinding.inflate(layoutInflater)\n    setContentView(binding.root)\n\n    binding.getData.setOnClickListener {\n        val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)\n        intent.type = \"application\/pdf\"\n        startActivityForResult(intent, PICK_PDF_REQUEST)\n    }\n}\n<\/code><\/pre>\n<p><a id=\"b\"><\/a><\/p>\n<h3>2.\u53d6\u5f97\u56de\u50b3\u7684\u6a94\u6848<\/h3>\n<pre><code class=\"language-Kotlin line-numbers\">override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {\n    super.onActivityResult(requestCode, resultCode, data)\n    if (requestCode == PICK_PDF_REQUEST &amp;&amp; resultCode == Activity.RESULT_OK) {\n\n        var file: File? = null\n\n        data?.data?.also { uri -&gt;\n            val cursor: Cursor? = contentResolver.query(uri, null, null, null, null)\n            cursor?.run {\n                if (moveToFirst()) {\n                    val displayName: String =\n                        getString(getColumnIndex(OpenableColumns.DISPLAY_NAME))\n                    try {\n                        val `is`: InputStream? = contentResolver.openInputStream(uri)\n                        val cache = File(externalCacheDir!!.absolutePath, displayName)\n                        val fos = FileOutputStream(cache)\n                        fos.write(`is`?.readBytes())\n                        file = cache\n                        fos.close()\n                        `is`?.close()\n                    } catch (e: IOException) {\n                        e.printStackTrace()\n                    }\n                }\n                close()\n            }\n        }\n\n        binding.name.text = file?.name\n        binding.path.text = file?.path\n    }\n}\n<\/code><\/pre>\n<p><a id=\"c\"><\/a><\/p>\n<h3>3.\u6548\u679c\u5c55\u793a<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/badgameshow.com\/fly\/wp-content\/uploads\/2021\/01\/20210127_172553.gif\" style=\"width:80%; max-width:250px\"><\/p>\n\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>Storage Access Framework(SAF) \u53d6\u5f97\u624b\u6a5f\u8207\u96f2\u7aefPDF\u6a94 \u6587\u7ae0\u76ee\u9304 \u8a2d\u7f6eIntent &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,15,168],"class_list":["post-1100","post","type-post","status-publish","format-standard","hentry","category-android","tag-android","tag-kotlin","tag-saf"],"_links":{"self":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/1100","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=1100"}],"version-history":[{"count":7,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/1100\/revisions"}],"predecessor-version":[{"id":1109,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/1100\/revisions\/1109"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/media?parent=1100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/categories?post=1100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/tags?post=1100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}