{"id":20,"date":"2017-03-18T15:30:34","date_gmt":"2017-03-18T07:30:34","guid":{"rendered":"http:\/\/www.shounenwind.tw\/blog\/?p=20"},"modified":"2018-03-05T17:45:25","modified_gmt":"2018-03-05T09:45:25","slug":"runtime-permissions","status":"publish","type":"post","link":"https:\/\/shounenwind.tw\/blog\/programming\/android\/runtime-permissions\/","title":{"rendered":"Runtime Permissions"},"content":{"rendered":"<p>\u5728 Android 6.0 \u88e1\uff0c\u65b0\u589e\u4e86\u4e00\u500b\u6771\u897f\uff0c\u57fa\u672c\u4e0a\u5c31\u662f\u5728\u4f7f\u7528\u8005\u9700\u8981\u7684\u6642\u5019\u518d\u554f\u4f7f\u7528\u8005\u8981\u4e0d\u8981\u63d0\u4f9b\u6b0a\u9650\u3002<\/p>\n<p><a href=\"https:\/\/developer.android.com\/training\/permissions\/requesting.html\">\u5b98\u65b9\u63d0\u4f9b\u7684\u6559\u5b78\u88e1<\/a>\uff0c\u9664\u4e86\u8981\u5728 <span class=\"pl-s\">AndroidManifest.xml<\/span> \u5b9a\u7fa9\u4f60\u9700\u8981\u7684\u6b0a\u9650\u4ee5\u5916\uff0c\u4f60\u9700\u8981\u547c\u53eb checkSelfPermission \u4f86\u78ba\u5b9a\u6b0a\u9650\u662f\u4e0d\u662f\u6709\u958b\u653e\uff0c\u82e5\u6c92\u6709\uff0c\u4f7f\u7528 requestPermissions\uff0c\u544a\u8a34\u7cfb\u7d71\u4f60\u9700\u8981\u8981\u6c42\u7684\u6b0a\u9650\uff0c\u63a5\u8457 Override onRequestPermissionsResult\uff0c\u8655\u7406\u4f7f\u7528\u8005\u5141\u8a31\u6216\u62d2\u7d55\u7d66\u4e88\u6b0a\u9650\u4e4b\u5f8c\u7684\u52d5\u4f5c\u3002<\/p>\n<p>\u7136\u800c\u6211\u5f8c\u4f86\u5be6\u5728\u5f88\u61f6\uff0c\u6240\u4ee5\u5beb\u4e86\u4e00\u500b <a href=\"https:\/\/gist.github.com\/michaeimm\/d9d0538e53dd6434b54488a9a7b3a762\">class<\/a> \u7e7c\u627f <span class=\"pl-e\">AppCompatActivity\uff0c\u4e3b\u8981\u5e6b\u6211\u7522\u751f\u4e00\u500b requestCode\uff0c\u518d\u8b93 callback \u8ddf\u8acb\u6c42\u6b0a\u9650\u5beb\u5728\u540c\u6a23\u7684\u5730\u65b9\u3002\u7562\u7adf\u6211\u5f88\u8a0e\u53ad\u6372\u4f86\u6372\u53bb\u7684\u3002<\/span><\/p>\n<p>Edit\uff1a\u5f8c\u4f86\u7684\u5f8c\u4f86\uff0c\u53c8\u5beb\u4e86\u4e00\u500b <span class=\"pl-en\"><a href=\"https:\/\/gist.github.com\/michaeimm\/13aebc2a42f8870b4983dbf7ff3de177\">RequestPermissionsUtil<\/a> \u53d6\u4ee3\u4e4b\u524d\u7684 class\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Android 6.0 \u88e1\uff0c\u65b0\u589e\u4e86\u4e00\u500b\u6771\u897f\uff0c\u57fa\u672c\u4e0a\u5c31\u662f\u5728\u4f7f\u7528\u8005\u9700\u8981\u7684\u6642\u5019\u518d\u554f\u4f7f\u7528\u8005\u8981\u4e0d\u8981\u63d0\u4f9b\u6b0a\u9650\u3002 \u5b98\u65b9\u63d0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-20","post","type-post","status-publish","format-standard","hentry","category-android"],"_links":{"self":[{"href":"https:\/\/shounenwind.tw\/blog\/wp-json\/wp\/v2\/posts\/20","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/shounenwind.tw\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shounenwind.tw\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shounenwind.tw\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shounenwind.tw\/blog\/wp-json\/wp\/v2\/comments?post=20"}],"version-history":[{"count":4,"href":"https:\/\/shounenwind.tw\/blog\/wp-json\/wp\/v2\/posts\/20\/revisions"}],"predecessor-version":[{"id":75,"href":"https:\/\/shounenwind.tw\/blog\/wp-json\/wp\/v2\/posts\/20\/revisions\/75"}],"wp:attachment":[{"href":"https:\/\/shounenwind.tw\/blog\/wp-json\/wp\/v2\/media?parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shounenwind.tw\/blog\/wp-json\/wp\/v2\/categories?post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shounenwind.tw\/blog\/wp-json\/wp\/v2\/tags?post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}