apptentive / apptentive-android

Apptentive Android SDK
http://www.apptentive.com
BSD 3-Clause "New" or "Revised" License
65 stars 64 forks source link

New in app rate dialog is not being displayed #217

Closed gmbett closed 3 years ago

gmbett commented 3 years ago

Hello,

In our company we are trying to use the latest version of your SDK (version 5.6.0) which in theory brings support for Google Play In-App Review but I'm seeing an error in Logcat when the new rate dialog should be displayed:

2020-11-12 09:54:41.933 31780-31780/com.swisscom.mycloud E/Apptentive: [IN_APP_REVIEW] Unable to create in-app review manager
    java.lang.ClassCastException: com.swisscom.ngti.mycloud.MyCloudApplication cannot be cast to android.app.Activity
        at com.apptentive.android.sdk.external.DefaultInAppReviewManagerFactory.createReviewManager(DefaultInAppReviewManagerFactory.java:36)
        at com.apptentive.android.sdk.module.engagement.InAppRatingDialogInteractionLauncher.launch(InAppRatingDialogInteractionLauncher.java:46)
        at com.apptentive.android.sdk.module.engagement.InAppRatingDialogInteractionLauncher.launch(InAppRatingDialogInteractionLauncher.java:21)
        at com.apptentive.android.sdk.module.engagement.EngagementModule.launchInteraction(EngagementModule.java:135)
        at com.apptentive.android.sdk.module.engagement.EngagementModule$1.execute(EngagementModule.java:122)
        at com.apptentive.android.sdk.util.threading.DispatchTask.run(DispatchTask.java:39)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

It seems that you are trying to cast the context provided to the SDK (when is initialized) to Activity?

CaseyApptentive commented 3 years ago

Hi @gmbett,

Great question. You are understanding this correctly. Apptentive controls who can see the Google Play Rating Dialog, where it is displayed, and how often we try to show it -- but Google's API requires that the Where Event used to launch it have an Activity Context.

Here's a bit more depth in our docs: https://learn.apptentive.com/knowledge-base/requesting-ratings-on-google-play/#apptentive-rating-dialog-shown-instead-of-google-play-rating-dialog

Other Apptentive Interactions types -- which are fully 'owned' by Apptentive -- do not have the same restriction. Essentially, this is a rule handed down from Google directly.

To fix this, you'll need to adjust how the Where Event is called in your code to ensure it has an Activity Context. It may also be wise to see if any of your other Events may not have an Activity Context either. Remember, other Apptentive Interactions do not strictly require an Activity Context -- but if anyone adjusts the targeting of the Rating Dialog in the future, they do need to use an Event that works.

gmbett commented 3 years ago

Hi @CaseyApptentive, thanks for the explanation!

I will adjust our implementation. Cheers, Germán

CaseyApptentive commented 3 years ago

Thanks for doing that. The new Google Play Rating Dialog works very well. I know it can take some legwork to make adjustments for it, but doing so is great.

gmbett commented 3 years ago

@CaseyApptentive I updated our implementation but still the rate dialog is not showing up, now I can see in the logs the following error:


I/Apptentive: [Apptentive Queue] [INTERACTIONS] Criteria evaluated => true
I/Apptentive: [INTERACTIONS] Launching interaction: 'InAppRatingDialog'
I/Apptentive: [Apptentive Queue] [INTERACTIONS] Engage event: 'com.apptentive#InAppRatingDialog#request'
D/ApptentiveUiManager: activityCreated: activity = com.google.android.play.core.common.PlayCoreDialogWrapperActivity@d06fe31, savedInstanceState = null
D/ApptentiveUiManager: activityStartedOrStopped: activity = com.google.android.play.core.common.PlayCoreDialogWrapperActivity@d06fe31, started = true
D/ApptentiveUiManager: Last activity set to com.google.android.play.core.common.PlayCoreDialogWrapperActivity@d06fe31
D/ApptentiveUiManager: Updated number of started activities: 2
E/Apptentive: [IN_APP_REVIEW] In-app review flow completed too fast (263 ms) and we have good reasons to believe it just failed silently.
I/Apptentive: [Apptentive Queue] [INTERACTIONS] Engage event: 'com.apptentive#InAppRatingDialog#not_shown'
D/ApptentiveUiManager: activityStartedOrStopped: activity = com.google.android.play.core.common.PlayCoreDialogWrapperActivity@d06fe31, started = false
D/ApptentiveUiManager: Last activity cleared, was com.google.android.play.core.common.PlayCoreDialogWrapperActivity@d06fe31
D/ApptentiveUiManager: Updated number of started activities: 1

Note: The behavior is worst than before because now not even the old rate dialog is displayed.
CaseyApptentive commented 3 years ago

Great question @gmbett.

So, you've hit a (really fun) expected behavior. Unfortunately, Google Play has given us a very helpful new tool with this Dialog, but there are several hoops to jump through to use it -- hoops that especially impact testing. Thanks for the logs. This is the key section:

E/Apptentive: [IN_APP_REVIEW] In-app review flow completed too fast (263 ms) and we have good reasons to believe it just failed silently.
I/Apptentive: [Apptentive Queue] [INTERACTIONS] Engage event: 'com.apptentive#InAppRatingDialog#not_shown'

This error means that Apptentive attempted to display the Google Play Rating Dialog, but that for at least one of a handful of expected reasons, the Dialog could not be shown. Here are a few of the most common reasons:

Please check out the full list of reasons here: https://learn.apptentive.com/knowledge-base/requesting-ratings-on-google-play/#google-play-rating-dialog-not-shown

Every testing setup is a bit different, so let me know if any of those reasons are the likely culprit blocking the Rating Dialog from being shown.

For customers in the wild, we do not expect to see these limitations very regularly, but it is possible. If it does come up, the Rating Dialog would fail silently -- so it's not a terrible customer experience. And, if you want to monitor how many customers we attempt to present the Dialog to but do not actually see it, you can see it on the front page of your Apptentive Dashboard -- that way you can be aware and make any targeting adjustments that might help reduce that number.

gmbett commented 3 years ago

Hi @CaseyApptentive thanks again for your detailed response.

CaseyApptentive commented 3 years ago

No problem. Let us know if you need anything else.