<tfoot id='fVsER'></tfoot>
    <i id='fVsER'><tr id='fVsER'><dt id='fVsER'><q id='fVsER'><span id='fVsER'><b id='fVsER'><form id='fVsER'><ins id='fVsER'></ins><ul id='fVsER'></ul><sub id='fVsER'></sub></form><legend id='fVsER'></legend><bdo id='fVsER'><pre id='fVsER'><center id='fVsER'></center></pre></bdo></b><th id='fVsER'></th></span></q></dt></tr></i><div id='fVsER'><tfoot id='fVsER'></tfoot><dl id='fVsER'><fieldset id='fVsER'></fieldset></dl></div>
    <legend id='fVsER'><style id='fVsER'><dir id='fVsER'><q id='fVsER'></q></dir></style></legend>

  • <small id='fVsER'></small><noframes id='fVsER'>

          <bdo id='fVsER'></bdo><ul id='fVsER'></ul>
      1. Firebase 控制台:如何为通知指定 click_action

        Firebase console: How to specify click_action for notifications(Firebase 控制台:如何为通知指定 click_action)

      2. <small id='s6sCa'></small><noframes id='s6sCa'>

          • <tfoot id='s6sCa'></tfoot>
            <legend id='s6sCa'><style id='s6sCa'><dir id='s6sCa'><q id='s6sCa'></q></dir></style></legend>

                <bdo id='s6sCa'></bdo><ul id='s6sCa'></ul>

                  <i id='s6sCa'><tr id='s6sCa'><dt id='s6sCa'><q id='s6sCa'><span id='s6sCa'><b id='s6sCa'><form id='s6sCa'><ins id='s6sCa'></ins><ul id='s6sCa'></ul><sub id='s6sCa'></sub></form><legend id='s6sCa'></legend><bdo id='s6sCa'><pre id='s6sCa'><center id='s6sCa'></center></pre></bdo></b><th id='s6sCa'></th></span></q></dt></tr></i><div id='s6sCa'><tfoot id='s6sCa'></tfoot><dl id='s6sCa'><fieldset id='s6sCa'></fieldset></dl></div>
                    <tbody id='s6sCa'></tbody>
                  本文介绍了Firebase 控制台:如何为通知指定 click_action的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我实现了 Firebase 并测试了 Firebase 通知.当应用程序在前台时我没有问题,我实现了一个扩展 FirebaseMessagingService 的服务并处理 onMessageReceived

                  I implemented Firebase and testing the Firebase notifications. When the app is in the foreground I don't have problems, I implemented a service that extends FirebaseMessagingService and handle the message and data in onMessageReceived

                  当应用程序处于后台时我遇到问题,我想发送一个通知以打开特定活动并执行我计划执行的操作,而不仅仅是打开应用程序.

                  I have problems when the app is in background, I would like to send a notification that opens a specific activity and does what I schedule to do, not just opening the App.

                  我按照 Firebase 指南中的说明进行操作,但无法启动特定活动.

                  I did as described on the Firebase guide, but I'm not able to start the specific activity.

                  这里是清单:

                  <activity android:name=".BasicNotificationActivity">
                              <intent-filter>
                                  <action android:name="OPEN_ACTIVITY_1" />
                                  <category android:name="android.intent.category.DEFAULT" />
                              </intent-filter>
                          </activity>
                  

                  这里是 Firebase 控制台.我必须在这些字段中写什么才能打开我的BasicNotificationActivity"?

                  And here the Firebase Console. What do I have to write in those fields to open my "BasicNotificationActivity"?

                  推荐答案

                  这是这个问题的重复:Firebase FCM 通知 click_action 有效负载

                  但是这个问题的作者接受的答案只是表明 Firebase 控制台是不可能的,但它是 - 有一个简单的解决方法.这个 diidu 的回答对同一问题的解释解释了我将使用的解决方法.

                  But the answer that was accepted by the author of this question just states that it is not possible with Firebase Console, but it is - with an easy workaround. This answer by diidu to the same question explains the workaround I would use.

                  更新:
                  详细说明他的答案:

                  UPDATE:
                  To elaborate on his answer:

                  添加一个辅助类(或以某种方式实现 startActivity() 方法):

                  Add a helper class (or implement startActivity() method somehow):

                  public class ClickActionHelper {
                      public static void startActivity(String className, Bundle extras, Context context){
                          Class cls;
                          try {
                              cls = Class.forName(className);
                          }catch(ClassNotFoundException e){
                              //means you made a wrong input in firebase console
                          }
                          Intent i = new Intent(context, cls);
                          i.putExtras(extras);
                          context.startActivity(i);
                      }
                  }
                  

                  在应用的启动器活动中,调用一个方法来检查 onCreate()onNewIntent() 中的任何新意图 (onNewIntent() 仅在使用单顶标志启动 Activity 时才调用而不是 onCreate()):

                  In the launcher-activity of your app, call a mehtod to check any new intents in onCreate() and onNewIntent() (onNewIntent() is only called instead of onCreate() if Activity is launched with single-top flag):

                  @Override
                  protected void onCreate(Bundle bundle) {
                      [...]
                      checkIntent(getIntent());
                   }
                  
                  @Override
                  protected void onNewIntent(Intent intent) {
                      super.onNewIntent(intent);
                      [...]
                      checkIntent(intent);
                  }
                  
                  public void checkIntent(Intent intent) {
                         if (intent.hasExtra("click_action")) {
                          ClickActionHelper.startActivity(intent.getStringExtra("click_action"), intent.getExtras(), this);
                         }
                  }
                  

                  而在onMessageReceived()中:

                   public void onMessageReceived(RemoteMessage remoteMessage) {
                       Map<String, String> data = remoteMessage.getData();        
                       if (data.containsKey("click_action")) {
                           ClickActionHelper.startActivity(data.get("click_action"), null, this);
                       }
                   }
                  

                  要使用 firebase 控制台发送通知,请将键值对作为自定义数据,如下所示:

                  To send a notification with firebase console, put a key-value-pair as custom data like this:

                  Key: click_action
                  Value: <fully qualified classname of your activity>
                  

                  现在,当收到并点击通知时,它将打开您的活动.如果您的应用程序在前台,它也会立即更改为活动 - 询问用户是否想进入此活动可能会很好(通过在 onMessageReceived() 中显示一个对话框).

                  Now when a notification is received and clicked on, it will open your activity. If your app is in foreground, it will also immediately change to the activity - it would probably be good to ask the user if he wants to go to this activity or not (by showing a dialog in onMessageReceived()).

                  这篇关于Firebase 控制台:如何为通知指定 click_action的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)
                  cocos2d-android: how to display score(cocos2d-android:如何显示分数)
                  Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
                  SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
                  Android file copy(安卓文件拷贝)
                  Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)

                  <small id='ENQfH'></small><noframes id='ENQfH'>

                  <i id='ENQfH'><tr id='ENQfH'><dt id='ENQfH'><q id='ENQfH'><span id='ENQfH'><b id='ENQfH'><form id='ENQfH'><ins id='ENQfH'></ins><ul id='ENQfH'></ul><sub id='ENQfH'></sub></form><legend id='ENQfH'></legend><bdo id='ENQfH'><pre id='ENQfH'><center id='ENQfH'></center></pre></bdo></b><th id='ENQfH'></th></span></q></dt></tr></i><div id='ENQfH'><tfoot id='ENQfH'></tfoot><dl id='ENQfH'><fieldset id='ENQfH'></fieldset></dl></div>
                    <tbody id='ENQfH'></tbody>

                      <legend id='ENQfH'><style id='ENQfH'><dir id='ENQfH'><q id='ENQfH'></q></dir></style></legend>

                        • <bdo id='ENQfH'></bdo><ul id='ENQfH'></ul>

                          1. <tfoot id='ENQfH'></tfoot>