{"id":802,"date":"2020-10-12T11:00:24","date_gmt":"2020-10-12T03:00:24","guid":{"rendered":"https:\/\/badgameshow.com\/fly\/?p=802"},"modified":"2021-01-05T17:33:01","modified_gmt":"2021-01-05T09:33:01","slug":"android-%e8%87%aa%e5%ae%9a%e7%be%a9scheme-%e8%b7%b3%e8%bd%89%e5%88%b0%e6%8c%87%e5%ae%9a%e7%9a%84activity","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/fly\/android-%e8%87%aa%e5%ae%9a%e7%be%a9scheme-%e8%b7%b3%e8%bd%89%e5%88%b0%e6%8c%87%e5%ae%9a%e7%9a%84activity\/","title":{"rendered":"Android \u81ea\u5b9a\u7fa9scheme \u8df3\u8f49\u5230\u6307\u5b9a\u7684Activity Deep Link"},"content":{"rendered":"<h4>1.\u5728Manifests\u8072\u660e\u6307\u5b9a\u7684scheme<\/h4>\n<pre><code class=\"language-XML line-numbers\">\/\/\u8a3b\u518a(test:\/\/register)\n&lt;activity android:name=\".RegisterActivity\"&gt;\n    &lt;intent-filter&gt;\n         &lt;action android:name=\"android.intent.action.VIEW\" \/&gt;\n\n         &lt;category android:name=\"android.intent.category.DEFAULT\" \/&gt;\n         &lt;category android:name=\"android.intent.category.BROWSABLE\" \/&gt;\n\n         &lt;data\n              android:host=\"register\"\n              android:scheme=\"test\" \/&gt;\n    &lt;\/intent-filter&gt;\n&lt;\/activity&gt;\n\/\/\u767b\u5165(test:\/\/login)\n&lt;activity android:name=\".LoginActivity\"&gt;\n     &lt;intent-filter&gt;\n           &lt;action android:name=\"android.intent.action.VIEW\" \/&gt;\n\n           &lt;category android:name=\"android.intent.category.DEFAULT\" \/&gt;\n           &lt;category android:name=\"android.intent.category.BROWSABLE\" \/&gt;\n\n           &lt;data\n                android:host=\"login\"\n                android:scheme=\"test\" \/&gt;\n      &lt;\/intent-filter&gt;\n&lt;\/activity&gt;\n\/\/\u9996\u9801(test:\/\/home)\n&lt;activity android:name=\".MainActivity\"&gt;\n       &lt;intent-filter&gt;\n            &lt;action android:name=\"android.intent.action.MAIN\" \/&gt;\n\n            &lt;category android:name=\"android.intent.category.LAUNCHER\" \/&gt;\n       &lt;\/intent-filter&gt;\n\n       &lt;intent-filter&gt;\n             &lt;action android:name=\"android.intent.action.VIEW\" \/&gt;\n\n             &lt;category android:name=\"android.intent.category.DEFAULT\" \/&gt;\n             &lt;category android:name=\"android.intent.category.BROWSABLE\" \/&gt;\n\n             &lt;data\n                  android:host=\"home\"\n                  android:scheme=\"test\" \/&gt;\n       &lt;\/intent-filter&gt;\n&lt;\/activity&gt;\n<\/code><\/pre>\n<h4>2.\u53d6\u5f97url\u50b3\u904e\u4f86\u7684\u53c3\u6578<\/h4>\n<h5>test:\/\/login?account=tony123<\/h5>\n<pre><code class=\"language-Kotlin line-numbers\">val intent = intent\nval uri = intent.data\n\nuri?.also {\n    host.text = it.host             \/\/login\n    data.text = intent.dataString   \/\/test:\/\/login?account=tony123\n    account.text = it.getQueryParameter(\"account\")  \/\/tony123\n}\n<\/code><\/pre>\n<h3>\u53e6\u4e00\u7a2e\u65b9\u5f0f<\/h3>\n<h4>1.\u8fd4\u56de\u81ea\u5df1APP\u4e0d\u662f\u700f\u89bd\u5668(\u8a2d\u7f6eparentActivityName)<\/h4>\n<pre><code class=\"language-XML line-numbers\">&lt;activity android:name=\".RegisterActivity\"\n    android:parentActivityName=\".MainActivity\"\/&gt;\n\n&lt;activity android:name=\".LoginActivity\"\n    android:parentActivityName=\".MainActivity\"\/&gt;\n\n&lt;activity android:name=\".MainActivity\"&gt;\n    &lt;intent-filter&gt;\n        &lt;action android:name=\"android.intent.action.MAIN\" \/&gt;\n\n        &lt;category android:name=\"android.intent.category.LAUNCHER\" \/&gt;\n    &lt;\/intent-filter&gt;\n\n    &lt;intent-filter&gt;\n         &lt;action android:name=\"android.intent.action.VIEW\" \/&gt;\n\n         &lt;category android:name=\"android.intent.category.DEFAULT\" \/&gt;\n         &lt;category android:name=\"android.intent.category.BROWSABLE\" \/&gt;\n\n         &lt;data\n                    android:scheme=\"test\" \/&gt;\n     &lt;\/intent-filter&gt;\n&lt;\/activity&gt;\n<\/code><\/pre>\n<h4>2.MainActivity\u63a7\u5236\u8df3\u8f49\u7684\u6982\u5ff5<\/h4>\n<pre><code class=\"language-Kotlin line-numbers\">val host = intent.data?.host\n\n\nif (host.equals(\"login\")) {\n      \/\/header(\"Location: test:\/\/login\");\n      TaskStackBuilder.create(this)\n            .addParentStack(LoginActivity::class.java)\n            .addNextIntent(Intent(this, LoginActivity::class.java))\n            .startActivities()\n} else if (host.equals(\"register\")) {\n       \/\/header(\"Location: test:\/\/register\");\n       TaskStackBuilder.create(this)\n            .addParentStack(RegisterActivity::class.java)\n            .addNextIntent(Intent(this, RegisterActivity::class.java))\n            .startActivities()\n}\n<\/code><\/pre>\n\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>1.\u5728Manifests\u8072\u660e\u6307\u5b9a\u7684scheme \/\/\u8a3b\u518a(test:\/\/register) &lt;activ &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[5],"tags":[13,126,21],"class_list":["post-802","post","type-post","status-publish","format-standard","hentry","category-android","tag-android","tag-deep-link","tag-scheme"],"_links":{"self":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/802","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/comments?post=802"}],"version-history":[{"count":2,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/802\/revisions"}],"predecessor-version":[{"id":1045,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/802\/revisions\/1045"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/media?parent=802"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/categories?post=802"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/tags?post=802"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}