I have 2 apps in the Google Play Pass program (subscription program by Google where users can get access to a catalog of apps for a monthly fee). In order to participate, I had to modify the licensing library to bring up an app store wall if their subscription has expired. All was well and good until I started targeting API level 28 instead of 27. When the app tries to run the code for lc.followLastLicensingURL, I get a crash with the following error.
The code that I am having trouble with is the following:
On the JAVA side, I have the following code.
Any ideas about what to try to make JAVA happy?
main_lc_dontallow (java line: 1472)
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
at android.app.ContextImpl.startActivity(ContextImpl.java:974)
at android.app.ContextImpl.startActivity(ContextImpl.java:950)
at android.content.ContextWrapper.startActivity(ContextWrapper.java:384)
at com.android.vending.licensing.LicenseChecker.followLastLicensingUrl(LicenseChecker.java:213)
at anywheresoftware.b4a.objects.LicenseCheckerWrapper.followLastLicensingURL(LicenseCheckerWrapper.java:86)
at mindware.mindgamespro.main._lc_dontallow(main.java:1472)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at anywheresoftware.b4a.BA$2.run(BA.java:370)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6990)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
main_lc_dontallow (java line: 1472)
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
at android.app.ContextImpl.startActivity(ContextImpl.java:974)
at android.app.ContextImpl.startActivity(ContextImpl.java:950)
at android.content.ContextWrapper.startActivity(ContextWrapper.java:384)
at com.android.vending.licensing.LicenseChecker.followLastLicensingUrl(LicenseChecker.java:213)
at anywheresoftware.b4a.objects.LicenseCheckerWrapper.followLastLicensingURL(LicenseCheckerWrapper.java:86)
at mindware.mindgamespro.main._lc_dontallow(main.java:1472)
at java.lang.reflect.Method.invoke(Native Method)
The code that I am having trouble with is the following:
B4X:
Sub lc_DontAllow (PolicyReason As Int)
StateManager.SetSetting("licensed",False)
StateManager.SaveSettings
If Not(PolicyReason=lc.POLICY_RETRY) Then
lc.followLastLicensingURL
ExitApplication
End If
End Sub
On the JAVA side, I have the following code.
B4X:
public void followLastLicensingURL() {
lc.followLastLicensingUrl(BA.applicationContext);
// Call finish() on the surrounding activity to remove it from the backstack.
//MainActivity.this.finish();
}
Any ideas about what to try to make JAVA happy?