[admob][android] Add initialize method + documentation
This commit is contained in:
parent
ad68ccc9af
commit
e12567e57f
|
@ -7,13 +7,11 @@ import android.util.Log;
|
|||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.google.android.gms.ads.AdRequest;
|
||||
import io.invertase.firebase.Utils;
|
||||
import com.google.android.gms.ads.MobileAds;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
|
@ -31,7 +29,6 @@ public class RNFirebaseAdMob extends ReactContextBaseJavaModule {
|
|||
|
||||
private HashMap<String, RNFirebaseAdmobInterstitial> interstitials = new HashMap<>();
|
||||
private HashMap<String, RNFirebaseAdMobRewardedVideo> rewardedVideos = new HashMap<>();
|
||||
private HashMap<String, RNFirebaseAdMobNativeExpress> nativeExpressAds = new HashMap<>();
|
||||
|
||||
public RNFirebaseAdMob(ReactApplicationContext reactContext) {
|
||||
super(reactContext);
|
||||
|
@ -43,6 +40,11 @@ public class RNFirebaseAdMob extends ReactContextBaseJavaModule {
|
|||
return TAG;
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void initialize(String appId) {
|
||||
MobileAds.initialize(this.getContext(), appId);
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void interstitialLoadAd(String adUnit, ReadableMap request) {
|
||||
RNFirebaseAdmobInterstitial interstitial = getOrCreateInterstitial(adUnit);
|
||||
|
|
|
@ -1,8 +1,17 @@
|
|||
# AdMob
|
||||
|
||||
The admob allows you to display adverts in your app, using your account from [AdMob by Google](https://www.google.co.uk/admob/).
|
||||
The admob allows you to display adverts in your app, using your account from [AdMob by Google](https://www.google.co.uk/admob/). RNFirebase allows you to display Banners, Interstitials, NativeExpress Ads & Rewarded Videos.
|
||||
|
||||
RNFirebase allows you to display Banners, Interstitials, NativeExpress Ads & Rewarded Videos.
|
||||
## Initialize
|
||||
|
||||
Before using any AdMob feature, ensure you call the initialize method. This only needs to be done once per the apps lifecycle.
|
||||
Initialize takes your AdMob App ID, where you can find on your AdMob dashboard.
|
||||
|
||||
> For testing purposes, you can use AdMobs test app ID "ca-app-pub-3940256099942544~3347511713".
|
||||
|
||||
```js
|
||||
firebase.admob().initialize("ca-app-pub-3940256099942544~3347511713");
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
|
|
|
@ -61,7 +61,6 @@ class AdMobComponent extends React.Component {
|
|||
* @param nativeEvent
|
||||
*/
|
||||
onBannerEvent = ({ nativeEvent }) => {
|
||||
console.log(nativeEvent)
|
||||
if (this.props[nativeEvent.type]) {
|
||||
if (nativeEvent.type === 'onAdFailedToLoad') {
|
||||
const { code, message } = nativeEvent.payload;
|
||||
|
|
|
@ -20,6 +20,7 @@ export default class Admob extends Base {
|
|||
return nativeSDKMissing('admob');
|
||||
}
|
||||
|
||||
this._initialized = false;
|
||||
FirebaseAdMobEvt.addListener('interstitial_event', this._onInterstitialEvent.bind(this));
|
||||
FirebaseAdMobEvt.addListener('rewarded_video_event', this._onRewardedVideoEvent.bind(this));
|
||||
}
|
||||
|
@ -46,6 +47,16 @@ export default class Admob extends Base {
|
|||
this.emit(jsEventType, event);
|
||||
}
|
||||
|
||||
initialize(appId: string) {
|
||||
if (this._initialized) {
|
||||
this.log.warn('AdMob has already been initialized!');
|
||||
return;
|
||||
}
|
||||
|
||||
this._initialized = true;
|
||||
return FirebaseAdMob.initialize(appId);
|
||||
}
|
||||
|
||||
interstitial(adUnit: string) {
|
||||
return new Interstitial(this, adUnit);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue