推送网址无法打开

时间:2018-01-26 14:24:29

标签: java android json android-intent push-notification

我有一个非常基本的PushNotification代码,它应该在没有URL时打开一个活动,并在有URL时打开一个URL。但是在收到通知时它不会打开URL。

以下代码

public class MyFirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService {
  private static final String TAG = "FirebaseMessagingServic";

  public MyFirebaseMessagingService() {}

  @Override
  public void onMessageReceived(RemoteMessage remoteMessage) {
    if (remoteMessage.getData().size() > 0) {
      Log.d(TAG, "Message data payload: " + remoteMessage.getData());
      try {
        JSONObject data = new JSONObject(remoteMessage.getData());
        String jsonMessage = data.getString("extra_information");
        Log.d(TAG, "onMessageReceived: \n" +
          "Extra Information: " + jsonMessage);
      } catch (JSONException e) {
        e.printStackTrace();
      }
    }
    if (remoteMessage.getNotification() != null) {
      String title = remoteMessage.getNotification().getTitle();
      String message = remoteMessage.getNotification().getBody();
      String click_action = remoteMessage.getNotification().getClickAction();
      Uri uri = remoteMessage.getNotification().getLink();

      Log.d(TAG, "Message Notification Title: " + title);
      Log.d(TAG, "Message Notification Body: " + message);
      Log.d(TAG, "Message Notification click_action: " + click_action);
      Log.d(TAG, "Message Notification url: " + uri);

    }
  }

  @Override
  public void onDeletedMessages() {}

  private void sendNotification(String title, String messageBody, String click_action, Uri uri) {
    Intent intent;
    if (uri != null) {
      intent = new Intent(Intent.ACTION_VIEW);
      intent.setData(uri));
    } else {
      intent = new Intent(click_action);
    }

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */ , intent,
      0);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
      .setSmallIcon(R.drawable.app_logo_final)
      .setContentTitle("PushNotification")
      .setContentText(messageBody)
      .setAutoCancel(true)
      .setSound(defaultSoundUri)
      .setContentIntent(pendingIntent);
    NotificationManager notificationManager =
      (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */ , notificationBuilder.build());
  }
}

我发送的通知是这样的:

{
  "to": "/topics/NEWS",
  "data": {
    "extra_information": "This is some extra information"
  },
  "notification": {
    "title": "Test title: http://www.google.com",
    "body": "Test body: http://www.google.com",
    "uri": "http://www.google.com",
    "click_action": "MAIN_PAGE"
  }
}

