{"id":13,"date":"2025-09-04T22:15:44","date_gmt":"2025-09-04T14:15:44","guid":{"rendered":"https:\/\/www.yun-games.com\/?p=13"},"modified":"2025-09-04T22:15:47","modified_gmt":"2025-09-04T14:15:47","slug":"%e5%a6%82%e4%bd%95%e5%ae%89%e5%85%a8%e7%9a%84%e4%bd%bf%e7%94%a8%e9%9a%90%e5%bc%8fintent","status":"publish","type":"post","link":"https:\/\/www.yun-games.com\/?p=13","title":{"rendered":"\u5982\u4f55\u5b89\u5168\u7684\u4f7f\u7528\u9690\u5f0fintent"},"content":{"rendered":"\n<p>@SuppressLint(&#8220;UnsafeImplicitIntentLaunch&#8221;)\u662f\u4ec0\u4e48<br><code>@SuppressLint(\"UnsafeImplicitIntentLaunch\")<\/code> \u662f Android Lint \u7ed9\u4f60\u7684\u8b66\u544a\u6291\u5236\u6ce8\u89e3\uff0c\u51fa\u73b0\u5728\u4f60\u5199 \u9690\u5f0f Intent \u7684\u5730\u65b9\u65f6\uff0cLint \u4f1a\u5728 IDE \u91cc\u63d0\u793a\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Unsafe implicit intent launch: Intent could be intercepted or hijacked.<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u2705 \u4ec0\u4e48\u662f \u201cUnsafeImplicitIntentLaunch\u201d<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f60\u521b\u5efa\u4e86\u4e00\u4e2a \u9690\u5f0f Intent\uff08\u6ca1\u6709 <code>setComponent<\/code> \/ <code>setClass<\/code> \/ <code>setPackage<\/code>\uff09\u3002<\/li>\n\n\n\n<li>Android \u7cfb\u7edf\u4f1a\u5728 \u6240\u6709 \u5df2\u5b89\u88c5\u4e14 <code>exported=true<\/code> \u7684\u7ec4\u4ef6\u91cc\u505a\u5339\u914d\u3002<\/li>\n\n\n\n<li>\u6076\u610f App \u53ef\u4ee5\u63d0\u524d\u6ce8\u518c\u540c\u6837\u7684 <code>&lt;intent-filter><\/code> \u6765 \u62e6\u622a \u4f60\u7684 Intent\uff0c\u5bfc\u81f4\uff1a<\/li>\n\n\n\n<li>\u6570\u636e\u88ab\u7a83\u542c\u6216\u7be1\u6539<\/li>\n\n\n\n<li>\u7528\u6237\u88ab\u5f15\u5bfc\u5230\u9493\u9c7c\u754c\u9762<\/li>\n\n\n\n<li>\u670d\u52a1 \/ \u5e7f\u64ad\u88ab\u5192\u724c\u5b9e\u73b0<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u2705 \u5b98\u65b9\u63a8\u8350\u7684 3 \u79cd\u5b89\u5168\u5199\u6cd5\uff08\u4e0d\u7528\u52a0\u6ce8\u89e3\uff09<\/p>\n\n\n\n<p>\u65b9\u6848 \u4ee3\u7801\u793a\u4f8b \u573a\u666f<br>\u663e\u5f0f Intent\uff08\u6700\u7b80\u5355\uff09 <code>new Intent(this, TargetActivity.class)<\/code> \u53ea\u5728 \u672c App \u5185\u90e8\u8df3\u8f6c<br>\u7ed9\u9690\u5f0f Intent \u52a0 package <code>intent.setPackage(\"com.xxx.yyy\")<\/code> \u660e\u786e\u6307\u5b9a \u67d0\u4e2a App<br>Resolve &amp; \u767d\u540d\u5355 \u5148 <code>PackageManager.resolveActivity()<\/code>\uff0c\u518d\u6bd4\u5bf9 \u7b7e\u540d \/ \u5305\u540d \u540e\u624d\u542f\u52a8 \u8c03\u7528 \u7b2c\u4e09\u65b9 App\uff0c\u4f46\u53c8\u6015\u52ab\u6301<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u2705 \u4e3a\u4ec0\u4e48\u6709\u4eba\u52a0 <code>@SuppressLint<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4e34\u65f6\u7ed5\u8fc7\uff1a\u5f00\u53d1\u8005\u61d2\u5f97\u6539\u6216\u786e\u5b9a\u73af\u5883\u53ef\u63a7\uff08\u6bd4\u5982\u5185\u90e8\u6d4b\u8bd5 App\uff09\u3002<\/li>\n\n\n\n<li>\u8bef\u62a5\uff1a\u67d0\u4e9b\u573a\u666f\u786e\u5b9e\u5b89\u5168\uff0c\u4f46 Lint \u65e0\u6cd5\u8bc6\u522b\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u2705 \u4e00\u53e5\u8bdd\u603b\u7ed3<\/p>\n\n\n\n<p>\u52a0 <code>@SuppressLint(\"UnsafeImplicitIntentLaunch\")<\/code> \u53ea\u662f\u201c\u63a9\u8033\u76d7\u94c3\u201d\uff1b\u771f\u6b63\u5b89\u5168\u7684\u662f\uff1a\u7528\u663e\u5f0f Intent \u6216 <code>setPackage()<\/code> \u660e\u786e\u76ee\u6807\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>@SuppressLint(&#8220;UnsafeImplicitIntentLaunch&#8221;) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.yun-games.com\/index.php?rest_route=\/wp\/v2\/posts\/13","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yun-games.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yun-games.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yun-games.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yun-games.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13"}],"version-history":[{"count":1,"href":"https:\/\/www.yun-games.com\/index.php?rest_route=\/wp\/v2\/posts\/13\/revisions"}],"predecessor-version":[{"id":14,"href":"https:\/\/www.yun-games.com\/index.php?rest_route=\/wp\/v2\/posts\/13\/revisions\/14"}],"wp:attachment":[{"href":"https:\/\/www.yun-games.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yun-games.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yun-games.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}