mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-06-16 11:59:29 +08:00
fix(admob): add null checks for getCurrentActivity() usages (#2913)
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user