受其他主题的启发,我有:

  1. 尝试设置Uri.parse("http://www.google.com"),检查它是否会在任何条件下打开www.google.com,但它不起作用。
  2. 已添加sendNotification(title, message, click_action, uri);。没用?
  3. 删除了if条件并仅设置intent = new intent(Intent.ACTION_VIEW); intent.setData(uri));。没用?
  4. 使用网址替换click_action的ACTIVITY。没用?
  5. 添加了startActivity(intent)
  6. 的额外行

    在我的清单中,我有:

    <activity android: name = ".MainScreen">
      <intent-filter>
        <action android: name = "android.intent.action.MAIN"/>
        <category android: name = "android.intent.category.LAUNCHER"/>
      </intent-filter> 
      <intent-filter>
        <action android: name = "MAIN_PAGE"/>
        <category android: name = "android.intent.category.DEFAULT"/>
      </intent-filter>
    

    它现在做的是打开这个MAIN_PAGE。我是否需要在Manifest中添加其他内容以打开链接?

    编辑:我刚刚发现在邮差中我需要“链接”而不是“uri”。尽管如此,这并没有解决问题。通过在后台运行应用程序查看Logcat,当我点击通知时,我有了这个:

    01 - 26 16: 51: 28.668 1395 - 1395 / com.tabian.firebasepushnotifications I / dalvikvm: Could not find method android.view.Window$Callback.onPointerCaptureChanged, referenced from method android.support.v7.view.WindowCallbackWrapper.onPointerCaptureChanged
    01 - 26 16: 51: 28.668 1395 - 1395 / com.tabian.firebasepushnotifications W / dalvikvm: VFY: unable to resolve interface method 16186: Landroid / view / Window$Callback;.onPointerCaptureChanged(Z) V
    01 - 26 16: 51: 28.668 1395 - 1395 / com.tabian.firebasepushnotifications D / dalvikvm: VFY: replacing opcode 0x72 at 0x0002
    01 - 26 16: 51: 28.668 1395 - 1395 / com.tabian.firebasepushnotifications I / dalvikvm: Could not find method android.view.Window$Callback.onProvideKeyboardShortcuts, referenced from method android.support.v7.view.WindowCallbackWrapper.onProvideKeyboardShortcuts
    01 - 26 16: 51: 28.668 1395 - 1395 / com.tabian.firebasepushnotifications W / dalvikvm: VFY: unable to resolve interface method 16188: Landroid / view / Window$Callback;.onProvideKeyboardShortcuts(Ljava / util / List; Landroid / view / Menu; I) V
    01 - 26 16: 51: 28.668 1395 - 1395 / com.tabian.firebasepushnotifications D / dalvikvm: VFY: replacing opcode 0x72 at 0x0002
    01 - 26 16: 51: 28.668 1395 - 1395 / com.tabian.firebasepushnotifications W / dalvikvm: VFY: unable to find class referenced in signature(Landroid / view / SearchEvent;)
    01 - 26 16: 51: 28.668 1395 - 1395 / com.tabian.firebasepushnotifications I / dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
    01 - 26 16: 51: 28.668 1395 - 1395 / com.tabian.firebasepushnotifications W / dalvikvm: VFY: unable to resolve interface method 16190: Landroid / view / Window$Callback;.onSearchRequested(Landroid / view / SearchEvent;) Z
    01 - 26 16: 51: 28.668 1395 - 1395 / com.tabian.firebasepushnotifications D / dalvikvm: VFY: replacing opcode 0x72 at 0x0002
    01 - 26 16: 51: 28.668 1395 - 1395 / com.tabian.firebasepushnotifications I / dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
    01 - 26 16: 51: 28.668 1395 - 1395 / com.tabian.firebasepushnotifications W / dalvikvm: VFY: unable to resolve interface method 16194: Landroid / view / Window$Callback;.onWindowStartingActionMode(Landroid / view / ActionMode$Callback; I) Landroid / view / ActionMode;
    01 - 26 16: 51: 28.668 1395 - 1395 / com.tabian.firebasepushnotifications D / dalvikvm: VFY: replacing opcode 0x72 at 0x0002
    01 - 26 16: 51: 28.678 1395 - 1395 / com.tabian.firebasepushnotifications I / dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations
    01 - 26 16: 51: 28.678 1395 - 1395 / com.tabian.firebasepushnotifications W / dalvikvm: VFY: unable to resolve virtual method 811: Landroid / content / res / TypedArray;.getChangingConfigurations() I
    01 - 26 16: 51: 28.678 1395 - 1395 / com.tabian.firebasepushnotifications D / dalvikvm: VFY: replacing opcode 0x6e at 0x0002
    01 - 26 16: 51: 28.678 1395 - 1395 / com.tabian.firebasepushnotifications I / dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
    01 - 26 16: 51: 28.678 1395 - 1395 / com.tabian.firebasepushnotifications W / dalvikvm: VFY: unable to resolve virtual method 833: Landroid / content / res / TypedArray;.getType(I) I
    01 - 26 16: 51: 28.678 1395 - 1395 / com.tabian.firebasepushnotifications D / dalvikvm: VFY: replacing opcode 0x6e at 0x0008
    01 - 26 16: 51: 28.688 1395 - 1395 / com.tabian.firebasepushnotifications V / FA: onActivityCreated
    01 - 26 16: 51: 28.748 1395 - 1395 / com.tabian.firebasepushnotifications I / dalvikvm: Could not find method android.widget.FrameLayout.startActionModeForChild, referenced from method android.support.v7.widget.ActionBarContainer.startActionModeForChild
    01 - 26 16: 51: 28.748 1395 - 1395 / com.tabian.firebasepushnotifications W / dalvikvm: VFY: unable to resolve virtual method 16655: Landroid / widget / FrameLayout;.startActionModeForChild(Landroid / view / View; Landroid / view / ActionMode$Callback; I) Landroid / view / ActionMode;
    01 - 26 16: 51: 28.748 1395 - 1395 / com.tabian.firebasepushnotifications D / dalvikvm: VFY: replacing opcode 0x6f at 0x0002
    01 - 26 16: 51: 28.758 1395 - 1395 / com.tabian.firebasepushnotifications I / dalvikvm: Could not find method android.content.Context.getColorStateList, referenced from method android.support.v7.content.res.AppCompatResources.getColorStateList
    01 - 26 16: 51: 28.758 1395 - 1395 / com.tabian.firebasepushnotifications W / dalvikvm: VFY: unable to resolve virtual method 560: Landroid / content / Context;.getColorStateList(I) Landroid / content / res / ColorStateList;
    01 - 26 16: 51: 28.758 1395 - 1395 / com.tabian.firebasepushnotifications D / dalvikvm: VFY: replacing opcode 0x6e at 0x0006
    01 - 26 16: 51: 28.768 1395 - 1395 / com.tabian.firebasepushnotifications W / dalvikvm: VFY: unable to find class referenced in signature(Landroid / graphics / drawable / Icon;)
    01 - 26 16: 51: 28.768 1395 - 1395 / com.tabian.firebasepushnotifications I / dalvikvm: Could not find method android.widget.ImageButton.setImageIcon, referenced from method android.support.v7.widget.AppCompatImageButton.setImageIcon
    01 - 26 16: 51: 28.768 1395 - 1395 / com.tabian.firebasepushnotifications W / dalvikvm: VFY: unable to resolve virtual method 16678: Landroid / widget / ImageButton;.setImageIcon(Landroid / graphics / drawable / Icon;) V
    01 - 26 16: 51: 28.768 1395 - 1395 / com.tabian.firebasepushnotifications D / dalvikvm: VFY: replacing opcode 0x6f at 0x0000
    01 - 26 16: 51: 28.768 1395 - 1395 / com.tabian.firebasepushnotifications I / dalvikvm: Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawable
    01 - 26 16: 51: 28.768 1395 - 1395 / com.tabian.firebasepushnotifications W / dalvikvm: VFY: unable to resolve virtual method 774: Landroid / content / res / Resources;.getDrawable(ILandroid / content / res / Resources$Theme;) Landroid / graphics / drawable / Drawable;
    01 - 26 16: 51: 28.768 1395 - 1395 / com.tabian.firebasepushnotifications D / dalvikvm: VFY: replacing opcode 0x6e at 0x0002
    01 - 26 16: 51: 28.768 1395 - 1395 / com.tabian.firebasepushnotifications I / dalvikvm: Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawableForDensity
    01 - 26 16: 51: 28.768 1395 - 1395 / com.tabian.firebasepushnotifications W / dalvikvm: VFY: unable to resolve virtual method 776: Landroid / content / res / Resources;.getDrawableForDensity(IILandroid / content / res / Resources$Theme;) Landroid / graphics / drawable / Drawable;
    01 - 26 16: 51: 28.768 1395 - 1395 / com.tabian.firebasepushnotifications D / dalvikvm: VFY: replacing opcode 0x6e at 0x0002
    01 - 26 16: 51: 28.778 1395 - 1395 / com.tabian.firebasepushnotifications E / dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
    01 - 26 16: 51: 28.778 1395 - 1395 / com.tabian.firebasepushnotifications W / dalvikvm: VFY: unable to resolve instanceof 210(Landroid / graphics / drawable / RippleDrawable;) in Landroid / support / v7 / widget / AppCompatImageHelper;
    01 - 26 16: 51: 28.778 1395 - 1395 / com.tabian.firebasepushnotifications D / dalvikvm: VFY: replacing opcode 0x20 at 0x000c
    01 - 26 16: 51: 28.788 1395 - 1395 / com.tabian.firebasepushnotifications I / dalvikvm: Could not find method android.widget.TextView.getAutoSizeMaxTextSize, referenced from method android.support.v7.widget.AppCompatTextView.getAutoSizeMaxTextSize
    01 - 26 16: 51: 28.788 1395 - 1395 / com.tabian.firebasepushnotifications W / dalvikvm: VFY: unable to resolve virtual method 16974: Landroid / widget / TextView;.getAutoSizeMaxTextSize() I
    01 - 26 16: 51: 28.788 1395 - 1395 / com.tabian.firebasepushnotifications D / dalvikvm: VFY: replacing opcode 0x6f at 0x0006
    01 - 26 16: 51: 28.788 1395 - 1395 / com.tabian.firebasepushnotifications I / dalvikvm: Could not find method android.widget.TextView.getAutoSizeMinTextSize, referenced from method android.support.v7.widget.AppCompatTextView.getAutoSizeMinTextSize
    01 - 26 16: 51: 28.788 1395 - 1395 / com.tabian.firebasepushnotifications W / dalvikvm: VFY: unable to resolve virtual method 16975: Landroid / widget / TextView;.getAutoSizeMinTextSize() I
    01 - 26 16: 51: 28.788 1395 - 1395 / com.tabian.firebasepushnotifications D / dalvikvm: VFY: replacing opcode 0x6f at 0x0006
    01 - 26 16: 51: 28.798 1395 - 1395 / com.tabian.firebasepushnotifications I / dalvikvm: Could not find method android.widget.TextView.getAutoSizeStepGranularity, referenced from method android.support.v7.widget.AppCompatTextView.getAutoSizeStepGranularity
    01 - 26 16: 51: 28.798 1395 - 1395 / com.tabian.firebasepushnotifications W / dalvikvm: VFY: unable to resolve virtual method 16976: Landroid / widget / TextView;.getAutoSizeStepGranularity() I
    01 - 26 16: 51: 28.798 1395 - 1395 / com.tabian.firebasepushnotifications D / dalvikvm: VFY: replacing opcode 0x6f at 0x0006
    01 - 26 16: 51: 28.798 1395 - 1395 / com.tabian.firebasepushnotifications I / dalvikvm: Could not find method android.widget.TextView.getAutoSizeTextAvailableSizes, referenced from method android.support.v7.widget.AppCompatTextView.getAutoSizeTextAvailableSizes
    01 - 26 16: 51: 28.798 1395 - 1395 / com.tabian.firebasepushnotifications W / dalvikvm: VFY: unable to resolve virtual method 16977: Landroid / widget / TextView;.getAutoSizeTextAvailableSizes()[I 01 - 26 16: 51: 28.798 1395 - 1395 / com.tabian.firebasepushnotifications D / dalvikvm: VFY: replacing opcode 0x6f at 0x0006 01 - 26 16: 51: 28.798 1395 - 1395 / com.tabian.firebasepushnotifications I / dalvikvm: Could not find method android.widget.TextView.getAutoSizeTextType, referenced from method android.support.v7.widget.AppCompatTextView.getAutoSizeTextType 01 - 26 16: 51: 28.798 1395 - 1395 / com.tabian.firebasepushnotifications W / dalvikvm: VFY: unable to resolve virtual method 16978: Landroid / widget / TextView;.getAutoSizeTextType() I 01 - 26 16: 51: 28.798 1395 - 1395 / com.tabian.firebasepushnotifications D / dalvikvm: VFY: replacing opcode 0x6f at 0x0008 01 - 26 16: 51: 28.798 1395 - 1395 / com.tabian.firebasepushnotifications I / dalvikvm: Could not find method android.widget.TextView.setAutoSizeTextTypeUniformWithConfiguration, referenced from method android.support.v7.widget.AppCompatTextView.setAutoSizeTextTypeUniformWithConfiguration 01 - 26 16: 51: 28.798 1395 - 1395 / com.tabian.firebasepushnotifications W / dalvikvm: VFY: unable to resolve virtual method 17021: Landroid / widget / TextView;.setAutoSizeTextTypeUniformWithConfiguration(IIII) V 01 - 26 16: 51: 28.798 1395 - 1395 / com.tabian.firebasepushnotifications D / dalvikvm: VFY: replacing opcode 0x6f at 0x0006 01 - 26 16: 51: 28.798 1395 - 1395 / com.tabian.firebasepushnotifications I / dalvikvm: Could not find method android.widget.TextView.setAutoSizeTextTypeUniformWithPresetSizes, referenced from method android.support.v7.widget.AppCompatTextView.setAutoSizeTextTypeUniformWithPresetSizes 01 - 26 16: 51: 28.798 1395 - 1395 / com.tabian.firebasepushnotifications W / dalvikvm: VFY: unable to resolve virtual method 17022: Landroid / widget / TextView;.setAutoSizeTextTypeUniformWithPresetSizes([II) V 01 - 26 16: 51: 28.798 1395 - 1395 / com.tabian.firebasepushnotifications D / dalvikvm: VFY: replacing opcode 0x6f at 0x0006 01 - 26 16: 51: 28.798 1395 - 1395 / com.tabian.firebasepushnotifications I / dalvikvm: Could not find method android.widget.TextView.setAutoSizeTextTypeWithDefaults, referenced from method android.support.v7.widget.AppCompatTextView.setAutoSizeTextTypeWithDefaults 01 - 26 16: 51: 28.798 1395 - 1395 / com.tabian.firebasepushnotifications W / dalvikvm: VFY: unable to resolve virtual method 17023: Landroid / widget / TextView;.setAutoSizeTextTypeWithDefaults(I) V 01 - 26 16: 51: 28.798 1395 - 1395 / com.tabian.firebasepushnotifications D / dalvikvm: VFY: replacing opcode 0x6f at 0x0006 01 - 26 16: 51: 28.798 1395 - 1395 / com.tabian.firebasepushnotifications I / dalvikvm: Could not find method android.widget.TextView.getAutoSizeStepGranularity, referenced from method android.support.v7.widget.AppCompatTextHelper.loadFromAttributes 01 - 26 16: 51: 28.798 1395 - 1395 / com.tabian.firebasepushnotifications W / dalvikvm: VFY: unable to resolve virtual method 16976: Landroid / widget / TextView;.getAutoSizeStepGranularity() I 01 - 26 16: 51: 28.798 1395 - 1395 / com.tabian.firebasepushnotifications D / dalvikvm: VFY: replacing opcode 0x6e at 0x0197 01 - 26 16: 51: 28.808 1395 - 1395 / com.tabian.firebasepushnotifications I / dalvikvm: Could not find method android.text.StaticLayout$Builder.obtain, referenced from method android.support.v7.widget.AppCompatTextViewAutoSizeHelper.createStaticLayoutForMeasuring 01 - 26 16: 51: 28.808 1395 - 1395 / com.tabian.firebasepushnotifications W / dalvikvm: VFY: unable to resolve static method 15457: Landroid / text / StaticLayout$Builder;.obtain(Ljava / lang / CharSequence; IILandroid / text / TextPaint; I) Landroid / text / StaticLayout$Builder; 01 - 26 16: 51: 28.808 1395 - 1395 / com.tabian.firebasepushnotifications D / dalvikvm: VFY: replacing opcode 0x71 at 0x0014 01 - 26 16: 51: 28.828 1395 - 1409 / com.tabian.firebasepushnotifications V / FA: Connecting to remote service 01 - 26 16: 51: 28.848 1395 - 1409 / com.tabian.firebasepushnotifications V / FA: Activity resumed, time: 242636715 01 - 26 16: 51: 28.848 1395 - 1409 / com.tabian.firebasepushnotifications I / FA: Tag Manager is not found and thus will not be used 01 - 26 16: 51: 28.848 1395 - 1409 / com.tabian.firebasepushnotifications D / FA: Logging event(FE): screen_view(_vs), Bundle[{
            firebase_event_origin(_o) = auto,
            firebase_screen_class(_sc) = Main_Screen,
            firebase_screen_id(_si) = 6213183756703048966
          }] 01 - 26 16: 51: 28.858 1395 - 1395 / com.tabian.firebasepushnotifications I / Adreno - EGL: < qeglDrvAPI_eglInitialize: 381 >: EGL 1.4 QUALCOMM build: (CL3869936) OpenGL ES Shader Compiler Version: 17.01 .12.SPL Build Date: 03 / 03 / 14 Mon Local Branch: default Remote Branch:
          Local Patches:
          Reconstruct Branch:
          01 - 26 16: 51: 28.918 1395 - 1395 / com.tabian.firebasepushnotifications D / OpenGLRenderer: Enabling debug mode 0 01 - 26 16: 51: 28.948 1395 - 1395 / com.tabian.firebasepushnotifications W / dalvikvm: VFY: unable to find class referenced in signature(Landroid / graphics / drawable / Icon;) 01 - 26 16: 51: 28.948 1395 - 1395 / com.tabian.firebasepushnotifications I / dalvikvm: Could not find method android.widget.ImageView.setImageIcon, referenced from method android.support.v7.widget.AppCompatImageView.setImageIcon 01 - 26 16: 51: 28.948 1395 - 1395 / com.tabian.firebasepushnotifications W / dalvikvm: VFY: unable to resolve virtual method 16713: Landroid / widget / ImageView;.setImageIcon(Landroid / graphics / drawable / Icon;) V 01 - 26 16: 51: 28.948 1395 - 1395 / com.tabian.firebasepushnotifications D / dalvikvm: VFY: replacing opcode 0x6f at 0x0000 01 - 26 16: 51: 28.948 1395 - 1409 / com.tabian.firebasepushnotifications V / FA: Connection attempt already in progress 01 - 26 16: 51: 29.018 1395 - 1409 / com.tabian.firebasepushnotifications D / FA: Connected to remote service 01 - 26 16: 51: 29.018 1395 - 1409 / com.tabian.firebasepushnotifications V / FA: Processing queued up service tasks: 2 01 - 26 16: 51: 31.871 1395 - 1395 / com.tabian.firebasepushnotifications I / PersonaManager: getPersonaService() name persona_policy 01 - 26 16: 51: 31.881 1395 - 1395 / com.tabian.firebasepushnotifications V / FA: onActivityCreated 01 - 26 16: 51: 31.911 1395 - 1409 / com.tabian.firebasepushnotifications V / FA: Recording user engagement, ms: 2928 01 - 26 16: 51: 31.911 1395 - 1409 / com.tabian.firebasepushnotifications V / FA: Activity paused, time: 242639638 01 - 26 16: 51: 31.931 1395 - 1409 / com.tabian.firebasepushnotifications D / FA: Logging event(FE): user_engagement(_e), Bundle[{
            firebase_event_origin(_o) = auto,
            engagement_time_msec(_et) = 2928,
            firebase_screen_class(_sc) = Main_Screen,
            firebase_screen_id(_si) = 6213183756703048966
          }] 01 - 26 16: 51: 31.941 1395 - 1395 / com.tabian.firebasepushnotifications E / ViewRootImpl: sendUserActionEvent() mView == null 01 - 26 16: 51: 32.091 1395 - 1409 / com.tabian.firebasepushnotifications V / FA: Activity resumed, time: 242639824 01 - 26 16: 51: 37.097 1395 - 1409 / com.tabian.firebasepushnotifications V / FA: Inactivity, disconnecting from the service

    当应用程序打开时,当我发送通知时,它会显示:

    01 - 26 16: 53: 29.096 1395 - 2149 / com.tabian.firebasepushnotifications D / FirebaseMessagingServic: Message data payload: {
      extra_information = This is some extra information
    }
    01 - 26 16: 53: 29.096 1395 - 2149 / com.tabian.firebasepushnotifications D / FirebaseMessagingServic: onMessageReceived:
      Extra Information: This is some extra information
    01 - 26 16: 53: 29.096 1395 - 2149 / com.tabian.firebasepushnotifications D / FirebaseMessagingServic: Message Notification Title: Test title: http: //www.google.com
      01 - 26 16: 53: 29.096 1395 - 2149 / com.tabian.firebasepushnotifications D / FirebaseMessagingServic: Message Notification Body: Test body: http: //www.google.com
      01 - 26 16: 53: 29.096 1395 - 2149 / com.tabian.firebasepushnotifications D / FirebaseMessagingServic: Message Notification click_action: MAIN_PAGE
    01 - 26 16: 53: 29.106 1395 - 2149 / com.tabian.firebasepushnotifications D / FirebaseMessagingServic: Message Notification url: http: //www.google.com
      01 - 26 16: 53: 35.293 1395 - 1395 / com.tabian.firebasepushnotifications I / PersonaManager: getPersonaService() name persona_policy
    01 - 26 16: 53: 35.313 1395 - 1395 / com.tabian.firebasepushnotifications V / FA: onActivityCreated
    01 - 26 16: 53: 35.353 1395 - 1395 / com.tabian.firebasepushnotifications E / ViewRootImpl: sendUserActionEvent() mView == null
    01 - 26 16: 53: 35.353 1395 - 1845 / com.tabian.firebasepushnotifications V / FA: Recording user engagement, ms: 16086
    01 - 26 16: 53: 35.353 1395 - 1845 / com.tabian.firebasepushnotifications V / FA: Connecting to remote service
    01 - 26 16: 53: 35.383 1395 - 1845 / com.tabian.firebasepushnotifications V / FA: Activity paused, time: 242763126
    01 - 26 16: 53: 35.383 1395 - 1845 / com.tabian.firebasepushnotifications V / FA: Connection attempt already in progress
    01 - 26 16: 53: 35.383 1395 - 1845 / com.tabian.firebasepushnotifications V / FA: Activity resumed, time: 242763247
    01 - 26 16: 53: 35.383 1395 - 1845 / com.tabian.firebasepushnotifications D / FA: Logging event(FE): user_engagement(_e), Bundle[{
      firebase_event_origin(_o) = auto,
      engagement_time_msec(_et) = 16086,
      firebase_screen_class(_sc) = Main_Screen,
      firebase_screen_id(_si) = 6213183756703048969
    }]
    01 - 26 16: 53: 35.423 1395 - 1845 / com.tabian.firebasepushnotifications V / FA: Connection attempt already in progress
    01 - 26 16: 53: 35.493 1395 - 1845 / com.tabian.firebasepushnotifications D / FA: Connected to remote service
    01 - 26 16: 53: 35.493 1395 - 1845 / com.tabian.firebasepushnotifications V / FA: Processing queued up service tasks: 3

1 个答案:

答案 0 :(得分:1)

您正在推送json中发送notification个有效负载。这将使onMessageReceived无法被调用。

来自firebase文档(https://firebase.google.com/docs/cloud-messaging/android/receive?hl=en):

  大多数消息类型都提供了

onMessageReceived   以下例外:

     
      
  • 当您的应用在后台时发送通知消息。在这种情况下,通知会传递到设备的系统托盘。用户点按通知会默认打开应用启动器。
  •   
  • 包含通知和数据有效负载的消息,包括后台和前台。在这种情况下,通知将传递到设备的系统托盘,并且数据有效负载将在意图的附加内容中传递。你的发射器活动。
  •   

因此,如果您想自己处理通知,则应仅发送data个有效负载。

此外,在您的代码中,您并未在任何地方致电sendNotification(String title, String messageBody, String click_action, Uri uri)

sendNotification实施正确且工作正常。你忘了在onMessageReceived !!

里面打电话

修改

要获得data有效负载,您应该使用remoteMessage.getData()代替remoteMessage.getNotification()