Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pinpoint: Can't move to DeepLink page #2326

Closed
changxu0306 opened this issue Jan 11, 2021 · 5 comments
Closed

Pinpoint: Can't move to DeepLink page #2326

changxu0306 opened this issue Jan 11, 2021 · 5 comments
Assignees
Labels
bug Something isn't working pinpoint Issues with the AWS Android SDK for Pinpoint.

Comments

@changxu0306
Copy link
Contributor

Describe the bug
The source code used is here

In general, DeepLink notification works well when the users receive push notification while the application is in the background.
But DeepLink notification doesn't work sometimes as below:

  1. The application is on the foreground
  2. DeepLink push notification comes
  3. Press Back Button to close the app (Never touch the notification yet)
  4. Touch the push notification
  5. Application starts with main page, not deeplink page

To Reproduce
Receive Push Notification which contains deeplink in foreground -> Press Home Button -> Press Recent Key -> Kill the application -> Swipe down notification center -> Click the push notification -> Deeplink isn't opened
(even onReceive() at PinpointNotificationReceiver isn't called)

In order to get notification in foreground, I wrote the code below so the application can receive notifications in foreground:

PinpointConfiguration pinpointConfig = new PinpointConfiguration(
                    applicationContext,
                    AWSMobileClient.getInstance(),
                    awsConfig);
            pinpointConfig.withPostNotificationsInForeground(true);

the example of Deeplink scheme and host I used in the video
pinpoint://deeplink/page1?custom=babo

It works well in normal situation. But when I force to kill the application and touch the notification, it doesn't work well.

The following are some of the things worth paying attention to:

Normal Log

2020-12-15 01:44:51.286 23824-24066/kr.jhb.pinpointsampleapp D/AWSMobileClient: Inspecting user state details
2020-12-15 01:44:51.289 23824-24066/kr.jhb.pinpointsampleapp D/AWSMobileClient: waitForSignIn: userState:GUEST
2020-12-15 01:44:51.291 23824-24066/kr.jhb.pinpointsampleapp D/KeyProvider23: AndroidKeyStore contains keyAlias com.amazonaws.mobile.client.aesKeyStoreAlias
2020-12-15 01:44:51.291 23824-24066/kr.jhb.pinpointsampleapp D/KeyProvider23: Loading the encryption key from Android KeyStore.
2020-12-15 01:44:51.308 23824-23824/kr.jhb.pinpointsampleapp V/DeepLinkActivity: pinpoint://deeplink?title=foo&message=bar
2020-12-15 01:44:51.313 23824-23824/kr.jhb.pinpointsampleapp D/Dialog: mIsSamsungBasicInteraction = false
2020-12-15 01:44:51.313 23824-23824/kr.jhb.pinpointsampleapp D/Dialog: mIsSamsungBasicInteraction = false, isMetaDataInActivity = false

Error Log

It starts FirebaseInitProvider

2020-12-15 01:43:49.247 23824-23824/? E/Zygote: isWhitelistProcess - Process is Whitelisted
2020-12-15 01:43:49.252 23824-23824/? E/Zygote: accessInfo : 1
2020-12-15 01:43:49.263 23824-23824/? I/npointsampleap: Late-enabling -Xcheck:jni
2020-12-15 01:43:49.604 23824-23824/kr.jhb.pinpointsampleapp I/npointsampleap: The ClassLoaderContext is a special shared library.
2020-12-15 01:43:51.168 23824-23824/kr.jhb.pinpointsampleapp I/FirebaseInitProvider: FirebaseApp initialization successful
2020-12-15 01:43:51.267 23824-23824/kr.jhb.pinpointsampleapp W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@a36603c
2020-12-15 01:43:51.397 23824-23824/kr.jhb.pinpointsampleapp W/npointsampleap: Accessing hidden method Landroid/graphics/drawable/Drawable;->getOpticalInsets()Landroid/graphics/Insets; (light greylist, linking)
2020-12-15 01:43:51.397 23824-23824/kr.jhb.pinpointsampleapp W/npointsampleap: Accessing hidden field Landroid/graphics/Insets;->left:I (light greylist, linking)
2020-12-15 01:43:51.397 23824-23824/kr.jhb.pinpointsampleapp W/npointsampleap: Accessing hidden field Landroid/graphics/Insets;->right:I (light greylist, linking)
2020-12-15 01:43:51.397 23824-23824/kr.jhb.pinpointsampleapp W/npointsampleap: Accessing hidden field Landroid/graphics/Insets;->top:I (light greylist, linking)
2020-12-15 01:43:51.397 23824-23824/kr.jhb.pinpointsampleapp W/npointsampleap: Accessing hidden field Landroid/graphics/Insets;->bottom:I (light greylist, linking)
2020-12-15 01:43:51.419 23824-23824/kr.jhb.pinpointsampleapp I/DecorView: createDecorCaptionView >> DecorView@c44a0be[], isFloating: false, isApplication: true, hasWindowDecorCaption: false, hasWindowControllerCallback: true

As I've debugged it, onReceive method at PinpointNotificationReceiver class wasn't called after app was killed.
That's why NotificationClient can't open DeepLink.
I think you may start from this point.

Which AWS service(s) are affected?
Amazon Pinpoint v2.16

@changxu0306 changxu0306 added bug Something isn't working pinpoint Issues with the AWS Android SDK for Pinpoint. labels Jan 11, 2021
@tjleing
Copy link
Contributor

tjleing commented Jan 7, 2022

I was able to reproduce this issue. It's important that you fire the push notification while the app is open, because if you fire the notification before opening it the deeplink will work as expected. Also, I was only able to receive notifications when using Pinpoint instead of FCM; probably just a feature of the sample app.

Next, by setting the developer option to wait for debugger when starting to open an app, I was able to set a breakpoint in the PinpointNotificationReceiver and see that onReceive actually is being called, although the notificationClient is null which looks like it leads to handleNotificationOpen not being called which might be related to the issue. In any case, because I got a little further in this issue I decided to write this up.

In both of the other scenarios (app open -> send&click message, and app force closed -> send&click message) notificationClient is not null in PinpointNotificationReceiver.onReceive().

@tjleing
Copy link
Contributor

tjleing commented Jan 14, 2022

Workaround: add

if(getIntent().getExtras() != null) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(getIntent().getExtras().getString("pinpoint.deeplink")));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
}

