appodeal.canShow() crashes the app

Hello,

I would like to find out if the user is in flight mode, and thought that would possibly work with appodeal.canShow(“xyz”).

In the docs, it says that the call should work with the modular beta plugins, which I am using. Daily build 3393 for Android.

But whenever I call the line, the app crashes. I hoped it would at least return nil. appodeal.isLoaded() works fine. These are the lines in the code:

print ("ABCD") print (appodeal.canShow("banner"))

… and in the console, I get:

11-04 12:56:37.863 28039 28054 I Corona  : ABCD

11-04 12:56:37.865 28039 28054 I Corona  : ERROR: Runtime error

11-04 12:56:37.865 28039 28054 I Corona  : java.lang.NullPointerException: Attempt to invoke virtual method ‘java.lang.Object android.content.Context.getSystemService(java.lang.String)’ on a null object reference

what version of appodeal and corona are you using? I remember this being an older issue.

have you confirmed the initialization worked before calling that function?

I use Corona 3393, and the Appodeal version is built in accordingly I guess?

Yes, one line before, I call appodeal.isLoaded(), that works fine.

Can you provide a little more insight on your implementation? That is can you show us your initialization code, callback listener and what order/when you’re calling .isLoaded()?

Rob

I just tested:

  1. Android Pie.
  2. Corona Version 3426.

And at least for me, it worked as expected.

Also isLoaded is not the init that roaminggamer was talking about.

You first init. For example something like this:

appodeal.init( appodealListerner, { appKey=appodealId, disableWriteExternalPermissionCheck=true, testMode=false, hasUserConsent=false } )

And then you wait for the response back:

local appodealListerner = function( event ) if event.phase == "init" then -- Successful initialization -- do stuff with banner elseif event.data ~= nil and event.type == "rewardedVideo" and event.data.name == "reward" and event.phase == "playbackEnded" then -- do other stuff elseif event.type == "rewardedVideo" and event.phase == "closed" then -- do other stuff end end

I init a bit before, I just wanted to mention that a similar function works fine. I don’t have the chance to test it with 3426 at the moment, but I will later. It’s not critical, I was just curious, but it’s good to know that it works for you. Below is the code that I am using.

Sure, this is the code part:

local function appodealListener(e) if e.phase == "init" then print ("hello appodeal") elseif e.phase == "failed" then print("no appodeal", e.type, e.isError, e.response) end end appodeal.init(appodealListener, {appKey = "...", hasUserConsent = false, locationTracking = false, supportedAdTypes = {"..."}, bannerAnimation = true}) --- later in the game, the first time with 3000ms delay: function showVideo() local isAppodealLoaded = appodeal.isLoaded("rewardedVideo") local canAppodealShow = appodeal.canShow("rewardedVideo") -- app crashes here if (isAppodealLoaded and canAppodealShow) then appodeal.show("rewardedVideo") return false else appodeal.load("rewardedVideo") end end

Please take time to read this:

http://docs.coronalabs.com/tutorial/basics/ads/index.html

Rob

  1. Test using the beta. At one point canShow was not available in the non-beta version. I also don’t believe it is available in the Amazon version.

  2. My code is similar-ish. I would put a boolean in the init to make sure that appodeal actually initializes.

  3. Then I would check the boolean before making any calls.

    local appodealReady = false local function appodealListener(e) if e.phase == “init” then print (“hello appodeal”) appodealReady = true elseif e.phase == “failed” then print(“no appodeal”, e.type, e.isError, e.response) end end

My code works fine with Build 3426. Really seems to be a build-number related issue.

Thanks for your help.

what version of appodeal and corona are you using? I remember this being an older issue.

have you confirmed the initialization worked before calling that function?

I use Corona 3393, and the Appodeal version is built in accordingly I guess?

Yes, one line before, I call appodeal.isLoaded(), that works fine.

Can you provide a little more insight on your implementation? That is can you show us your initialization code, callback listener and what order/when you’re calling .isLoaded()?

Rob

I just tested:

  1. Android Pie.
  2. Corona Version 3426.

And at least for me, it worked as expected.

Also isLoaded is not the init that roaminggamer was talking about.

You first init. For example something like this:

appodeal.init( appodealListerner, { appKey=appodealId, disableWriteExternalPermissionCheck=true, testMode=false, hasUserConsent=false } )

And then you wait for the response back:

local appodealListerner = function( event ) if event.phase == "init" then -- Successful initialization -- do stuff with banner elseif event.data ~= nil and event.type == "rewardedVideo" and event.data.name == "reward" and event.phase == "playbackEnded" then -- do other stuff elseif event.type == "rewardedVideo" and event.phase == "closed" then -- do other stuff end end

I init a bit before, I just wanted to mention that a similar function works fine. I don’t have the chance to test it with 3426 at the moment, but I will later. It’s not critical, I was just curious, but it’s good to know that it works for you. Below is the code that I am using.

Sure, this is the code part:

local function appodealListener(e) if e.phase == "init" then print ("hello appodeal") elseif e.phase == "failed" then print("no appodeal", e.type, e.isError, e.response) end end appodeal.init(appodealListener, {appKey = "...", hasUserConsent = false, locationTracking = false, supportedAdTypes = {"..."}, bannerAnimation = true}) --- later in the game, the first time with 3000ms delay: function showVideo() local isAppodealLoaded = appodeal.isLoaded("rewardedVideo") local canAppodealShow = appodeal.canShow("rewardedVideo") -- app crashes here if (isAppodealLoaded and canAppodealShow) then appodeal.show("rewardedVideo") return false else appodeal.load("rewardedVideo") end end

Please take time to read this:

http://docs.coronalabs.com/tutorial/basics/ads/index.html

Rob

  1. Test using the beta. At one point canShow was not available in the non-beta version. I also don’t believe it is available in the Amazon version.

  2. My code is similar-ish. I would put a boolean in the init to make sure that appodeal actually initializes.

  3. Then I would check the boolean before making any calls.

    local appodealReady = false local function appodealListener(e) if e.phase == “init” then print (“hello appodeal”) appodealReady = true elseif e.phase == “failed” then print(“no appodeal”, e.type, e.isError, e.response) end end

My code works fine with Build 3426. Really seems to be a build-number related issue.

Thanks for your help.