草庐IT

java - 推送网址打不开

coder 2023-11-27 原文

我有一个非常基本的 PushNotification 代码,它应该在没有 URL 时打开一个 Activity ,并在有 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 替换为 URL。没用
  5. 添加了一行 startActivity(intent)

在我的 list 中,我有:

<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。是否需要在 list 中添加其他内容才能打开链接?

编辑:我刚刚发现在 Postman 中我需要“链接”而不是“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

最佳答案

您正在推送 json 中发送 notification 负载。这将使 onMessageReceived 不被调用。

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

onMessageReceived is provided for most message types, with the following exceptions:

  • Notification messages delivered when your app is in the background. In this case, the notification is delivered to the device’s system tray. A user tap on a notification opens the app launcher by default.
  • Messages with both notification and data payload, both background and foreground. In this case, the notification is delivered to the device’s system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.

所以如果你想自己处理通知,你应该只发送data payload。

此外,在您的代码中,您不会在任何地方调用 sendNotification(String title, String messageBody, String click_action, Uri uri)

sendNotification 实现是正确的并且工作正常。你只是忘了在 onMessageReceived 中调用它!!

编辑:

要获取data 负载,您应该使用remoteMessage.getData() 而不是remoteMessage.getNotification()

关于java - 推送网址打不开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48463276/

有关java - 推送网址打不开的更多相关文章

  1. java - 等价于 Java 中的 Ruby Hash - 2

    我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/

  2. java - 从 JRuby 调用 Java 类的问题 - 2

    我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www

  3. java - 我的模型类或其他类中应该有逻辑吗 - 2

    我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我

  4. java - 什么相当于 ruby​​ 的 rack 或 python 的 Java wsgi? - 2

    什么是ruby​​的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht

  5. Observability:从零开始创建 Java 微服务并监控它 (二) - 2

    这篇文章是继上一篇文章“Observability:从零开始创建Java微服务并监控它(一)”的续篇。在上一篇文章中,我们讲述了如何创建一个Javaweb应用,并使用Filebeat来收集应用所生成的日志。在今天的文章中,我来详述如何收集应用的指标,使用APM来监控应用并监督web服务的在线情况。源码可以在地址 https://github.com/liu-xiao-guo/java_observability 进行下载。摄入指标指标被视为可以随时更改的时间点值。当前请求的数量可以改变任何毫秒。你可能有1000个请求的峰值,然后一切都回到一个请求。这也意味着这些指标可能不准确,你还想提取最小/

  6. 【Java 面试合集】HashMap中为什么引入红黑树,而不是AVL树呢 - 2

    HashMap中为什么引入红黑树,而不是AVL树呢1.概述开始学习这个知识点之前我们需要知道,在JDK1.8以及之前,针对HashMap有什么不同。JDK1.7的时候,HashMap的底层实现是数组+链表JDK1.8的时候,HashMap的底层实现是数组+链表+红黑树我们要思考一个问题,为什么要从链表转为红黑树呢。首先先让我们了解下链表有什么不好???2.链表上述的截图其实就是链表的结构,我们来看下链表的增删改查的时间复杂度增:因为链表不是线性结构,所以每次添加的时候,只需要移动一个节点,所以可以理解为复杂度是N(1)删:算法时间复杂度跟增保持一致查:既然是非线性结构,所以查询某一个节点的时候

  7. 【Java入门】使用Java实现文件夹的遍历 - 2

    遍历文件夹我们通常是使用递归进行操作,这种方式比较简单,也比较容易理解。本文为大家介绍另一种不使用递归的方式,由于没有使用递归,只用到了循环和集合,所以效率更高一些!一、使用递归遍历文件夹整体思路1、使用File封装初始目录,2、打印这个目录3、获取这个目录下所有的子文件和子目录的数组。4、遍历这个数组,取出每个File对象4-1、如果File是否是一个文件,打印4-2、否则就是一个目录,递归调用代码实现publicclassSearchFile{publicstaticvoidmain(String[]args){//初始目录Filedir=newFile("d:/Dev");Datebeg

  8. java - 为什么 ruby​​ modulo 与 java/other lang 不同? - 2

    我基本上来自Java背景并且努力理解Ruby中的模运算。(5%3)(-5%3)(5%-3)(-5%-3)Java中的上述操作产生,2个-22个-2但在Ruby中,相同的表达式会产生21个-1-2.Ruby在逻辑上有多擅长这个?模块操作在Ruby中是如何实现的?如果将同一个操作定义为一个web服务,两个服务如何匹配逻辑。 最佳答案 在Java中,模运算的结果与被除数的符号相同。在Ruby中,它与除数的符号相同。remainder()在Ruby中与被除数的符号相同。您可能还想引用modulooperation.

  9. java - Ruby 相当于 Java 的 Collections.unmodifiableList 和 Collections.unmodifiableMap - 2

    Java的Collections.unmodifiableList和Collections.unmodifiableMap在Ruby标准API中是否有等价物? 最佳答案 使用freeze应用程序接口(interface):Preventsfurthermodificationstoobj.ARuntimeErrorwillberaisedifmodificationisattempted.Thereisnowaytounfreezeafrozenobject.SeealsoObject#frozen?.Thismethodretur

  10. arrays - Ruby 数组 += vs 推送 - 2

    我有一个数组数组,想将元素附加到子数组。+=做我想做的,但我想了解为什么push不做。我期望的行为(并与+=一起工作):b=Array.new(3,[])b[0]+=["apple"]b[1]+=["orange"]b[2]+=["frog"]b=>[["苹果"],["橙子"],["Frog"]]通过推送,我将推送的元素附加到每个子数组(为什么?):a=Array.new(3,[])a[0].push("apple")a[1].push("orange")a[2].push("frog")a=>[[“苹果”、“橙子”、“Frog”]、[“苹果”、“橙子”、“Frog”]、[“苹果”、“

随机推荐