after getPinpointManager(getApplicationContext()); in the MainActivity onCreate() function. For more broad usage, just note that getIntent().getExtras() will pull out a Bundle of the data of the push notification exactly in the case described above where the user closes the app and then taps on the push notification. The pinpoint.deeplink key of that Bundle has the deeplink URI provided in the push notification.

This will not contribute to Pinpoint campaign tracking. I am unsure if it will work if provided a deeplink that doesn't look like pinpoint://..., but I believe that that isn't supported by Pinpoint anyway, especially because the SDK docs recommend configuring the manifest XML file to match that URI format.

@tjleing
Copy link
Contributor

tjleing commented Jan 14, 2022

Hmm actually this might be solved if we also solve #2762, it seems like a PendingIntent is exactly what I'm looking for instead of the workaround described in the discussion above.

@tylerjroach
Copy link
Contributor

@changxu0306 Are you initializing PinpointManager in an Activity, such as MainActivity?

If the application is closed, the BroadcastReceiver (future release will be an Activity) is getting the notification bundle, but it is unable to properly route because notificationClient will be null at this time. This is because the Activity class that has PinpointManager initialization has not been created yet.

To fix this, Pinpoint initialization should be completed in a custom Application class instead. We are looking at our documentation around Pinpoint initialization to clarify this.

@tylerjroach tylerjroach self-assigned this Jun 9, 2022
@tylerjroach
Copy link
Contributor

Documentation has been updated to recommend configuring from Application class instead of Activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pinpoint Issues with the AWS Android SDK for Pinpoint.
Projects
None yet
Development

No branches or pull requests

3 participants