fix(admob): add null checks for getCurrentActivity() usages (#2913)

This commit is contained in:
Juan
2019-11-23 13:45:34 -03:00
committed by Mike Diarmid
parent 227ab631a6
commit 1fb296dc3b
2 changed files with 22 additions and 0 deletions

View File

@@ -63,6 +63,13 @@ public class ReactNativeFirebaseAdMobInterstitialModule extends ReactNativeFireb
@ReactMethod
public void interstitialLoad(int requestId, String adUnitId, ReadableMap adRequestOptions) {
if (getCurrentActivity() == null) {
WritableMap error = Arguments.createMap();
error.putString("code", "null-activity");
error.putString("message", "Interstitial ad attempted to load but the current Activity was null.");
sendInterstitialEvent(AD_ERROR, requestId, adUnitId, error);
return;
}
getCurrentActivity().runOnUiThread(() -> {
InterstitialAd interstitialAd = new InterstitialAd(getApplicationContext());
interstitialAd.setAdUnitId(adUnitId);
@@ -112,6 +119,10 @@ public class ReactNativeFirebaseAdMobInterstitialModule extends ReactNativeFireb
@ReactMethod
public void interstitialShow(int requestId, ReadableMap showOptions, Promise promise) {
if (getCurrentActivity() == null) {
rejectPromiseWithCodeAndMessage(promise, "null-activity", "Interstitial ad attempted to show but the current Activity was null.");
return;
}
getCurrentActivity().runOnUiThread(() -> {
InterstitialAd interstitialAd = interstitialAdArray.get(requestId);

View File

@@ -50,6 +50,13 @@ public class ReactNativeFirebaseAdMobRewardedModule extends ReactNativeFirebaseM
@ReactMethod
public void rewardedLoad(int requestId, String adUnitId, ReadableMap adRequestOptions) {
if (getCurrentActivity() == null) {
WritableMap error = Arguments.createMap();
error.putString("code", "null-activity");
error.putString("message", "Rewarded ad attempted to load but the current Activity was null.");
sendRewardedEvent(AD_ERROR, requestId, adUnitId, error, null);
return;
}
getCurrentActivity().runOnUiThread(() -> {
RewardedAd rewardedAd = new RewardedAd(getApplicationContext(), adUnitId);
@@ -80,6 +87,10 @@ public class ReactNativeFirebaseAdMobRewardedModule extends ReactNativeFirebaseM
@ReactMethod
public void rewardedShow(int requestId, String adUnitId, ReadableMap showOptions, Promise promise) {
if (getCurrentActivity() == null) {
rejectPromiseWithCodeAndMessage(promise, "null-activity", "Rewarded ad attempted to show but the current Activity was null.");
return;
}
getCurrentActivity().runOnUiThread(() -> {
RewardedAd rewardedAd = rewardedAdArray.get(requestId);