{"id":12689,"date":"2022-11-24T15:16:20","date_gmt":"2022-11-24T07:16:20","guid":{"rendered":"https:\/\/www.yimenapp.com\/kb-yimen\/?p=12689"},"modified":"2022-11-24T15:16:21","modified_gmt":"2022-11-24T07:16:21","slug":"%e5%b0%8f%e7%b1%b3%e5%bc%80%e5%8f%91%e5%b9%b3%e5%8f%b0-%e5%8f%8c%e5%bc%80%e5%ba%94%e7%94%a8%e4%bf%ae%e6%94%b9%e5%a4%b4%e5%83%8f%e5%a4%b1%e8%b4%a5%e7%ad%89%e5%9c%ba%e6%99%af%e9%80%82%e9%85%8d%e8%af%b4","status":"publish","type":"post","link":"https:\/\/www.yimenapp.com\/kb-yimen\/12689\/","title":{"rendered":"\u5c0f\u7c73\u5f00\u53d1\u5e73\u53f0 \u53cc\u5f00\u5e94\u7528\u4fee\u6539\u5934\u50cf\u5931\u8d25\u7b49\u573a\u666f\u9002\u914d\u8bf4\u660e"},"content":{"rendered":"\n<p>\u5c0f\u7c73\u5f00\u53d1\u5e73\u53f0 \u53cc\u5f00\u5e94\u7528\u4fee\u6539\u5934\u50cf\u5931\u8d25\u7b49\u573a\u666f\u9002\u914d\u8bf4\u660e<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_0\">\u80cc\u666f<\/h2>\n\n\n\n<p>\u5728<span class=\"wpcom_tag_link\"><a href=\"https:\/\/www.yimenapp.com\/kb-yimen\/tag\/android-11\/\" title=\"Android 11\" target=\"_blank\">Android 11<\/a><\/span>\u53ca\u4ee5\u4e0a\u7248\u672c\uff0c\u5f53<span class=\"wpcom_tag_link\"><a href=\"https:\/\/www.yimenapp.com\/kb-yimen\/tag\/%e5%ba%94%e7%94%a8%e5%8f%8c%e5%bc%80\/\" title=\"\u5e94\u7528\u53cc\u5f00\" target=\"_blank\">\u5e94\u7528\u53cc\u5f00<\/a><\/span>\u540e\uff0c\u53cc\u5f00\u5e94\u7528\u4e2d\u542f\u52a8\u7cfb\u7edf\u526a\u88c1\u9875\u9762\uff0c\u5b9e\u73b0\u4fee\u6539\u5934\u50cf\u7b49\u573a\u666f\u65f6\uff0c\u4f1a\u51fa\u73b0\u526a\u88c1\u4fdd\u5b58\u56fe\u7247\u5931\u8d25\u95ee\u9898\u3002\u6b64\u573a\u666f\u9700\u8981\u5e94\u7528\u9002\u914d\u53cc\u5f00\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_1\">\u5e94\u7528\u53cc\u5f00\u529f\u80fd<\/h2>\n\n\n\n<p>\u624b\u673a\u8bbe\u7f6e-\u5e94\u7528\u8bbe\u7f6e-\u5e94\u7528\u53cc\u5f00<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_2\">\u9002\u914d\u8bf4\u660e<\/h2>\n\n\n\n<p>\u5728\u5e94\u7528\u542f\u52a8\u526a\u88c1\u9875\u9762\u65f6\uff0cintent\u4e2d\u653e\u5165\u7684\u8f93\u51fa\u8def\u5f84\u7684uri\u9700\u8981\u5e26\u4e0auserId\uff0c\u5177\u4f53\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>\/**\n* \u53cd\u5c04\u83b7\u53d6getCallingUserId\n*\/<\/em>\n<strong>private<\/strong> <strong>int<\/strong> <strong>getCallingUserId<\/strong>(){\n        Class UserHandleClass = UserHandle.class;\n        <strong>int<\/strong> userId = 0;\n        <strong>try<\/strong> {\n            userId = (<strong>int<\/strong>)UserHandleClass.getMethod(\"getCallingUserId\").invoke(UserHandleClass);\n        } <strong>catch<\/strong> (IllegalAccessException e) {\n            e.printStackTrace();\n        } <strong>catch<\/strong> (InvocationTargetException e) {\n            e.printStackTrace();\n        } <strong>catch<\/strong> (NoSuchMethodException e){\n            e.printStackTrace();\n        }\n            <strong>return<\/strong> userId;\n    }<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><em>\/**\n* @param uri: \u9700\u8981\u526a\u88c1uri\uff0c\u5982\u56fe\u5e93\u7b49\u8fd4\u56de\u7684uri\n* \u62c9\u8d77\u7cfb\u7edf\u526a\u88c1\u9875\u9762\n*\/<\/em>\n<strong>private<\/strong> <strong>void<\/strong> <strong>cropImage<\/strong>(Uri uri) {\n        <strong>if<\/strong>(uri == <strong>null<\/strong>) {\n           <strong>return<\/strong>;\n        }\n        Intent intent = <strong>new<\/strong> Intent(\"com.android.camera.action.CROP\");\n        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);\n        intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);\n        intent.putExtra(\"scale\", <strong>true<\/strong>);\n        intent.putExtra(\"aspectX\", XXX);\n        intent.putExtra(\"aspectY\", XXX);\n        intent.putExtra(\"outputX\", XXX);\n        intent.putExtra(\"outputY\", XXX);\n        intent.putExtra(\"outputFormat\", XXX);\n        intent.putExtra(\"return-data\", XXX);\n        File tmpFile = <strong>new<\/strong> File(getExternalFilesDir(<strong>null<\/strong>), System.currentTimeMillis()+\".jpg\");\n        <strong>try<\/strong> {\n            tmpFile.createNewFile();\n        } <strong>catch<\/strong> (IOException e) {\n            e.printStackTrace();\n        }\n        Uri mCutUri = FileProvider.getUriForFile(MainActivity.<strong>this<\/strong>,\n                \"com.xxx.fileprovider\", tmpFile);\n        <em>\/\/\u751f\u6210\u5e26userId\u7684uri<\/em>\n        Uri.Builder builder = mCutUri.buildUpon();\n        Uri newUri = builder.encodedAuthority(\"\" + getCallingUserId() + \"@\" + mCutUri.getEncodedAuthority()).build();\n \n        intent.putExtra(MediaStore.EXTRA_OUTPUT, newUri);\n        <em>\/\/\u8c03\u7528grantUriPermission\u7ed9newUri\u6388\u6743<\/em>\n        grantUriPermission(\"packaName\", newUri,  Intent.FLAG_GRANT_READ_URI_PERMISSION|Intent.FLAG_GRANT_WRITE_URI_PERMISSION);\n        intent.setDataAndType(uri, \"image\/*\");\n        startActivityForResult(intent, REQUEST_CROP);\n  \n    }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728Android 11\u53ca\u4ee5\u4e0a\u7248\u672c\uff0c\u5f53\u5e94\u7528\u53cc\u5f00\u540e\uff0c\u53cc\u5f00\u5e94\u7528\u4e2d\u542f\u52a8\u7cfb\u7edf\u526a\u88c1\u9875\u9762\uff0c\u5b9e\u73b0\u4fee\u6539\u5934\u50cf\u7b49\u573a\u666f\u65f6\uff0c\u4f1a\u51fa\u73b0\u526a\u88c1\u4fdd\u5b58\u56fe\u7247\u5931\u8d25\u95ee\u9898\u3002\u6b64\u573a\u666f\u9700\u8981\u5e94\u7528\u9002\u914d\u53cc\u5f00\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46,94,160],"tags":[3384,5933,5932,5931,5934,5935,5930],"special":[67],"attr":[],"class_list":{"0":"post-12689","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-appsj","7":"category-appjc","8":"category-appcs","9":"tag-android-11","10":"tag-app","12":"tag-5931","15":"tag-5930","16":"special-xiaomikfpt","17":"entry"},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/posts\/12689","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/comments?post=12689"}],"version-history":[{"count":1,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/posts\/12689\/revisions"}],"predecessor-version":[{"id":12690,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/posts\/12689\/revisions\/12690"}],"wp:attachment":[{"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/media?parent=12689"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/categories?post=12689"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/tags?post=12689"},{"taxonomy":"special","embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/special?post=12689"},{"taxonomy":"attr","embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/attr?post=12689"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}