{"id":1241,"date":"2023-03-18T09:33:04","date_gmt":"2023-03-18T01:33:04","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1241"},"modified":"2023-04-29T09:31:34","modified_gmt":"2023-04-29T01:31:34","slug":"precautions-for-installing-apk-using-fileprovider-on-android-7-and-above","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/18\/precautions-for-installing-apk-using-fileprovider-on-android-7-and-above\/","title":{"rendered":"Android 7.0\u53ca\u4ee5\u4e0a\u5229\u7528FileProvider\u5b89\u88c5apk\u6ce8\u610f\u4e8b\u9879"},"content":{"rendered":"<p>Android 7.0\u53ca\u4ee5\u4e0a\u5229\u7528FileProvider\u5b89\u88c5apk\u4e00\u5b9a\u8981\u58f0\u660e\u6743\u9650\uff0c\u907f\u514d\u5f53\u6210\u672a\u77e5\u5e94\u7528\u88ab\u963b\u6b62\u5b89\u88c5<\/p>\n<h3>\u5229\u7528FileProvider\u5b89\u88c5apk<\/h3>\n<p><!-- more --><\/p>\n<pre><code class=\"language-java\">\/**\n * \u901a\u8fc7\u9690\u5f0f\u610f\u56fe\u8c03\u7528\u7cfb\u7edf\u5b89\u88c5\u7a0b\u5e8f\u5b89\u88c5apk\n *\/\nIntent intent = new Intent(Intent.ACTION_VIEW);\n\/\/\u7531\u4e8e\u6ca1\u6709\u5728Activity\u73af\u5883\u4e0b\u542f\u52a8Activity\uff0c\u8bbe\u7f6e\u4e0b\u9762\u7684\u6807\u7b7e\nintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);\nif (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.N) {\n    intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);\n    Uri fileUri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + &quot;.fileProvider&quot;, appFile);\n    intent.setDataAndType(fileUri, &quot;application\/vnd.android.package-archive&quot;);\n} else {\n    intent.setDataAndType(Uri.fromFile(appFile), &quot;application\/vnd.android.package-archive&quot;);\n}\ncontext.startActivity(intent);<\/code><\/pre>\n<h3>\u58f0\u660e\u6743\u9650\uff0c\u907f\u514d\u88ab\u5f53\u6210\u672a\u77e5\u5e94\u7528\u88ab\u963b\u6b62\u5b89\u88c5<\/h3>\n<pre><code class=\"language-xml\">&lt;uses-permission android:name=&quot;android.permission.REQUEST_INSTALL_PACKAGES&quot; \/&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Android 7.0\u53ca\u4ee5\u4e0a\u5229\u7528FileProvider\u5b89\u88c5apk\u4e00\u5b9a\u8981\u58f0\u660e\u6743\u9650\uff0c\u907f\u514d\u5f53\u6210\u672a\u77e5\u5e94\u7528\u88ab\u963b\u6b62\u5b89\u88c5  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[210,312],"class_list":["post-1241","post","type-post","status-publish","format-standard","hentry","category-android-basic","tag-apk","tag-fileprovider"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1241","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1241"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1241\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}