{"id":1902,"date":"2022-11-25T18:00:42","date_gmt":"2022-11-25T10:00:42","guid":{"rendered":"https:\/\/app.applebyme.cn\/cloud\/appshangjia\/1902.html"},"modified":"2022-11-25T18:00:42","modified_gmt":"2022-11-25T10:00:42","slug":"android-12-%e5%ba%94%e7%94%a8%e9%80%82%e9%85%8d%e6%8c%87%e5%8d%972-%e6%96%b0%e5%8a%9f%e8%83%bd%e5%92%8capi","status":"publish","type":"post","link":"https:\/\/app.applebyme.cn\/cloud\/appshangjia\/1902.html","title":{"rendered":"Android 12 \u5e94\u7528\u9002\u914d\u6307\u53572 \u65b0\u529f\u80fd\u548cAPI"},"content":{"rendered":"<p><span class=\"wpcom_tag_link\">Android 12<\/span> \u5e94\u7528\u9002\u914d\u6307\u53572 \u65b0\u529f\u80fd\u548cAPI<\/p>\n<h2 id=\"_3\">\u65b0\u529f\u80fd\u548cAPI<\/h2>\n<h3 id=\"_3_0\">3.1 \u7528\u4e8e\u63a5\u6536\u5185\u5bb9\u7684\u7edf\u4e00API<\/h3>\n<p>\u5f53\u524d\uff0c\u7528\u6237\u66f4\u559c\u6b22\u56fe\u7247\u3001\u89c6\u9891\u7b49\u5bcc\u6709\u8868\u73b0\u529b\u7684\u5185\u5bb9\uff0c\u4f46\u5728\u5e94\u7528\u4e2d\u63d2\u5165\u548c\u79fb\u52a8\u5e76\u975e\u6613\u4e8b\u3002\u4e3a\u4e86\u4f7f\u5e94\u7528\u80fd\u591f\u8f7b\u677e\u5730\u63a5\u6536\u5bcc\u5a92\u4f53\u5185\u5bb9\uff0cAndroid 12 \u5f15\u5165\u4e86\u5168\u65b0\u7684\u7edf\u4e00 API\uff0c\u60a8\u53ef\u4ee5\u4ece\u4efb\u4f55\u53ef\u7528\u6765\u6e90\uff08\u526a\u8d34\u677f\u7c98\u8d34\u3001\u952e\u76d8\u6216\u62d6\u653e\u64cd\u4f5c\uff09\u63a5\u6536\u5bcc\u5a92\u4f53\u5185\u5bb9\u3002<\/p>\n<h4>3.1.1 \u63a5\u6536\u5185\u5bb9\u7684API<\/h4>\n<p>\u4ee5\u524d\u6bcf\u4e2a\u754c\u9762\u673a\u5236\uff08\u4f8b\u5982\u957f\u6309\u83dc\u5355\u6216\u62d6\u653e\uff09\u90fd\u6709\u5bf9\u5e94\u7684 API\u3002\u8fd9\u610f\u5473\u7740\u60a8\u5fc5\u987b\u5355\u72ec\u4e0e\u6bcf\u4e2a API \u96c6\u6210\uff0c\u5e76\u4e3a\u6bcf\u79cd\u63d2\u5165\u5185\u5bb9\u7684\u673a\u5236\u6dfb\u52a0\u7c7b\u4f3c\u7684\u4ee3\u7801\uff1a<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/kb.cdn.yimenapp.com\/yimen\/2022\/11\/20221124154403871.png\" alt=\"Android 12 \u5e94\u7528\u9002\u914d\u6307\u53572 \u65b0\u529f\u80fd\u548cAPI\" \/><img decoding=\"async\" class=\"j-lazy\" src=\"https:\/\/www.yimenapp.com\/kb-yimen\/wp-content\/themes\/justnews\/themer\/assets\/images\/lazy.png\" data-original=\"https:\/\/kb.cdn.yimenapp.com\/yimen\/2022\/11\/20221124154403871.png\" alt=\"Android 12 \u5e94\u7528\u9002\u914d\u6307\u53572 \u65b0\u529f\u80fd\u548cAPI\" \/><\/figure>\n<p>\u73b0\u5728\u65b0\u7684\u7edf\u4e00 API \u4f1a\u901a\u8fc7\u521b\u5efa\u4e00\u4e2a\u8981\u5b9e\u73b0\u7684\u5355\u4e00 API \u6765\u6574\u5408\u8fd9\u4e9b\u4e0d\u540c\u7684\u4ee3\u7801\u8def\u5f84\uff0c\u8fd9\u6837\u60a8\u5c31\u53ef\u4ee5\u4e13\u6ce8\u4e8e\u5e94\u7528\u7279\u5b9a\u7684\u903b\u8f91\uff0c\u800c\u8ba9\u7cfb\u7edf\u5904\u7406\u5176\u4f59\u7684\u5de5\u4f5c\uff1a<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/kb.cdn.yimenapp.com\/yimen\/2022\/11\/20221124154404332.png\" alt=\"Android 12 \u5e94\u7528\u9002\u914d\u6307\u53572 \u65b0\u529f\u80fd\u548cAPI\" \/><img decoding=\"async\" class=\"j-lazy\" src=\"https:\/\/www.yimenapp.com\/kb-yimen\/wp-content\/themes\/justnews\/themer\/assets\/images\/lazy.png\" data-original=\"https:\/\/kb.cdn.yimenapp.com\/yimen\/2022\/11\/20221124154404332.png\" alt=\"Android 12 \u5e94\u7528\u9002\u914d\u6307\u53572 \u65b0\u529f\u80fd\u548cAPI\" \/><\/figure>\n<p>\u65b0 API \u662f\u4e00\u4e2a\u76d1\u542c\u5668\u63a5\u53e3\uff0c\u5305\u542b\u4e00\u79cd\u65b9\u6cd5\uff0c\u5373 \u200bOnReceiveContentListener\u200b\u3002\u6b64\u56de\u8c03\u4f1a\u6210\u4e3a\u60a8\u7684\u4ee3\u7801\u5904\u7406\u63a5\u6536\u6240\u6709\u5185\u5bb9\uff08\u4ece\u7eaf\u6587\u672c\u548c\u6837\u5f0f\u6587\u672c\u5230\u6807\u8bb0\u3001\u56fe\u7247\u3001\u89c6\u9891\u3001\u97f3\u9891\u6587\u4ef6\u7b49\uff09\u7684\u552f\u4e00\u4f4d\u7f6e\u3002\u4e3a\u4e86\u517c\u5bb9\u8f83\u4f4e\u7248\u672c\u7684 Android \u5e73\u53f0\uff0c\u6211\u4eec\u5efa\u8bae\u60a8\u4f7f\u7528 AndroidX\uff0c\u53ef\u5728&nbsp;Core 1.5.0-beta1&nbsp;\u548c&nbsp;Appcompat 1.3.0-beta-01&nbsp;\u4e2d\u83b7\u5f97\u8be5API\u3002<\/p>\n<h4>3.1.2 \u5b9e\u73b0\u4ee3\u7801<\/h4>\n<p>\u5982\u9700\u4f7f\u7528\u8be5 API\uff0c\u8bf7\u5148\u6307\u5b9a\u60a8\u7684\u5e94\u7528\u53ef\u4ee5\u5904\u7406\u54ea\u4e9b\u7c7b\u578b\u7684\u5185\u5bb9\uff0c\u4ee5\u5f00\u59cb\u5b9e\u73b0\u8be5\u76d1\u542c\u5668\uff1a<\/p>\n<pre class=\"wp-block-code\"><code><strong>public<\/strong> <strong>class<\/strong> <strong>MyReceiver<\/strong> <strong>implements<\/strong> <strong>OnReceiveContentListener<\/strong> {\n     <strong>public<\/strong> <strong>static<\/strong> <strong>final<\/strong> String&#091;] MIME_TYPES = <strong>new<\/strong> String&#091;] \n     {\"image\/*\", \"video\/*\"};\n     <em>\/\/ ...<\/em>\n<\/code><\/pre>\n<p>\u6307\u5b9a\u60a8\u7684\u5e94\u7528\u652f\u6301\u7684\u6240\u6709\u5185\u5bb9 MIME \u7c7b\u578b\u540e\uff0c\u5b9e\u73b0\u8be5\u76d1\u542c\u5668\u7684\u5176\u4f59\u90e8\u5206\uff1a<\/p>\n<pre class=\"wp-block-code\"><code><strong>public<\/strong> <strong>class<\/strong> <strong>MyReceiver<\/strong> <strong>implements<\/strong> <strong>OnReceiveContentListener<\/strong> {\n     <strong>public<\/strong> <strong>static<\/strong> <strong>final<\/strong> String&#091;] MIME_TYPES = <strong>new<\/strong> String&#091;] {\"image\/*\", \"video\/*\"};\n\n     @Override\n     <strong>public<\/strong> ContentInfoCompat <strong>onReceiveContent<\/strong>(View view, ContentInfoCompat contentInfo) {\n         Pair&lt;ContentInfoCompat, ContentInfoCompat&gt; split = contentInfo.partition(\n                 item -&gt; item.getUri() != <strong>null<\/strong>);\n         ContentInfo uriContent = split.first;\n         ContentInfo remaining = split.second;\n         <strong>if<\/strong> (uriContent != <strong>null<\/strong>) {\n             ClipData clip = uriContent.getClip();\n             <strong>for<\/strong> (<strong>int<\/strong> i = 0; i &lt; clip.getItemCount(); i++) {\n                 Uri uri = clip.getItemAt(i).getUri();\n                 <em>\/\/ App-specific logic to handle the URI ...<\/em>\n             }\n         }\n         <em>\/\/ Return anything that your app didn't handle. This preserves the default platform<\/em>\n         <em>\/\/ behavior for text and anything else that you aren't implementing custom handling for.<\/em>\n         <strong>return<\/strong> remaining;\n     }\n }<\/code><\/pre>\n<h4>3.1.3 \u5b9e\u73b0\u6548\u679c<\/h4>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/kb.cdn.yimenapp.com\/yimen\/2022\/11\/20221124154404240.gif\" alt=\"Android 12 \u5e94\u7528\u9002\u914d\u6307\u53572 \u65b0\u529f\u80fd\u548cAPI\" \/><img decoding=\"async\" class=\"j-lazy\" src=\"https:\/\/www.yimenapp.com\/kb-yimen\/wp-content\/themes\/justnews\/themer\/assets\/images\/lazy.png\" data-original=\"https:\/\/kb.cdn.yimenapp.com\/yimen\/2022\/11\/20221124154404240.gif\" alt=\"Android 12 \u5e94\u7528\u9002\u914d\u6307\u53572 \u65b0\u529f\u80fd\u548cAPI\" \/><\/figure>\n<h3 id=\"_3_1\">3.2 \u517c\u5bb9\u7684\u5a92\u4f53\u8f6c\u7801<\/h3>\n<p>Android 12 \u5f15\u5165\u4e86\u4e00\u9879\u65b0\u529f\u80fd\uff0c\u8ba9\u5f55\u5236\u89c6\u9891\u7684\u5e94\u7528\u53ef\u4ee5\u5bf9\u8bbe\u5907\u4e0a\u5f55\u5236\u7684\u89c6\u9891\u8fdb\u884c\u66f4\u73b0\u4ee3\u3001\u5b58\u50a8\u6548\u7387\u66f4\u9ad8\u7684\u7f16\u7801\uff0c\u540c\u65f6\u53c8\u4e0d\u5f71\u54cd\u4e0e\u5176\u4ed6\u5e94\u7528\u7684\u517c\u5bb9\u6027\u3002\u5982\u679c\u89c6\u9891\u88ab\u4e0d\u652f\u6301 HEVC \u683c\u5f0f\u7684\u5e94\u7528\u6253\u5f00\uff0cAndroid \u4f1a\u81ea\u52a8\u5c06\u4ee5 HEVC (H.265) \u7b49\u683c\u5f0f\u5f55\u5236\u7684\u89c6\u9891\u8f6c\u7801\u4e3a AVC (H.264) \u683c\u5f0f\u3002\u5bf9\u4e8e\u5728\u8bbe\u5907\u4e0a\u521b\u5efa\u7684\u4ee5\u4e0b\u683c\u5f0f\u7684\u5185\u5bb9\uff0c\u7cfb\u7edf\u53ef\u4ee5\u81ea\u52a8\u8fdb\u884c\u8f6c\u7801\uff1a<\/p>\n<figure class=\"wp-block-table\">\n<table>\n<tbody>\n<tr>\n<td>\u5a92\u4f53\u683c\u5f0f<\/td>\n<td>XML\u5c5e\u6027<\/td>\n<td>MediaFormat MMIE\u7c7b\u578b<\/td>\n<\/tr>\n<tr>\n<td>HEVC (H.265)<\/td>\n<td>HEVC<\/td>\n<td>MediaFormat.MIMETYPE_VIDEO_HEVC<\/td>\n<\/tr>\n<tr>\n<td>HDR10<\/td>\n<td>HDR10<\/td>\n<td>MediaFeature.HdrType.HDR10<\/td>\n<\/tr>\n<tr>\n<td>HDR10+<\/td>\n<td>HDR10Plus<\/td>\n<td>MediaFeature.HdrType.HDR10_PLUS<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p>Android\u7cfb\u7edf\u9ed8\u8ba4\u5e94\u7528\u53ef\u4ee5\u652f\u6301\u64ad\u653e\u6240\u6709\u5a92\u4f53\u683c\u5f0f\uff0c\u56e0\u6b64\u201c\u517c\u5bb9\u7684\u5a92\u4f53\u8f6c\u7801\u201d\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u662f\u5173\u95ed\u7684\u3002\u5e94\u7528\u6709\u4e24\u79cd\u65b9\u6cd5\u6765\u8bf7\u6c42\u5c06\u5a92\u4f53\u6587\u4ef6\u8f6c\u7801\u6210\u66f4\u517c\u5bb9\u7684\u683c\u5f0f\uff1a1.\u5728\u8d44\u6e90\u6587\u4ef6\u4e2d\u58f0\u660e\uff1b2.\u5728\u4ee3\u7801\u4e2d\u58f0\u660e\u3002<\/p>\n<h4>3.2.1 \u5728\u8d44\u6e90\u6587\u4ef6\u4e2d\u58f0\u660e\u529f\u80fd<\/h4>\n<p>\u9996\u5148\u5728xml\u76ee\u5f55\u4e0b\u521b\u5efamedia_capabilities.xml\u8d44\u6e90\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;media-capabilities xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"&gt;\n    &lt;format android:name=\"HEVC\" supported=\"true\"\/&gt;\n    &lt;format android:name=\"HDR10\" supported=\"false\"\/&gt;\n    &lt;format android:name=\"HDR10Plus\" supported=\"false\"\/&gt;\n&lt;\/media-capabilities&gt;<\/code><\/pre>\n<p>\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5f55\u5236\u7684HEVC\u89c6\u9891\u65e0\u6cd5\u8f6c\u7801\uff0c\u800cHDR\u89c6\u9891\u4f1a\u88ab\u8f6c\u7801\u4e3aAVC SDR\uff08\u6807\u51c6\u52a8\u6001\u8303\u56f4\uff09\u89c6\u9891\u3002\u540c\u65f6\uff0c\u9700\u8981\u5728\u5e94\u7528AndroidManifest.xml\u4e2d<span class=\"wpcom_keyword_link\">app<\/span>lication \u6807\u7b7e\u4e2d\u4f7f\u7528property\u6765\u6807\u8bb0\u5bf9\u5a92\u4f53\u529f\u80fd\u6587\u4ef6\u7684\u5f15\u7528\uff1a<\/p>\n<pre class=\"wp-block-code\"><code>&lt;property\n    android:name=\"android.media.PROPERTY_MEDIA_CAPABILITIES\"\n    android:resource=\"@xml\/media_capabilities\" \/&gt;<\/code><\/pre>\n<h4>3.2.2 \u5728\u4ee3\u7801\u4e2d\u58f0\u660e\u529f\u80fd<\/h4>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528\u6784\u5efa\u5668\u6784\u9020 ApplicationMediaCapabilities\u5bf9\u8c61\u7684\u5b9e\u4f8b\uff0c\u5728\u4ee3\u7801\u4e2d\u58f0\u660e\u5a92\u4f53\u529f\u80fd\uff1a<\/p>\n<pre class=\"wp-block-code\"><code>ApplicationMediaCapabilities mediaCapabilities = <strong>new<\/strong> ApplicationMediaCapabilities.Builder() \n        .addSupportedVideoMimeType(MediaFormat.MIMETYPE_VIDEO_HEVC)\n        .addUnsupportedHdrType(MediaFeature.HdrType.HDR10)\n        .addUnsupportedHdrType(MediaFeature.HdrType.HDR10_PLUS)\n        .build();<\/code><\/pre>\n<p>\u901a\u8fc7 ContentResolver#openTypedAssetFileDescriptor()\u7b49\u65b9\u6cd5\u8bbf\u95ee\u5a92\u4f53\u5185\u5bb9\u65f6\uff0c\u8bf7\u4f7f\u7528\u6b64\u5bf9\u8c61\uff1a<\/p>\n<pre class=\"wp-block-code\"><code>Bundle providerOptions = <strong>new<\/strong> Bundle();\nproviderOptions.putParcelable(MediaStore.EXTRA_MEDIA_CAPABILITIES, mediaCapabilities);\n<strong>try<\/strong> (AssetFileDescriptor fileDescriptor =  contentResolver.openTypedAssetFileDescriptor(mediaUri, mediaMimeType, providerOptions)) {\n    <em>\/\/\u89c6\u9891\u5185\u5bb9\u4f1a\u8f6c\u6362\u6210ApplicationMediaCapabilities\u6307\u5b9a\u7684\u683c\u5f0f<\/em>\n}\n<\/code><\/pre>\n<p>\u6ce8\u610f\uff1a\u4ee3\u7801\u7684\u65b9\u5f0f\u4f1a\u4f18\u5148\u4e8e\u8d44\u6e90\u6587\u4ef6\uff0c\u8fd9\u6837\u53ef\u4ee5\u5bf9\u7279\u5b9a\u4ee3\u7801\u8def\u5f84\u505a\u66f4\u7cbe\u7ec6\u63a7\u5236\u3002<\/p>\n<h3 id=\"_3_2\">3.3 \u5728\u4f01\u4e1a\u4e2d\u4f7f\u7528Android<\/h3>\n<h4>3.3.1 Android 12\u4e2d\u7684\u4f01\u4e1a\u529f\u80fd\u65b0\u53d8\u5316<\/h4>\n<ul>\n<li>\u5bc6\u7801\u590d\u6742\u5ea6\u529f\u80fd\u4ee5\u9884\u5b9a\u4e49\u590d\u6742\u5b58\u50a8\u5206\u533a\uff08\u9ad8\u3001\u4e2d\u3001\u4f4e\u548c\u65e0\uff09\u7684\u5f62\u5f0f\u8bbe\u5b9a\u8bbe\u5907\u7ea7\u5bc6\u7801\u8981\u6c42\u3002\u5982\u6709\u5fc5\u8981\uff0c\u53ef\u5bf9\u5de5\u4f5c\u8d44\u6599\u5b89\u5168\u9a8c\u8bc1\u5e94\u7528\u4e25\u683c\u7684\u5bc6\u7801\u8981\u6c42\u3002<\/li>\n<li>\u5de5\u4f5c\u8d44\u6599\u5b89\u5168\u9a8c\u8bc1\u65b0\u624b\u5165\u95e8\u6d41\u7a0b\u5df2\u7b80\u5316\u3002\u73b0\u5728\uff0c\u8bbe\u7f6e\u4f1a\u8003\u8651\u8bbe\u5907\u5bc6\u7801\u662f\u5426\u7b26\u5408\u7ba1\u7406\u5458\u8981\u6c42\uff0c\u8ba9\u7528\u6237\u53ef\u4ee5\u8f7b\u677e\u9009\u62e9\u662f\u589e\u5f3a\u8bbe\u5907\u5bc6\u7801\u7684\u5f3a\u5ea6\u8fd8\u662f\u4f7f\u7528\u5de5\u4f5c\u8d44\u6599\u5b89\u5168\u9a8c\u8bc1\u3002<\/li>\n<li>\u6ce8\u518c\u7279\u5b9a ID \u63d0\u4f9b\u4e86\u4e00\u4e2a\u552f\u4e00 ID\uff0c\u7528\u4e8e\u6807\u8bc6\u7279\u5b9a\u7ec4\u7ec7\u7684\u5de5\u4f5c\u8d44\u6599\u6ce8\u518c\uff0c\u5e76\u4e14\u53ef\u5728\u6062\u590d\u51fa\u5382\u8bbe\u7f6e\u540e\u4fdd\u6301\u7a33\u5b9a\u3002\u5728 Android 12 \u4e2d\uff0c\u5bf9\u4e8e\u5177\u6709\u5de5\u4f5c\u8d44\u6599\u7684\u4e2a\u4eba\u8bbe\u5907\uff0c\u7cfb\u7edf\u4f1a\u79fb\u9664\u5bf9\u8be5\u8bbe\u5907\u7684\u5176\u4ed6\u786c\u4ef6\u6807\u8bc6\u7b26\uff08IMEI\u3001MEID\u3001\u5e8f\u5217\u53f7\uff09\u7684\u8bbf\u95ee\u6743\u9650\u3002<\/li>\n<li>\u516c\u53f8\u81ea\u6709\u8bbe\u5907\uff08\u65e0\u8bba\u662f\u5426\u5177\u6709\u5de5\u4f5c\u8d44\u6599\uff09\u53ef\u4ee5\u9009\u62e9\u662f\u5426\u4fdd\u7559\u4e0a\u8ff0\u5217\u8868\u9879\u4e2d\u5217\u51fa\u7684\u529f\u80fd\uff0c\u4f46\u4e0d\u9700\u8981\u5728 Android 12 \u4e2d\u91c7\u7528\u3002<\/li>\n<\/ul>\n<p>\u66f4\u8be6\u7ec6\u7684\u8d44\u6599\uff0c\u8bf7\u53c2\u9605\uff1aAndroid 12\u4f01\u4e1a\u529f\u80fd\u65b0\u53d8\u5316<\/p>\n<h3 id=\"_3_3\">3.4.\u65b0\u7684\u5e94\u7528\u542f\u52a8\u52a8\u753b<\/h3>\n<p>Android 12 \u6dfb\u52a0\u4e86SplashScreenAPI\uff0c\u5b83\u53ef\u4e3a\u6240\u6709\u5e94\u7528\u542f\u7528\u65b0\u7684\u5e94\u7528\u542f\u52a8\u52a8\u753b\u3002\u8fd9\u5305\u62ec\u542f\u52a8\u65f6\u7684\u8fdb\u5165\u5e94\u7528\u8fd0\u52a8\u3001\u663e\u793a\u5e94\u7528\u56fe\u6807\u7684\u542f\u52a8\u753b\u9762\uff0c\u4ee5\u53ca\u5411\u5e94\u7528\u672c\u8eab\u7684\u8fc7\u6e21\u3002<\/p>\n<p>\u8fd9\u79cd\u65b0\u4f53\u9a8c\u53ef\u8ba9\u5e94\u7528\u6bcf\u6b21\u542f\u52a8\u65f6\u90fd\u5448\u73b0\u6807\u51c6\u8bbe\u8ba1\u5143\u7d20\uff0c\u4f46\u5b83\u4e5f\u53ef\u81ea\u5b9a\u4e49\uff0c\u4ee5\u4fbf\u60a8\u7684\u5e94\u7528\u80fd\u591f\u4fdd\u6301\u5176\u72ec\u7279\u7684\u54c1\u724c\u3002<\/p>\n<h4>3.4.1 \u542f\u52a8\u753b\u9762\u7684\u5de5\u4f5c\u539f\u7406<\/h4>\n<p>\u5f53\u7528\u6237\u542f\u52a8\u5e94\u7528\u800c\u5e94\u7528\u7684\u8fdb\u7a0b\u672a\u5728\u8fd0\u884c\uff08\u51b7\u542f\u52a8\uff09\u6216 Activity \u5c1a\u672a\u521b\u5efa\uff08\u6e29\u542f\u52a8\uff09\u65f6\uff0c\u4f1a\u53d1\u751f\u4ee5\u4e0b\u4e8b\u4ef6\u3002\uff08\u5728\u70ed\u542f\u52a8\u671f\u95f4\u4ece\u4e0d\u663e\u793a\u542f\u52a8\u753b\u9762\u3002\uff09<\/p>\n<ul>\n<li>\u7cfb\u7edf\u4f7f\u7528\u4e3b\u9898\u4ee5\u53ca\u60a8\u5df2\u5b9a\u4e49\u7684\u4efb\u4f55\u52a8\u753b\u663e\u793a\u542f\u52a8\u753b\u9762\u3002<\/li>\n<li>\u5f53\u5e94\u7528\u51c6\u5907\u5c31\u7eea\u65f6\uff0c\u4f1a\u5173\u95ed\u542f\u52a8\u753b\u9762\u5e76\u663e\u793a\u5e94\u7528\u3002<\/li>\n<\/ul>\n<h4>3.4.2 \u52a8\u753b\u7684\u5143\u7d20\u548c\u673a\u5236<\/h4>\n<p>\u52a8\u753b\u7684\u5143\u7d20\u7531 Android \u6e05\u5355\u4e2d\u7684 XML \u8d44\u6e90\u6587\u4ef6\u5b9a\u4e49\u3002\u6bcf\u4e2a\u5143\u7d20\u90fd\u6709\u6d45\u8272\u6a21\u5f0f\u548c\u6df1\u8272\u6a21\u5f0f\u7248\u672c\u3002\u5b83\u4eec\u7531\u7a97\u53e3\u80cc\u666f\u3001\u52a8\u753b\u5f62\u5f0f\u7684\u5e94\u7528\u56fe\u6807\u548c\u56fe\u6807\u80cc\u666f\u7ec4\u6210\u3002<\/p>\n<p>\u5173\u4e8e\u8fd9\u4e9b\u5143\u7d20\uff0c\u8bf7\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<ul>\n<li>\u5e94\u7528\u56fe\u6807\u5e94\u8be5\u662f\u77e2\u91cf\u53ef\u7ed8\u5236\u5bf9\u8c61\uff0c\u5b83\u53ef\u4ee5\u662f\u9759\u6001\u6216\u52a8\u753b\u5f62\u5f0f\u3002\u867d\u7136\u52a8\u753b\u7684\u65f6\u957f\u53ef\u4ee5\u4e0d\u53d7\u9650\u5236\uff0c\u4f46\u6211\u4eec\u5efa\u8bae\u8ba9\u5176\u4e0d\u8d85\u8fc7 1000 \u6beb\u79d2\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u4f7f\u7528\u542f\u52a8\u5668\u56fe\u6807\u3002<\/li>\n<li>\u56fe\u6807\u80cc\u666f\u662f\u53ef\u9009\u7684\uff0c\u5728\u56fe\u6807\u4e0e\u7a97\u53e3\u80cc\u666f\u4e4b\u95f4\u9700\u8981\u66f4\u9ad8\u7684\u5bf9\u6bd4\u5ea6\u65f6\u5f88\u6709\u7528\u3002\u5982\u679c\u60a8\u4f7f\u7528\u4e00\u4e2a\u81ea\u9002\u5e94\u56fe\u6807\uff0c\u5f53\u8be5\u56fe\u6807\u4e0e\u7a97\u53e3\u80cc\u666f\u4e4b\u95f4\u7684\u5bf9\u6bd4\u5ea6\u8db3\u591f\u9ad8\u65f6\uff0c\u5c31\u4f1a\u663e\u793a\u5176\u80cc\u666f\u3002<\/li>\n<li>\u4e0e\u81ea\u9002\u5e94\u56fe\u6807\u4e00\u6837\uff0c\u524d\u666f\u7684 \u2153 \u88ab\u906e\u76d6\u3002<\/li>\n<li>\u7a97\u53e3\u80cc\u666f\u7531\u4e0d\u900f\u660e\u7684\u5355\u8272\u7ec4\u6210\u3002\u5982\u679c\u7a97\u53e3\u80cc\u666f\u5df2\u8bbe\u7f6e\u4e14\u4e3a\u7eaf\u8272\uff0c\u5219\u672a\u8bbe\u7f6e\u76f8\u5e94\u7684\u5c5e\u6027\u65f6\u9ed8\u8ba4\u4f7f\u7528\u8be5\u80cc\u666f\u3002<\/li>\n<\/ul>\n<p>\u542f\u52a8\u753b\u9762\u52a8\u753b\u673a\u5236\u7531\u8fdb\u5165\u52a8\u753b\u548c\u9000\u51fa\u52a8\u753b\u7ec4\u6210\u3002<\/p>\n<ul>\n<li>\u8fdb\u5165\u52a8\u753b\u7531\u7cfb\u7edf\u89c6\u56fe\u5230\u542f\u52a8\u753b\u9762\u7ec4\u6210\u3002\u8fd9\u7531\u7cfb\u7edf\u63a7\u5236\u4e14\u4e0d\u53ef\u81ea\u5b9a\u4e49\u3002<\/li>\n<li>\u9000\u51fa\u52a8\u753b\u7531\u9690\u85cf\u542f\u52a8\u753b\u9762\u7684\u52a8\u753b\u8fd0\u884c\u7ec4\u6210\u3002\u5982\u679c\u60a8\u8981\u5bf9\u5176\u8fdb\u884c\u81ea\u5b9a\u4e49\uff0c\u60a8\u5c06\u53ef\u4ee5\u8bbf\u95ee&nbsp;SplashScreenView&nbsp;\u53ca\u5176\u56fe\u6807\uff0c\u5e76\u4e14\u53ef\u4ee5\u5728\u5b83\u4eec\u4e4b\u4e0a\u8fd0\u884c\u4efb\u4f55\u52a8\u753b\uff08\u9700\u8981\u8bbe\u7f6e\u8f6c\u6362\u3001\u4e0d\u900f\u660e\u5ea6\u548c\u989c\u8272\uff09\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5f53\u52a8\u753b\u5b8c\u6210\u65f6\uff0c\u9700\u8981\u624b\u52a8\u79fb\u9664\u542f\u52a8\u753b\u9762\u3002<\/li>\n<\/ul>\n<h4>3.4.3 \u81ea\u5b9a\u4e49\u5e94\u7528\u4e2d\u7684\u542f\u52a8\u753b\u9762<\/h4>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cSplashScreen \u4f7f\u7528\u4e3b\u9898\u7684 windowBackground\uff08\u5982\u679c\u5b83\u662f\u5355\u8272\uff09\u548c\u542f\u52a8\u5668\u56fe\u6807\u3002\u542f\u52a8\u753b\u9762\u7684\u81ea\u5b9a\u4e49\u901a\u8fc7\u5411\u5e94\u7528\u4e3b\u9898\u6dfb\u52a0\u5c5e\u6027\u6765\u5b8c\u6210\u3002<\/p>\n<p>\u60a8\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4efb\u4e00\u65b9\u5f0f\u81ea\u5b9a\u4e49\u5e94\u7528\u7684\u542f\u52a8\u753b\u9762\uff1a<\/p>\n<ul>\n<li>\u8bbe\u7f6e\u4e3b\u9898\u5c5e\u6027\u4ee5\u66f4\u6539\u5176\u5916\u89c2<\/li>\n<li>\u8ba9\u5176\u5728\u5c4f\u5e55\u4e0a\u663e\u793a\u66f4\u957f\u65f6\u95f4<\/li>\n<li>\u81ea\u5b9a\u4e49\u7528\u4e8e\u5173\u95ed\u542f\u52a8\u753b\u9762\u7684\u52a8\u753b<\/li>\n<\/ul>\n<p><strong>\u8bbe\u7f6e\u542f\u52a8\u753b\u9762\u7684\u4e3b\u9898\u4ee5\u66f4\u6539\u5176\u5916\u89c2<\/strong><\/p>\n<p>\u60a8\u53ef\u4ee5\u5728 Activity \u4e3b\u9898\u4e2d\u6307\u5b9a\u4ee5\u4e0b\u5c5e\u6027\u6765\u81ea\u5b9a\u4e49\u5e94\u7528\u7684\u542f\u52a8\u753b\u9762\u3002\u5982\u679c\u60a8\u5df2\u6709\u4f7f\u7528 android:windowBackground \u7b49\u5c5e\u6027\u7684\u65e7\u7248\u542f\u52a8\u753b\u9762\u5b9e\u73b0\uff0c\u4e0d\u59a8\u8003\u8651\u4e3a Android 12 \u63d0\u4f9b\u66ff\u4ee3\u8d44\u6e90\u6587\u4ef6\u3002<\/p>\n<p>1.\u4f7f\u7528windowSplashScreenBackground&nbsp;\u4ee5\u7279\u5b9a\u7684\u5355\u8272\u586b\u5145\u80cc\u666f\uff1a<\/p>\n<pre class=\"wp-block-code\"><code>&lt;item name=\"android:windowSplashScreenBackground\"&gt;@color\/...&lt;\/item&gt;<\/code><\/pre>\n<p>2.\u4f7f\u7528windowSplashScreenAnimatedIcon\u66ff\u6362\u8d77\u59cb\u7a97\u53e3\u4e2d\u5fc3\u7684\u56fe\u6807\u3002\u5982\u679c\u5bf9\u8c61\u901a\u8fc7AnimationDrawable\u548cAnimatedVectorDrawable\u53ef\u5448\u73b0\u52a8\u753b\u6548\u679c\u4e14\u53ef\u7ed8\u5236\uff0c\u5219\u4e5f\u4f1a\u5728\u663e\u793a\u8d77\u59cb\u7a97\u53e3\u7684\u540c\u65f6\u64ad\u653e\u52a8\u753b\u3002<\/p>\n<pre class=\"wp-block-code\"><code>&lt;item name=\"android:windowSplashScreenAnimatedIcon\"&gt;@drawable\/...&lt;\/item&gt;<\/code><\/pre>\n<p>3.\u4f7f\u7528windowSplashScreenAnimationDuration\u8bbe\u7f6e\u542f\u52a8\u753b\u9762\u5728\u5173\u95ed\u4e4b\u524d\u663e\u793a\u7684\u65f6\u957f\u3002\u6700\u957f\u65f6\u95f4\u4e3a 1000 \u6beb\u79d2\u3002<\/p>\n<p>4.\u4f7f\u7528 windowSplashScreenIconBackground \u8bbe\u7f6e\u542f\u52a8\u753b\u9762\u56fe\u6807\u540e\u9762\u7684\u80cc\u666f\u3002\u5f53\u7a97\u53e3\u80cc\u666f\u4e0e\u56fe\u6807\u4e4b\u95f4\u7684\u5bf9\u6bd4\u5ea6\u4e0d\u591f\u9ad8\u65f6\uff0c\u8fd9\u5f88\u6709\u7528\u3002<\/p>\n<pre class=\"wp-block-code\"><code>&lt;item name=\"android:windowSplashScreenIconBackground\"&gt;@color\/...&lt;\/item&gt;<\/code><\/pre>\n<p>5.\uff08\u53ef\u9009\uff09\u60a8\u53ef\u4ee5\u4f7f\u7528windowSplashScreenBrandingImage\u8bbe\u7f6e\u8981\u663e\u793a\u5728\u542f\u52a8\u753b\u9762\u5e95\u90e8\u7684\u56fe\u7247\u3002\u8bbe\u8ba1\u51c6\u5219\u5efa\u8bae\u4e0d\u8981\u4f7f\u7528\u54c1\u724c\u56fe\u7247\u3002<\/p>\n<pre class=\"wp-block-code\"><code>&lt;item name=\"android:windowSplashScreenBrandingImage\"&gt;@drawable\/...&lt;\/item&gt;<\/code><\/pre>\n<p><strong>\u6ce8\u610f<\/strong>\uff1a\u5efa\u8bae\u7684\u8bbe\u8ba1\u51c6\u5219\u662f\u4e0d\u8981\u4f7f\u7528\u54c1\u724c\u56fe\u7247\u3002<\/p>\n<p><strong>\u8ba9\u542f\u52a8\u753b\u9762\u5728\u5c4f\u5e55\u4e0a\u663e\u793a\u66f4\u957f\u65f6\u95f4<\/strong><\/p>\n<p>\u5f53\u5e94\u7528\u7ed8\u5236\u7b2c\u4e00\u5e27\u540e\uff0c\u542f\u52a8\u753b\u9762\u4f1a\u7acb\u5373\u5173\u95ed\u3002\u5982\u679c\u60a8\u9700\u8981\u4ece\u672c\u5730\u78c1\u76d8\u5f02\u6b65\u52a0\u8f7d\u5c11\u91cf\u6570\u636e\uff08\u5982\u5e94\u7528\u5185\u4e3b\u9898\u8bbe\u7f6e\uff09\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528ViewTreeObserver.OnPreDrawListener\u8ba9\u5e94\u7528\u6682\u505c\u7ed8\u5236\u7b2c\u4e00\u5e27\u3002<\/p>\n<pre class=\"wp-block-code\"><code><em>\/\/ Create a new event for the activity.<\/em>\n@Override\n<strong>protected<\/strong> <strong>void<\/strong> <strong>onCreate<\/strong>(@Nullable Bundle savedInstanceState) {\n    <strong>super<\/strong>.onCreate(savedInstanceState);\n    <em>\/\/ Set the layout for the content view.<\/em>\n    setContentView(R.layout.main_activity);\n\n    <em>\/\/ Set up an OnPreDrawListener to the root view.<\/em>\n    <strong>final<\/strong> View content = findViewById(android.R.id.content);\n    content.getViewTreeObserver().addOnPreDrawListener(\n            <strong>new<\/strong> ViewTreeObserver.OnPreDrawListener() {\n                @Override\n                <strong>public<\/strong> <strong>boolean<\/strong> <strong>onPreDraw<\/strong>() {\n                    <em>\/\/ Check if the initial data is ready.<\/em>\n                    <strong>if<\/strong> (mViewModel.isReady()) {\n                        <em>\/\/ The content is ready; start drawing.<\/em>\n                        content.getViewTreeObserver().removeOnPreDrawListener(<strong>this<\/strong>);\n                        <strong>return<\/strong> <strong>true<\/strong>;\n                    } <strong>else<\/strong> {\n                        <em>\/\/ The content is not ready; suspend.<\/em>\n                        <strong>return<\/strong> <strong>false<\/strong>;\n                    }\n                }\n            });\n}<\/code><\/pre>\n<p><strong>\u81ea\u5b9a\u4e49\u7528\u4e8e\u5173\u95ed\u542f\u52a8\u753b\u9762\u7684\u52a8\u753b<\/strong><\/p>\n<p>\u60a8\u53ef\u4ee5\u901a\u8fc7Activity.getSplashScreen\u8fdb\u4e00\u6b65\u81ea\u5b9a\u4e49\u542f\u52a8\u753b\u9762\u7684\u52a8\u753b\u3002<\/p>\n<pre class=\"wp-block-code\"><code>@Override\n<strong>protected<\/strong> <strong>void<\/strong> <strong>onCreate<\/strong>(@Nullable Bundle savedInstanceState) {\n    <strong>super<\/strong>.onCreate(savedInstanceState);\n    <em>\/\/ ...<\/em>\n\n    <em>\/\/ Add a callback that's called when the splash screen is animating to<\/em>\n    <em>\/\/ the app content.<\/em>\n    getSplashScreen().setOnExitAnimationListener(splashScreenView -&gt; {\n        <strong>final<\/strong> ObjectAnimator slideUp = ObjectAnimator.ofFloat(\n                splashScreenView,\n                View.TRANSLATION_Y,\n                0f,\n                -splashScreenView.getHeight()\n        );\n        slideUp.setInterpolator(<strong>new<\/strong> AnticipateInterpolator());\n        slideUp.setDuration(200L);\n\n        <em>\/\/ Call SplashScreenView.remove at the end of your custom animation.<\/em>\n        slideUp.addListener(<strong>new<\/strong> AnimatorListenerAdapter() {\n            @Override\n            <strong>public<\/strong> <strong>void<\/strong> <strong>onAnimationEnd<\/strong>(Animator animation) {\n                splashScreenView.remove();\n            }\n        });\n\n        <em>\/\/ Run your animation.<\/em>\n        slideUp.start();\n    });\n}<\/code><\/pre>\n<p>\u5728\u6b64\u56de\u8c03\u5f00\u59cb\u65f6\uff0c\u542f\u52a8\u753b\u9762\u4e0a\u52a8\u753b\u5f62\u5f0f\u7684\u77e2\u91cf\u53ef\u7ed8\u5236\u5bf9\u8c61\u5df2\u7ecf\u5f00\u59cb\u3002\u6839\u636e\u5e94\u7528\u542f\u52a8\u7684\u65f6\u957f\uff0c\u53ef\u7ed8\u5236\u5bf9\u8c61\u53ef\u80fd\u5728\u5176\u52a8\u753b\u7684\u4e2d\u95f4\u3002\u4f7f\u7528SplashScreenView.getIconAnimationStartMillis&nbsp;\u53ef\u4e86\u89e3\u52a8\u753b\u4f55\u65f6\u5f00\u59cb\u3002\u60a8\u53ef\u4ee5\u6309\u5982\u4e0b\u65b9\u5f0f\u8ba1\u7b97\u56fe\u6807\u52a8\u753b\u7684\u5269\u4f59\u65f6\u957f\uff1a<\/p>\n<pre class=\"wp-block-code\"><code><em>\/\/ Get the duration of the animated vector drawable.<\/em>\n<strong>long<\/strong> animationDuration = splashScreenView.getIconAnimationDurationMillis();\n<em>\/\/ Get the start time of the animation.<\/em>\n<strong>long<\/strong> animationStart = splashScreenView.getIconAnimationStartMillis();\n<em>\/\/ Calculate the remaining duration of the animation.<\/em>\n<strong>long<\/strong> remainingDuration = Math.max(\n        animationDuration - (SystemClock.uptimeMillis() - animationStart),\n        0L\n);<\/code><\/pre>\n<h3 id=\"_3_4\">3.5 \u753b\u4e2d\u753b (PiP) \u6539\u8fdb<\/h3>\n<p>Android 12 \u9488\u5bf9\u753b\u4e2d\u753b (PiP) \u6a21\u5f0f\u5f15\u5165\u4e86\u884c\u4e3a\u6539\u8fdb\u548c\u65b0\u529f\u80fd<\/p>\n<h4>3.5.1 \u70b9\u6309\u4e00\u6b21\u548c\u70b9\u6309\u4e24\u6b21\u7684\u884c\u4e3a\u6539\u8fdb<\/h4>\n<p>Android 12 \u6539\u8fdb\u4e86\u70b9\u6309\u4e00\u6b21\u548c\u70b9\u6309\u4e24\u6b21\u7684\u753b\u4e2d\u753b\u884c\u4e3a\uff0c\u5177\u4f53\u8bf4\u660e\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\u73b0\u5728\uff0c\u70b9\u6309\u4e00\u6b21\u753b\u4e2d\u753b\u7a97\u53e3\u4f1a\u4e3a\u7528\u6237\u663e\u793a\u63a7\u4ef6\u3002\u4ee5\u524d\uff0c\u70b9\u6309\u4e00\u6b21\u4f1a\u5c55\u5f00\u753b\u4e2d\u753b\u7a97\u53e3\u5e76\u663e\u793a\u63a7\u4ef6\u3002<\/li>\n<li>\u73b0\u5728\uff0c\u70b9\u6309\u4e24\u6b21\u753b\u4e2d\u753b\u7a97\u53e3\u4f1a\u5728\u5f53\u524d\u753b\u4e2d\u753b\u5927\u5c0f\u4e0e\u6700\u5927\u753b\u4e2d\u753b\u5927\u5c0f\u4e4b\u95f4\u5207\u6362\u3002\u4ee5\u524d\uff0c\u70b9\u6309\u4e24\u6b21\u4f1a\u79bb\u5f00\u753b\u4e2d\u753b\u6a21\u5f0f\u800c\u6539\u4e3a\u5168\u5c4f\u6a21\u5f0f\u3002<\/li>\n<\/ul>\n<h4>3.5.2 \u65b0\u529f\u80fd<\/h4>\n<p>Android 12 \u9488\u5bf9\u753b\u4e2d\u753b\u6a21\u5f0f\u5f15\u5165\u4e86\u4ee5\u4e0b\u65b0\u529f\u80fd\uff1a<\/p>\n<ul>\n<li>\u7528\u4e8e\u5728\u624b\u52bf\u5bfc\u822a\u4e2d\u66f4\u6d41\u7545\u5730\u8fc7\u6e21\u5230\u753b\u4e2d\u753b\u6a21\u5f0f\u7684\u65b0 API \u6807\u5fd7<\/li>\n<li>\u7528\u4e8e\u4e3a\u975e\u89c6\u9891\u5185\u5bb9\u505c\u7528\u65e0\u7f1d\u5927\u5c0f\u8c03\u6574\u7684\u65b0 API \u6807\u5fd7<\/li>\n<li>\u9000\u51fa\u753b\u4e2d\u753b\u6a21\u5f0f\u65f6\u66f4\u6d41\u7545\u7684\u52a8\u753b<\/li>\n<li>\u652f\u6301\u65b0\u624b\u52bf<\/li>\n<\/ul>\n<h5>3.5.2.1 \u7528\u4e8e\u5728\u624b\u52bf\u5bfc\u822a\u4e2d\u66f4\u6d41\u7545\u5730\u8fc7\u6e21\u5230\u753b\u4e2d\u753b\u6a21\u5f0f\u7684\u65b0 API \u6807\u5fd7<\/h5>\n<p>Androi<a href=\"https:\/\/app.applebyme.cn\/shengcheng-68.html\">\u81ea\u52a8\u751f\u6210\u6392\u73ed\u8f6f\u4ef6app<\/a>d 12 \u53ef\u8ba9\u60a8\u4f7f\u7528\u65b0\u7684setAutoEnterEnabled\u6807\u5fd7\uff0c\u5728\u624b\u52bf\u5bfc\u822a\u6a21\u5f0f\u4e0b\u5411\u4e0a\u6ed1\u52a8\u8f6c\u5230\u4e3b\u5c4f\u5e55\u65f6\u66f4\u6d41\u7545\u5730\u8fc7\u6e21\u5230\u753b\u4e2d\u753b\u6a21\u5f0f\u3002\u4ee5\u524d\uff0cAndroid \u4f1a\u7b49\u5230\u201c\u5411\u4e0a\u6ed1\u52a8\u8f6c\u5230\u4e3b\u5c4f\u5e55\u201d\u52a8\u753b\u7ed3\u675f\uff0c\u7136\u540e\u518d\u6de1\u5165\u753b\u4e2d\u753b\u7a97\u53e3\u3002<\/p>\n<p>\u5982\u9700\u5b9e\u73b0\u6b64\u529f\u80fd\uff0c\u8bf7\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n<p>1.\u4f7f\u7528setAutoEnterEnabled \u6784\u9020PictureInPictureParams.Builder\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre class=\"wp-block-code\"><code>setPictureInPictureParams(<strong>new<\/strong> PictureInPictureParams.Builder()\n    .setAspectRatio(aspectRatio)\n    .setSourceRectHint(sourceRectHint)\n    .setAutoEnterEnabled(<strong>true<\/strong>)    \n    .build());<\/code><\/pre>\n<p><strong>\u6ce8\u610f<\/strong>\uff1a\u542f\u7528 setAutoEnterEnabled \u540e\uff0c\u65e0\u9700\u5728onUserLeaveHint\u4e2d\u663e\u5f0f\u8c03\u7528enterPictureInPictureMode\u3002<\/p>\n<p>2.\u5c3d\u65e9\u4f7f\u7528\u6700\u65b0\u7684 PictureInPictureParams \u8c03\u7528 setPictureInPictureParams\u3002\u5e94\u7528\u4e0d\u5e94\u7b49\u5f85 onUserLeaveHint \u56de\u8c03\uff08\u5c31\u50cf\u5728 Android 11 \u4e2d\u6240\u505a\u7684\u90a3\u6837\uff09\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u5e94\u7528\u53ef\u80fd\u8981\u5728\u7b2c\u4e00\u6b21\u64ad\u653e\u4ee5\u53ca\u540e\u7eed\u4efb\u4f55\u4e00\u6b21\u64ad\u653e\u65f6\uff08\u5982\u679c\u5bbd\u9ad8\u6bd4\u53d1\u751f\u4e86\u53d8\u5316\uff09\u8c03\u7528 setPictureInPictureParams\u3002<\/p>\n<p>3.\u6839\u636e\u9700\u8981\u8c03\u7528 setAutoEnterEnabled(false)\u3002\u4f8b\u5982\uff0c\u5982\u679c\u5f53\u524d\u64ad\u653e\u5904\u4e8e\u6682\u505c\u72b6\u6001\uff0c\u5219\u89c6\u9891\u5e94\u7528\u8fdb\u5165\u753b\u4e2d\u753b\u6a21\u5f0f\u53ef\u80fd\u4e0d\u662f\u6700\u4f73\u9009\u62e9\u3002<\/p>\n<h5>3.5.2.2 \u7528\u4e8e\u4e3a\u975e\u89c6\u9891\u5185\u5bb9\u505c\u7528\u65e0\u7f1d\u5927\u5c0f\u8c03\u6574\u7684\u65b0 API \u6807\u5fd7<\/h5>\n<p>Android 12 \u6dfb\u52a0\u4e86SeamlessResizeEnabled\u6807\u5fd7\uff0c\u5728\u753b\u4e2d\u753b\u7a97\u53e3\u4e2d\u8c03\u6574\u975e\u89c6\u9891\u5185\u5bb9\u7684\u5927\u5c0f\u65f6\uff0c\u8be5\u6807\u5fd7\u53ef\u63d0\u4f9b\u66f4\u6d41\u7545\u7684\u4ea4\u66ff\u6de1\u53d8\u52a8\u753b\u3002\u4ee5\u524d\uff0c\u5728\u753b\u4e2d\u753b\u7a97\u53e3\u4e2d\u8c03\u6574\u975e\u89c6\u9891\u5185\u5bb9\u7684\u5927\u5c0f\u65f6\u4f1a\u4ea7\u751f\u70e6\u4eba\u7684\u89c6\u89c9\u4f2a\u5f71\u3002<\/p>\n<p>\u4e3a\u4e86\u5411\u540e\u517c\u5bb9\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5c06 setSeamlessResizeEnabled \u6807\u5fd7\u8bbe\u7f6e\u4e3a true\u3002\u5bf9\u4e8e\u89c6\u9891\u5185\u5bb9\uff0c\u8bf7\u5c06\u5176\u8bbe\u7f6e\u4fdd\u7559\u4e3a true\uff1b\u5bf9\u4e8e\u975e\u89c6\u9891\u5185\u5bb9\uff0c\u8bf7\u5c06\u5176\u66f4\u6539\u4e3a false\u3002<\/p>\n<p>\u5982\u9700\u505c\u7528\u975e\u89c6\u9891\u5185\u5bb9\u7684\u65e0\u7f1d\u5927\u5c0f\u8c03\u6574\uff0c\u8bf7\u7f16\u5199\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre class=\"wp-block-code\"><code> setPictureInPictureParams(<strong>new<\/strong> PictureInPictureParams.Builder()\n      .setSeamlessResizeEnabled(<strong>false<\/strong>)\n      .build());<\/code><\/pre>\n<h5>3.5.2.3 \u9000\u51fa\u753b\u4e2d\u753b\u6a21\u5f0f\u65f6\u652f\u6301\u66f4\u6d41\u7545\u7684\u52a8\u753b<\/h5>\n<p>\u5728 Android 12 \u4e2d\uff0cSourceRectHint\u6807\u5fd7\u73b0\u5728\u91cd\u7528\u4e8e\u5728\u9000\u51fa\u753b\u4e2d\u753b\u6a21\u5f0f\u65f6\u5b9e\u73b0\u66f4\u6d41\u7545\u7684\u52a8\u753b\u3002\u9000\u51fa\u65f6\uff0c\u7cfb\u7edf\u4f1a\u4f7f\u7528\u5f53\u524d\u53ef\u7528\u7684 sourceRectHint \u521b\u5efa\u52a8\u753b\uff0c\u65e0\u8bba\u5b83\u662f\u7528\u4e8e\u8fdb\u5165\u753b\u4e2d\u753b\u6a21\u5f0f\u7684\u539f\u59cb Rect\uff0c\u8fd8\u662f\u5e94\u7528\u63d0\u4f9b\u7684\u66f4\u65b0\u540e\u7684 Rect\u3002<\/p>\n<p>\u5982\u9700\u5b9e\u73b0\u6b64\u529f\u80fd\uff0c\u8bf7\u6309\u4ee5\u4e0b\u65b9\u5f0f\u66f4\u65b0\u60a8\u7684\u5e94\u7528\uff1a<\/p>\n<p>1.\u7ee7\u7eed\u4f7f\u7528sourceRectHint\u548caspectRatio\u6784\u9020 PictureInPictureParams\uff0c\u4ee5\u5b9e\u73b0\u6d41\u7545\u7684\u8fdb\u5165\u52a8\u753b\u3002<\/p>\n<p>2.\u5982\u6709\u5fc5\u8981\uff0c\u8bf7\u5728\u7cfb\u7edf\u5f00\u59cb\u9000\u51fa\u8fc7\u6e21\u4e4b\u524d\u66f4\u65b0sourceRectHint\u3002\u5f53\u7cfb\u7edf\u5373\u5c06\u9000\u51fa\u753b\u4e2d\u753b\u6a21\u5f0f\u65f6\uff0cactivity \u7684\u89c6\u56fe\u5c42\u6b21\u7ed3\u6784\u4f1a\u5e03\u5c40\u6210\u5176\u76ee\u6807\u914d\u7f6e\uff08\u4f8b\u5982\u5168\u5c4f\uff09\u3002\u5e94\u7528\u53ef\u4ee5\u5c06\u5e03\u5c40\u66f4\u6539\u76d1\u542c\u5668\u9644\u52a0\u5230\u5176\u6839\u89c6\u56fe\u6216\u76ee\u6807\u89c6\u56fe\uff08\u5982\u89c6\u9891\u64ad\u653e\u5668\u89c6\u56fe\uff09\uff0c\u4ee5\u68c0\u6d4b\u4e8b\u4ef6\u5e76\u5728\u52a8\u753b\u5f00\u59cb\u524d\u66f4\u65b0 sourceRectHint\u3002<\/p>\n<pre class=\"wp-block-code\"><code><em>\/\/ Listener is called immediately after the user exits PIP but before animating.  <\/em>\n playerView.addOnLayoutChangeListener { _, left, top, right, bottom,                      \n               oldLeft, oldTop, oldRight, oldBottom -&gt;      \n   <strong>if<\/strong> (left != oldLeft || right != oldRight || top != oldTop \n           || bottom != oldBottom) {         \n       <em>\/\/ The playerView's bounds changed, update the source hint rect to         <\/em>\n       <em>\/\/ reflect its new bounds.         <\/em>\n       val sourceRectHint = Rect()         \n       playerView.getGlobalVisibleRect(sourceRectHint)         \n       setPictureInPictureParams(             \n       <a href=\"https:\/\/app.applebyme.cn\/shengcheng-39.html\">\u624b\u673aapp\u751f\u6210\u5668<\/a>    PictureInPictureParams.Builder()                 \n               .setSourceRectHint(sourceRectHint)                 \n               .build()         \n       )      \n   }  \n}<\/code><\/pre>\n<h5>3.5.2.4 \u652f\u6301\u65b0\u624b\u52bf<\/h5>\n<p>Android 12 \u73b0\u5728\u652f\u6301\u5bf9\u753b\u4e2d\u753b\u7a97\u53e3\u4f7f\u7528\u9690\u85cf\u548c\u201c\u53cc\u6307\u5f20\u5408\u5373\u53ef\u7f29\u653e\u201d\u624b\u52bf\uff1a<\/p>\n<ul>\n<li>\u5982\u9700\u9690\u85cf\u7a97\u53e3\uff0c\u7528\u6237\u53ef\u4ee5\u5c06\u7a97\u53e3\u62d6\u52a8\u5230\u5de6\u4fa7\u6216\u53f3\u4fa7\u8fb9\u7f18\u3002\u5982\u9700\u53d6\u6d88\u9690\u85cf\u7a97\u53e3\uff0c\u7528\u6237\u53ef\u4ee5\u70b9\u6309\u5df2\u9690\u85cf\u7a97\u53e3\u7684\u53ef\u89c1\u90e8\u5206\u6216\u5c06\u5176\u62d6\u51fa\u3002<\/li>\n<li>\u7528\u6237\u73b0\u5728\u53ef\u4ee5\u4f7f\u7528\u201c\u53cc\u6307\u5f20\u5408\u5373\u53ef\u7f29\u653e\u201d\u624b\u52bf\u8c03\u6574\u753b\u4e2d\u753b\u7a97\u53e3\u7684\u5927\u5c0f\u3002<\/li>\n<\/ul>\n<h3 id=\"_3_5\">3.6 \u5b58\u50a8<\/h3>\n<p>Android 12 \u5f15\u5165\u4e86\u5bf9\u5b58\u50a8\u7ba1\u7406 API \u7684\u51e0\u9879\u53d8\u66f4\uff0c\u4e0b\u9762\u51e0\u90e8\u5206\u5bf9\u6b64\u8fdb\u884c\u4e86\u4ecb\u7ecd\u3002<\/p>\n<h4>3.6.1 \u8bed\u97f3\u5f55\u97f3\u7684\u65b0\u76ee\u5f55<\/h4>\n<p>\u7cfb\u7edf\u4f1a\u5c06\u5b58\u50a8\u5728\u65b0Environment.DIRECTORY_RECORDINGS\u6587\u4ef6\u5939\u4e2d\u7684\u97f3\u9891\u6587\u4ef6\u8bc6\u522b\u4e3a\u5f55\u97f3\u3002\u5f53\u60a8\u7684\u5e94\u7528\u5bf9\u7cfb\u7edf\u7684\u5a92\u4f53\u5e93\u6267\u884c\u67e5\u8be2\u65f6\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528IS_RECORDING\u6807\u5fd7\u6765\u68c0\u7d22\u5f55\u97f3\u3002<\/p>\n<h4>3.6.2 \u5a92\u4f53\u7ba1\u7406\u8bbf\u95ee\u6743\u9650<\/h4>\n<p>\u7528\u6237\u53ef\u80fd\u4f1a\u4fe1\u4efb\u7279\u5b9a\u7684\u5e94\u7528\u6765\u6267\u884c\u5a92\u4f53\u7ba1\u7406\uff0c\u5982\u9891\u7e41\u5730\u4fee\u6539\u5a92\u4f53\u6587\u4ef6\u3002\u5982\u679c\u60a8\u7684\u5e94\u7528\u4ee5 Android 11\uff08API \u7ea7\u522b 30\uff09\u6216\u66f4\u9ad8\u7248\u672c\u4e3a\u76ee\u6807\u5e73\u53f0\u4e14\u4e0d\u662f\u8bbe\u5907\u7684\u9ed8\u8ba4\u56fe\u5e93\u5e94\u7528\uff0c\u5219\u6bcf\u6b21\u60a8\u7684\u5e94\u7528\u5c1d\u8bd5\u4fee\u6539\u6216\u5220\u9664\u6587\u4ef6\u65f6\uff0c\u60a8\u90fd\u5fc5\u987b\u5411\u7528\u6237\u663e\u793a\u4e00\u4e2a\u786e\u8ba4\u5bf9\u8bdd\u6846\u3002<\/p>\n<p>\u5982\u679c\u60a8\u7684\u5e94\u7528\u4ee5 Android 12 \u4e3a\u76ee\u6807\u5e73\u53f0\uff0c\u60a8\u53ef\u4ee5\u8bf7\u6c42\u7528\u6237\u5411\u60a8\u7684\u5e94\u7528\u6388\u4e88\u6267\u884c\u4ee5\u4e0b\u5404\u9879\u64cd\u4f5c\u7684\u6743\u9650\uff0c\u800c\u65e0\u9700\u9488\u5bf9\u6bcf\u9879\u6587\u4ef6\u64cd\u4f5c\u63d0\u793a\u7528\u6237\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528&nbsp;createWriteRequest()&nbsp;\u4fee\u6539\u6587\u4ef6\u3002<\/li>\n<li>\u4f7f\u7528&nbsp;createTrashRequest()&nbsp;\u5c06\u6587\u4ef6\u79fb\u5165\u548c\u79fb\u51fa\u56de\u6536\u7ad9\u3002<\/li>\n<li>\u4f7f\u7528&nbsp;createDeleteRequest()&nbsp;\u5220\u9664\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<p>\u4e3a\u6b64\uff0c\u8bf7\u5b8c\u6210\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p>1.\u5728\u5e94\u7528\u7684\u6e05\u5355\u6587\u4ef6\u4e2d\u58f0\u660e\u65b0\u7684MANAGE_MEDIA\u6743\u9650\u548cREAD_EXTERNAL_STORAGE\u6743\u9650\u3002<\/p>\n<p>\u4e3a\u4e86\u8c03\u7528 createWriteRequest() \u800c\u4e0d\u663e\u793a\u786e\u8ba4\u5bf9\u8bdd\u6846\uff0c\u8bf7\u540c\u65f6\u58f0\u660eACCESS_MEDIA_LOCATION\u6743\u9650\u3002<\/p>\n<p>2.\u5728\u60a8\u7684\u5e94\u7528\u4e2d\uff0c\u5411\u7528\u6237\u663e\u793a\u4e00\u4e2a\u754c\u9762\uff0c\u8bf4\u660e\u4e3a\u4ec0\u4e48\u4ed6\u4eec\u53ef\u80fd\u9700\u8981\u5411\u60a8\u7684\u5e94\u7528\u6388\u4e88\u5a92\u4f53\u7ba1\u7406\u8bbf\u95ee\u6743\u9650\u3002<\/p>\n<p>3.\u8c03\u7528ACTION_REQUEST_MANAGE_MEDIA&nbsp;intent \u64cd\u4f5c\u3002\u8fd9\u6837\u4f1a\u5c06\u7528\u6237\u5f15\u5bfc\u81f3\u7cfb\u7edf\u8bbe\u7f6e\u4e2d\u7684\u5a92\u4f53\u7ba1\u7406\u5e94\u7528\u5c4f\u5e55\u3002\u5728\u6b64\u5904\uff0c\u7528\u6237\u53ef\u4ee5\u6388\u4e88\u7279\u6b8a\u5e94\u7528\u8bbf\u95ee\u6743\u9650\u3002<\/p>\n<h4>3.6.3 \u5e94\u7528\u5b58\u50a8\u8bbf\u95ee\u6743\u9650<\/h4>\n<p>\u5e94\u7528\u53ef\u4ee5\u58f0\u660e\u5e76\u521b\u5efa\u4e00\u4e2a\u81ea\u5b9a\u4e49 activity\uff0c\u8be5 activity \u5728\u542f\u52a8\u540e\u53ef\u8ba9\u7528\u6237\u7ba1\u7406\u5e94\u7528\u5b58\u50a8\u5728\u7528\u6237\u8bbe\u5907\u4e0a\u7684\u6570\u636e\u3002\u5e94\u7528\u53ef\u4ee5\u5728\u6e05\u5355\u6587\u4ef6\u4e2d\u4f7f\u7528android:manageSpaceActivity<\/p>\n<p>\u5c5e\u6027\u58f0\u660e\u6b64\u81ea\u5b9a\u4e49\u201c\u7ba1\u7406\u7a7a\u95f4\u201dactivity\u3002\u6587\u4ef6\u7ba1\u7406\u5668\u5e94\u7528\u53ef\u4ee5\u542f\u52a8\u6b64\u201c\u7ba1\u7406\u7a7a\u95f4\u201dactivity\uff0c\u5373\u4f7f\u5e94\u7528\u672a\u5bfc\u51fa\u8be5 activity\uff08\u5373\uff0c\u8be5 activity \u5c06android:exported\u8bbe\u7f6e\u4e3a false\uff09\u4e5f\u662f\u5982\u6b64\u3002<\/p>\n<p>\u5728 Android 12 \u4e2d\uff0c\u540c\u65f6\u5177\u6709MANAGE_EXTERNAL_STORAGE\u6743\u9650\u548cQUERY_ALL_PACKAGES\u6743\u9650\u7684\u5e94\u7528\uff08\u5982\u6587\u4ef6\u7ba1\u7406\u5e94\u7528\uff09\u53ef\u4f7f\u7528\u65b0\u7684getManageSpaceActivityIntent()<\/p>\n<p>\u5c06\u7528\u6237\u5f15\u5bfc\u81f3\u5176\u4ed6\u5e94\u7528\u7684\u81ea\u5b9a\u4e49\u201c\u7ba1\u7406\u7a7a\u95f4\u201dactivity\uff08\u5982\u679c\u4e3a\u8be5\u5e94\u7528\u5b9a\u4e49\u4e86\u4e00\u4e2a\uff09\u3002<\/p>\n<p>getManageSpaceActivityIntent() \u65b9\u6cd5\u63a5\u53d7\u8f6f\u4ef6\u5305\u540d\u79f0\u548c\u8bf7\u6c42\u4ee3\u7801\uff0c\u5b83\u8fd4\u56de\u4ee5\u4e0b\u67d0\u4e00\u9879\uff1a<\/p>\n<ul>\n<li>PendingIntent&nbsp;&#8211; \u5982\u679c\u5177\u6709\u6307\u5b9a\u8f6f\u4ef6\u5305\u540d\u79f0\u7684\u5e94\u7528\u5df2\u5b9a\u4e49\u81ea\u5b9a\u4e49\u201c\u7ba1\u7406\u7a7a\u95f4\u201dactivity\u3002\u8c03\u7528 getManageSpaceActivityIntent() \u65b9\u6cd5\u7684\u5e94\u7528\u968f\u540e\u53ef\u4ee5\u8c03\u7528\u8fd4\u56de\u7684 intent \u4ee5\u5c06\u7528\u6237\u5f15\u5bfc\u81f3\u8be5\u81ea\u5b9a\u4e49 activity\u3002<\/li>\n<li>null &#8211; \u5982\u679c\u5177\u6709\u6307\u5b9a\u8f6f\u4ef6\u5305\u540d\u79f0\u7684\u5e94\u7528\u672a\u5b9a\u4e49\u201c\u7ba1\u7406\u7a7a\u95f4\u201dactivity\u3002<\/li>\n<\/ul>\n<h4>3.6.4 \u6269\u5c55\u7684\u6587\u4ef6\u8bbf\u95ee\u6743\u9650\u652f\u6301<\/h4>\n<p>\u9664\u4e86\u5bf9 ExternalStorageProvider URI \u7684\u73b0\u6709\u652f\u6301\u4ee5\u5916\uff0cgetMediaUri()\u65b9\u6cd5\u73b0\u5728\u8fd8\u652f\u6301 MediaDocumentsProvider URI\u3002\u73b0\u5728\uff0c\u7cfb\u7edf\u5728\u8fd4\u56de\u8fd9\u4e9b URI \u4e4b\u524d\u5c06\u5176\u6388\u4e88\u8c03\u7528\u65b9\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u7531createWriteRequest()\u6388\u4e88\u7684\u5a92\u4f53 URI \u73b0\u5728\u652f\u6301File&nbsp;\u7c7b\u4e2d\u7684 API\u3002\u8fd9\u4e9b API \u63d0\u4f9b\u4e86\u8bfb\u53d6\u3001\u5199\u5165\u3001\u91cd\u547d\u540d\u548c\u5220\u9664\u6587\u4ef6\u7684\u529f\u80fd\u3002<\/p>\n<p>\u7f16\u8f91\uff1ayimen\uff0c\u5982\u82e5\u8f6c\u8f7d\uff0c\u8bf7\u6ce8\u660e\u51fa\u5904\uff1ahttps:\/\/www.yimenapp.com\/kb-yimen\/12725\/<\/p>\n<p>\u90e8\u5206\u5185\u5bb9\u6765\u81ea\u7f51\u7edc\u6295\u7a3f\uff0c\u5982\u6709\u4fb5\u6743\u8054\u7cfb\u7acb\u5220<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Android 12 \u5e94\u7528\u9002\u914d\u6307\u53572 \u65b0\u529f\u80fd\u548cAPI\u65b0\u529f\u80fd\u548cAPI3.1 \u7528\u4e8e\u63a5\u6536\u5185\u5bb9\u7684\u7edf\u4e00API\u5f53\u524d\uff0c\u7528\u6237\u66f4\u559c\u6b22\u56fe\u7247\u3001\u89c6\u9891\u7b49\u5bcc\u6709\u8868\u73b0\u529b\u7684\u5185\u5bb9\uff0c\u4f46\u5728\u5e94\u7528\u4e2d\u63d2\u5165\u548c\u79fb\u52a8\u5e76\u975e\u6613\u4e8b\u3002\u4e3a\u4e86\u4f7f\u5e94\u7528\u80fd\u591f\u8f7b\u677e\u5730\u63a5\u6536\u5bcc\u5a92\u4f53\u5185\u5bb9\uff0cAndroid 12 \u5f15\u5165\u4e86\u5168\u65b0\u7684\u7edf\u4e00 API\uff0c\u60a8\u53ef\u4ee5\u4ece\u4efb\u4f55\u53ef\u7528\u6765\u6e90\uff08\u526a\u8d34\u677f\u7c98\u8d34\u3001\u952e\u76d8\u6216\u62d6<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[113,1125,1162],"class_list":["post-1902","post","type-post","status-publish","format-standard","hentry","category-appshangjia","tag-api","tag-1125","tag-1162"],"_links":{"self":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/posts\/1902","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/comments?post=1902"}],"version-history":[{"count":0,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/posts\/1902\/revisions"}],"wp:attachment":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/media?parent=1902"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/categories?post=1902"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/tags?post=1902"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}