{"id":1268,"date":"2023-03-18T09:57:18","date_gmt":"2023-03-18T01:57:18","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1268"},"modified":"2023-04-29T09:24:23","modified_gmt":"2023-04-29T01:24:23","slug":"android-access-firebase-push-does-not-execute-onmessage-received-method","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/18\/android-access-firebase-push-does-not-execute-onmessage-received-method\/","title":{"rendered":"Android\u63a5\u5165Firebase\u63a8\u9001\u4e0d\u6267\u884conMessageReceived\u65b9\u6cd5"},"content":{"rendered":"<p>\u53c2\u8003\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/firebase.google.com\/docs\/cloud-messaging\/android\/receive\">https:\/\/firebase.google.com\/docs\/cloud-messaging\/android\/receive<\/a><br \/>\n\u53c2\u8003\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/firebase.google.com\/docs\/cloud-messaging\/http-server-ref\">https:\/\/firebase.google.com\/docs\/cloud-messaging\/http-server-ref<\/a><\/p>\n<p>Android\u63a5\u5165Firebase\u63a8\u9001\uff0c\u5f53\u5e94\u7528\u5904\u4e8e\u540e\u53f0\u72b6\u6001\u65f6\u4e0d\u6267\u884cFirebaseMessagingService\u7684onMessageReceived\u65b9\u6cd5<\/p>\n<p><!-- more --><\/p>\n<p>FCM\u5904\u7406\u540e\u53f0\u5e94\u7528\u4e2d\u6d88\u606f\u7684\u673a\u5236\uff1a<\/p>\n<p>\u5f53\u60a8\u7684\u5e94\u7528\u4f4d\u4e8e\u540e\u53f0\u65f6\uff0cAndroid \u4f1a\u5c06\u901a\u77e5\u6d88\u606f\u8f6c\u53d1\u81f3\u7cfb\u7edf\u6258\u76d8\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u7528\u6237\u70b9\u51fb\u901a\u77e5\u65f6\u5c06\u6253\u5f00\u5e94\u7528\u542f\u52a8\u7ec4\u4ef6\u3002<\/p>\n<p>\u8fd9\u4f1a\u5305\u62ec\u540c\u65f6\u5305\u542b\u901a\u77e5\u548c\u6570\u636e\u8d1f\u8f7d\u7684\u6d88\u606f\u3002\u5728\u8fd9\u4e9b\u60c5\u51b5\u4e0b\uff0c\u901a\u77e5\u5c06\u4f20\u9012\u81f3\u8bbe\u5907\u7684\u7cfb\u7edf\u6258\u76d8\uff0c\u6570\u636e\u8d1f\u8f7d\u5c06\u5728\u5e94\u7528\u542f\u52a8\u7ec4\u4ef6 Activity \u7684 Intent \u7684 extra \u4e2d\u4f20\u9012\u3002<\/p>\n<p>\u5982\u679c\u5e0c\u671b\u6253\u5f00\u60a8\u7684\u5e94\u7528\u548c\u6267\u884c\u7279\u5b9a\u64cd\u4f5c\uff0c\u8bf7\u5728\u901a\u77e5\u8d1f\u8f7d\u4e2d\u8bbe\u7f6e click_action\uff0c\u7136\u540e\u5c06\u5176\u6620\u5c04\u81f3\u60a8\u60f3\u542f\u52a8\u7684 Activity \u4e2d\u7684 Intent \u8fc7\u6ee4\u5668\u3002\u4f8b\u5982\uff0c\u5c06 click_action \u8bbe\u4e3a FCM_OPEN_ORDER_LIST_ACTIVITY \u4f1a\u89e6\u53d1\u7c7b\u4f3c\u4e8e\u5982\u4e0b\u7684 Intent \u8fc7\u6ee4\u5668\uff1a<\/p>\n<pre><code>&lt;intent-filter&gt;\n  &lt;action android:name=&quot;FCM_OPEN_ORDER_LIST_ACTIVITY&quot; \/&gt;\n  &lt;category android:name=&quot;android.intent.category.DEFAULT&quot; \/&gt;\n&lt;\/intent-filter&gt;<\/code><\/pre>\n<p>\u670d\u52a1\u7aef\u63a8\u9001notification\u53c2\u6570\u914d\u7f6eclick_action\u5b57\u6bb5<\/p>\n<pre><code class=\"language-javascript\">var payload = {\n  \/\/to: token,\n  to: &#039;\/topics\/activity&#039;,\n  notification: {\n    body: &quot;\u901a\u77e5\u5185\u5bb9&quot;,\n    title: &quot;Firebase Cloud Message&quot;,\n    data: {&#039;type&#039;: &#039;test&#039;, &#039;path&#039;: &#039;\/order_list&#039;},\n    click_action: &#039;FCM_OPEN_ORDER_LIST_ACTIVITY&#039;\n  },\n  data: {&#039;type&#039;: &#039;test&#039;, &#039;path&#039;: &#039;\/order_list&#039;, &#039;content&#039;: &#039;AppBlog.CN&#039;}\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u53c2\u8003\uff1ahttps:\/\/firebase.google.com\/docs\/cloud-messaging\/and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[316],"class_list":["post-1268","post","type-post","status-publish","format-standard","hentry","category-android-basic","tag-firebase"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1268","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1268"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1268\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}