@capacitor-community/admob 8.0.0 → 8.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +204 -22
- package/android/src/main/java/com/getcapacitor/community/admob/AdMob.java +73 -23
- package/android/src/main/java/com/getcapacitor/community/admob/appopen/AppOpenAdManager.kt +86 -0
- package/android/src/main/java/com/getcapacitor/community/admob/appopen/AppOpenAdPlugin.kt +104 -0
- package/android/src/main/java/com/getcapacitor/community/admob/appopen/AppOpenAdPluginEvents.kt +9 -0
- package/android/src/main/java/com/getcapacitor/community/admob/models/AdOptions.java +10 -0
- package/dist/docs.json +256 -42
- package/dist/esm/app-open/app-open-ad-options.interface.d.ts +3 -0
- package/dist/esm/app-open/app-open-ad-options.interface.js +2 -0
- package/dist/esm/app-open/app-open-ad-options.interface.js.map +1 -0
- package/dist/esm/app-open/app-open-ad-plugin-events.enum.d.ts +7 -0
- package/dist/esm/app-open/app-open-ad-plugin-events.enum.js +9 -0
- package/dist/esm/app-open/app-open-ad-plugin-events.enum.js.map +1 -0
- package/dist/esm/app-open/app-open-definitions.interface.d.ts +27 -0
- package/dist/esm/app-open/app-open-definitions.interface.js +2 -0
- package/dist/esm/app-open/app-open-definitions.interface.js.map +1 -0
- package/dist/esm/app-open/index.d.ts +3 -0
- package/dist/esm/app-open/index.js +4 -0
- package/dist/esm/app-open/index.js.map +1 -0
- package/dist/esm/definitions.d.ts +2 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.d.ts +9 -0
- package/dist/esm/web.js +16 -5
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +24 -5
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +24 -5
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/AdMobPlugin/AdMobPlugin.swift +30 -4
- package/ios/Sources/AdMobPlugin/AppOpen/AppOpenAdManager.swift +101 -0
- package/ios/Sources/AdMobPlugin/AppOpen/AppOpenAdPlugin.swift +71 -0
- package/ios/Sources/AdMobPlugin/AppOpen/AppOpenAdPluginEvents.swift +7 -0
- package/ios/Sources/AdMobPlugin/Banner/BannerExecutor.swift +6 -6
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -36,10 +36,10 @@ Made with [contributors-img](https://contrib.rocks).
|
|
|
36
36
|
|
|
37
37
|
### Screenshots
|
|
38
38
|
|
|
39
|
-
| | Banner | Interstitial | Reward |
|
|
40
|
-
| :---------- | :----------------------------------: | :----------------------------------------: | :----------------------------------: |
|
|
41
|
-
| **iOS** |  |  |  |
|
|
42
|
-
| **Android** |  |  |  |
|
|
39
|
+
| | Banner | Interstitial | Reward | App Open |
|
|
40
|
+
| :---------- | :----------------------------------: | :----------------------------------------: | :----------------------------------: | :---------------------------------: |
|
|
41
|
+
| **iOS** |  |  |  |  |
|
|
42
|
+
| **Android** |  |  |  |  |
|
|
43
43
|
|
|
44
44
|
## Installation
|
|
45
45
|
|
|
@@ -188,7 +188,44 @@ const consentInfo = await AdMob.requestConsentInfo({
|
|
|
188
188
|
2. AdMob.requestConsentInfo
|
|
189
189
|
3. AdMob.showConsentForm (If consent form required )
|
|
190
190
|
3/ AdMob.showBanner
|
|
191
|
+
|
|
192
|
+
### Show App Open Ad
|
|
191
193
|
|
|
194
|
+
```ts
|
|
195
|
+
import {
|
|
196
|
+
AdMob,
|
|
197
|
+
AppOpenAdPluginEvents,
|
|
198
|
+
AppOpenAdOptions,
|
|
199
|
+
} from '@capacitor-community/admob';
|
|
200
|
+
|
|
201
|
+
export async function showAppOpenAd(): Promise<void> {
|
|
202
|
+
// listen to events
|
|
203
|
+
AdMob.addListener(AppOpenAdPluginEvents.Loaded, () => {
|
|
204
|
+
console.log('App Open Ad loaded');
|
|
205
|
+
});
|
|
206
|
+
AdMob.addListener(AppOpenAdPluginEvents.FailedToLoad, (error) => {
|
|
207
|
+
console.log('Failed to load App Open Ad', error);
|
|
208
|
+
});
|
|
209
|
+
AdMob.addListener(AppOpenAdPluginEvents.Opened, () => {
|
|
210
|
+
console.log('App Open Ad open');
|
|
211
|
+
});
|
|
212
|
+
AdMob.addListener(AppOpenAdPluginEvents.Closed, () => {
|
|
213
|
+
console.log('App Open Ad close');
|
|
214
|
+
});
|
|
215
|
+
AdMob.addListener(AppOpenAdPluginEvents.FailedToShow, (error) => {
|
|
216
|
+
console.log('Failed to show App Open Ad', error);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
const options: AppOpenAdOptions = {
|
|
220
|
+
adId: 'YOUR_AD_UNIT_ID',
|
|
221
|
+
};
|
|
222
|
+
await AdMob.loadAppOpen(options);
|
|
223
|
+
const { value } = await AdMob.isAppOpenLoaded();
|
|
224
|
+
if (value) {
|
|
225
|
+
await AdMob.showAppOpen();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
```
|
|
192
229
|
### Show Banner
|
|
193
230
|
|
|
194
231
|
```ts
|
|
@@ -334,6 +371,14 @@ AdMob.addListener(RewardAdPluginEvents.Rewarded, async () => {
|
|
|
334
371
|
* [`requestTrackingAuthorization()`](#requesttrackingauthorization)
|
|
335
372
|
* [`setApplicationMuted(...)`](#setapplicationmuted)
|
|
336
373
|
* [`setApplicationVolume(...)`](#setapplicationvolume)
|
|
374
|
+
* [`loadAppOpen(...)`](#loadappopen)
|
|
375
|
+
* [`showAppOpen()`](#showappopen)
|
|
376
|
+
* [`isAppOpenLoaded()`](#isappopenloaded)
|
|
377
|
+
* [`addListener(AppOpenAdPluginEvents.Loaded, ...)`](#addlistenerappopenadplugineventsloaded-)
|
|
378
|
+
* [`addListener(AppOpenAdPluginEvents.FailedToLoad, ...)`](#addlistenerappopenadplugineventsfailedtoload-)
|
|
379
|
+
* [`addListener(AppOpenAdPluginEvents.Opened, ...)`](#addlistenerappopenadplugineventsopened-)
|
|
380
|
+
* [`addListener(AppOpenAdPluginEvents.Closed, ...)`](#addlistenerappopenadplugineventsclosed-)
|
|
381
|
+
* [`addListener(AppOpenAdPluginEvents.FailedToShow, ...)`](#addlistenerappopenadplugineventsfailedtoshow-)
|
|
337
382
|
* [`showBanner(...)`](#showbanner)
|
|
338
383
|
* [`hideBanner()`](#hidebanner)
|
|
339
384
|
* [`resumeBanner()`](#resumebanner)
|
|
@@ -461,6 +506,125 @@ Report application volume to AdMob SDK
|
|
|
461
506
|
--------------------
|
|
462
507
|
|
|
463
508
|
|
|
509
|
+
### loadAppOpen(...)
|
|
510
|
+
|
|
511
|
+
```typescript
|
|
512
|
+
loadAppOpen(options: AppOpenAdOptions) => Promise<void>
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
Load an App Open ad
|
|
516
|
+
|
|
517
|
+
| Param | Type |
|
|
518
|
+
| ------------- | ------------------------------------------------------------- |
|
|
519
|
+
| **`options`** | <code><a href="#appopenadoptions">AppOpenAdOptions</a></code> |
|
|
520
|
+
|
|
521
|
+
--------------------
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
### showAppOpen()
|
|
525
|
+
|
|
526
|
+
```typescript
|
|
527
|
+
showAppOpen() => Promise<void>
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
Shows the App Open ad if loaded
|
|
531
|
+
|
|
532
|
+
--------------------
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
### isAppOpenLoaded()
|
|
536
|
+
|
|
537
|
+
```typescript
|
|
538
|
+
isAppOpenLoaded() => Promise<{ value: boolean; }>
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
Check if the App Open ad is loaded
|
|
542
|
+
|
|
543
|
+
**Returns:** <code>Promise<{ value: boolean; }></code>
|
|
544
|
+
|
|
545
|
+
--------------------
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
### addListener(AppOpenAdPluginEvents.Loaded, ...)
|
|
549
|
+
|
|
550
|
+
```typescript
|
|
551
|
+
addListener(eventName: AppOpenAdPluginEvents.Loaded, listenerFunc: () => void) => Promise<PluginListenerHandle>
|
|
552
|
+
```
|
|
553
|
+
|
|
554
|
+
| Param | Type |
|
|
555
|
+
| ------------------ | ------------------------------------------------------------------------------ |
|
|
556
|
+
| **`eventName`** | <code><a href="#appopenadpluginevents">AppOpenAdPluginEvents.Loaded</a></code> |
|
|
557
|
+
| **`listenerFunc`** | <code>() => void</code> |
|
|
558
|
+
|
|
559
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>></code>
|
|
560
|
+
|
|
561
|
+
--------------------
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
### addListener(AppOpenAdPluginEvents.FailedToLoad, ...)
|
|
565
|
+
|
|
566
|
+
```typescript
|
|
567
|
+
addListener(eventName: AppOpenAdPluginEvents.FailedToLoad, listenerFunc: (error: AdMobError) => void) => Promise<PluginListenerHandle>
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
| Param | Type |
|
|
571
|
+
| ------------------ | ------------------------------------------------------------------------------------ |
|
|
572
|
+
| **`eventName`** | <code><a href="#appopenadpluginevents">AppOpenAdPluginEvents.FailedToLoad</a></code> |
|
|
573
|
+
| **`listenerFunc`** | <code>(error: <a href="#admoberror">AdMobError</a>) => void</code> |
|
|
574
|
+
|
|
575
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>></code>
|
|
576
|
+
|
|
577
|
+
--------------------
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
### addListener(AppOpenAdPluginEvents.Opened, ...)
|
|
581
|
+
|
|
582
|
+
```typescript
|
|
583
|
+
addListener(eventName: AppOpenAdPluginEvents.Opened, listenerFunc: () => void) => Promise<PluginListenerHandle>
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
| Param | Type |
|
|
587
|
+
| ------------------ | ------------------------------------------------------------------------------ |
|
|
588
|
+
| **`eventName`** | <code><a href="#appopenadpluginevents">AppOpenAdPluginEvents.Opened</a></code> |
|
|
589
|
+
| **`listenerFunc`** | <code>() => void</code> |
|
|
590
|
+
|
|
591
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>></code>
|
|
592
|
+
|
|
593
|
+
--------------------
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
### addListener(AppOpenAdPluginEvents.Closed, ...)
|
|
597
|
+
|
|
598
|
+
```typescript
|
|
599
|
+
addListener(eventName: AppOpenAdPluginEvents.Closed, listenerFunc: () => void) => Promise<PluginListenerHandle>
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
| Param | Type |
|
|
603
|
+
| ------------------ | ------------------------------------------------------------------------------ |
|
|
604
|
+
| **`eventName`** | <code><a href="#appopenadpluginevents">AppOpenAdPluginEvents.Closed</a></code> |
|
|
605
|
+
| **`listenerFunc`** | <code>() => void</code> |
|
|
606
|
+
|
|
607
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>></code>
|
|
608
|
+
|
|
609
|
+
--------------------
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
### addListener(AppOpenAdPluginEvents.FailedToShow, ...)
|
|
613
|
+
|
|
614
|
+
```typescript
|
|
615
|
+
addListener(eventName: AppOpenAdPluginEvents.FailedToShow, listenerFunc: (error: AdMobError) => void) => Promise<PluginListenerHandle>
|
|
616
|
+
```
|
|
617
|
+
|
|
618
|
+
| Param | Type |
|
|
619
|
+
| ------------------ | ------------------------------------------------------------------------------------ |
|
|
620
|
+
| **`eventName`** | <code><a href="#appopenadpluginevents">AppOpenAdPluginEvents.FailedToShow</a></code> |
|
|
621
|
+
| **`listenerFunc`** | <code>(error: <a href="#admoberror">AdMobError</a>) => void</code> |
|
|
622
|
+
|
|
623
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>></code>
|
|
624
|
+
|
|
625
|
+
--------------------
|
|
626
|
+
|
|
627
|
+
|
|
464
628
|
### showBanner(...)
|
|
465
629
|
|
|
466
630
|
```typescript
|
|
@@ -1102,6 +1266,31 @@ addListener(eventName: RewardInterstitialAdPluginEvents.Showed, listenerFunc: ()
|
|
|
1102
1266
|
| **`volume`** | <code>0 \| 1 \| 0.1 \| 0.2 \| 0.3 \| 0.4 \| 0.5 \| 0.6 \| 0.7 \| 0.8 \| 0.9</code> | If your app has its own volume controls (such as custom music or sound effect volumes), disclosing app volume to the Google Mobile Ads SDK allows video ads to respect app volume settings. enable set 0.0 - 1.0, any float allowed. | 4.1.1 |
|
|
1103
1267
|
|
|
1104
1268
|
|
|
1269
|
+
#### AppOpenAdOptions
|
|
1270
|
+
|
|
1271
|
+
| Prop | Type |
|
|
1272
|
+
| ---------- | ------------------- |
|
|
1273
|
+
| **`adId`** | <code>string</code> |
|
|
1274
|
+
|
|
1275
|
+
|
|
1276
|
+
#### PluginListenerHandle
|
|
1277
|
+
|
|
1278
|
+
| Prop | Type |
|
|
1279
|
+
| ------------ | ----------------------------------------- |
|
|
1280
|
+
| **`remove`** | <code>() => Promise<void></code> |
|
|
1281
|
+
|
|
1282
|
+
|
|
1283
|
+
#### AdMobError
|
|
1284
|
+
|
|
1285
|
+
For more information
|
|
1286
|
+
https://developers.google.com/android/reference/com/google/android/gms/ads/AdError
|
|
1287
|
+
|
|
1288
|
+
| Prop | Type | Description |
|
|
1289
|
+
| ------------- | ------------------- | -------------------------------------- |
|
|
1290
|
+
| **`code`** | <code>number</code> | Gets the error's code. |
|
|
1291
|
+
| **`message`** | <code>string</code> | Gets the message describing the error. |
|
|
1292
|
+
|
|
1293
|
+
|
|
1105
1294
|
#### BannerAdOptions
|
|
1106
1295
|
|
|
1107
1296
|
This interface extends <a href="#adoptions">AdOptions</a>
|
|
@@ -1117,13 +1306,6 @@ This interface extends <a href="#adoptions">AdOptions</a>
|
|
|
1117
1306
|
| **`immersiveMode`** | <code>boolean</code> | Sets a flag that controls if this interstitial or reward object will be displayed in immersive mode. Call this method before show. During show, if this flag is on and immersive mode is supported, SYSTEM_UI_FLAG_IMMERSIVE_STICKY &SYSTEM_UI_FLAG_HIDE_NAVIGATION will be turned on for interstitial or reward ad. | | 7.0.3 |
|
|
1118
1307
|
|
|
1119
1308
|
|
|
1120
|
-
#### PluginListenerHandle
|
|
1121
|
-
|
|
1122
|
-
| Prop | Type |
|
|
1123
|
-
| ------------ | ----------------------------------------- |
|
|
1124
|
-
| **`remove`** | <code>() => Promise<void></code> |
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
1309
|
#### AdMobBannerSize
|
|
1128
1310
|
|
|
1129
1311
|
When notice listener of OnAdLoaded, you can get banner size.
|
|
@@ -1134,17 +1316,6 @@ When notice listener of OnAdLoaded, you can get banner size.
|
|
|
1134
1316
|
| **`height`** | <code>number</code> |
|
|
1135
1317
|
|
|
1136
1318
|
|
|
1137
|
-
#### AdMobError
|
|
1138
|
-
|
|
1139
|
-
For more information
|
|
1140
|
-
https://developers.google.com/android/reference/com/google/android/gms/ads/AdError
|
|
1141
|
-
|
|
1142
|
-
| Prop | Type | Description |
|
|
1143
|
-
| ------------- | ------------------- | -------------------------------------- |
|
|
1144
|
-
| **`code`** | <code>number</code> | Gets the error's code. |
|
|
1145
|
-
| **`message`** | <code>string</code> | Gets the message describing the error. |
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
1319
|
#### AdmobConsentInfo
|
|
1149
1320
|
|
|
1150
1321
|
| Prop | Type | Description | Since |
|
|
@@ -1256,6 +1427,17 @@ From T, pick a set of properties whose keys are in the union K
|
|
|
1256
1427
|
| **`MatureAudience`** | <code>'MatureAudience'</code> | Content suitable only for mature audiences. |
|
|
1257
1428
|
|
|
1258
1429
|
|
|
1430
|
+
#### AppOpenAdPluginEvents
|
|
1431
|
+
|
|
1432
|
+
| Members | Value |
|
|
1433
|
+
| ------------------ | ------------------------------------ |
|
|
1434
|
+
| **`Loaded`** | <code>'appOpenAdLoaded'</code> |
|
|
1435
|
+
| **`FailedToLoad`** | <code>'appOpenAdFailedToLoad'</code> |
|
|
1436
|
+
| **`Opened`** | <code>'appOpenAdOpened'</code> |
|
|
1437
|
+
| **`Closed`** | <code>'appOpenAdClosed'</code> |
|
|
1438
|
+
| **`FailedToShow`** | <code>'appOpenAdFailedToShow'</code> |
|
|
1439
|
+
|
|
1440
|
+
|
|
1259
1441
|
#### BannerAdSize
|
|
1260
1442
|
|
|
1261
1443
|
| Members | Value | Description |
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
package com.getcapacitor.community.admob;
|
|
2
2
|
|
|
3
3
|
import android.Manifest;
|
|
4
|
+
import android.app.Activity;
|
|
5
|
+
import android.os.Handler;
|
|
6
|
+
import android.os.Looper;
|
|
4
7
|
import com.getcapacitor.JSArray;
|
|
5
8
|
import com.getcapacitor.JSObject;
|
|
6
9
|
import com.getcapacitor.Plugin;
|
|
@@ -8,6 +11,7 @@ import com.getcapacitor.PluginCall;
|
|
|
8
11
|
import com.getcapacitor.PluginMethod;
|
|
9
12
|
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
10
13
|
import com.getcapacitor.annotation.Permission;
|
|
14
|
+
import com.getcapacitor.community.admob.appopen.AppOpenAdPlugin;
|
|
11
15
|
import com.getcapacitor.community.admob.banner.BannerExecutor;
|
|
12
16
|
import com.getcapacitor.community.admob.consent.AdConsentExecutor;
|
|
13
17
|
import com.getcapacitor.community.admob.helpers.AuthorizationStatusEnum;
|
|
@@ -34,18 +38,21 @@ public class AdMob extends Plugin {
|
|
|
34
38
|
this::notifyListeners,
|
|
35
39
|
getLogTag()
|
|
36
40
|
);
|
|
41
|
+
|
|
37
42
|
private final AdRewardExecutor adRewardExecutor = new AdRewardExecutor(
|
|
38
43
|
this::getContext,
|
|
39
44
|
this::getActivity,
|
|
40
45
|
this::notifyListeners,
|
|
41
46
|
getLogTag()
|
|
42
47
|
);
|
|
48
|
+
|
|
43
49
|
private final AdRewardInterstitialExecutor adRewardInterstitialExecutor = new AdRewardInterstitialExecutor(
|
|
44
50
|
this::getContext,
|
|
45
51
|
this::getActivity,
|
|
46
52
|
this::notifyListeners,
|
|
47
53
|
getLogTag()
|
|
48
54
|
);
|
|
55
|
+
|
|
49
56
|
private final AdInterstitialExecutor adInterstitialExecutor = new AdInterstitialExecutor(
|
|
50
57
|
this::getContext,
|
|
51
58
|
this::getActivity,
|
|
@@ -61,23 +68,52 @@ public class AdMob extends Plugin {
|
|
|
61
68
|
getLogTag()
|
|
62
69
|
);
|
|
63
70
|
|
|
64
|
-
|
|
71
|
+
private final AppOpenAdPlugin appOpenAdPlugin = new AppOpenAdPlugin();
|
|
72
|
+
|
|
73
|
+
@PluginMethod
|
|
74
|
+
public void loadAppOpen(final PluginCall call) {
|
|
75
|
+
appOpenAdPlugin.loadAppOpen(getContext(), getActivity(), call, this::notifyListeners);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@PluginMethod
|
|
79
|
+
public void showAppOpen(final PluginCall call) {
|
|
80
|
+
appOpenAdPlugin.showAppOpen(getActivity(), call, this::notifyListeners);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@PluginMethod
|
|
84
|
+
public void isAppOpenLoaded(final PluginCall call) {
|
|
85
|
+
appOpenAdPlugin.isAppOpenLoaded(getActivity(), call);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ---------------------------------------------------------
|
|
89
|
+
// MAIN METHODS
|
|
90
|
+
// ---------------------------------------------------------
|
|
91
|
+
|
|
65
92
|
@PluginMethod
|
|
66
93
|
public void initialize(final PluginCall call) {
|
|
67
94
|
this.setRequestConfiguration(call);
|
|
68
95
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
96
|
+
// Same as banner/interstitial: bridge thread is not the UI thread — MobileAds + view setup must run on main.
|
|
97
|
+
Runnable initOnMain = () -> {
|
|
98
|
+
try {
|
|
99
|
+
MobileAds.initialize(
|
|
100
|
+
getContext(),
|
|
101
|
+
new OnInitializationCompleteListener() {
|
|
102
|
+
@Override
|
|
103
|
+
public void onInitializationComplete(InitializationStatus initializationStatus) {}
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
bannerExecutor.initialize();
|
|
107
|
+
call.resolve();
|
|
108
|
+
} catch (Exception ex) {
|
|
109
|
+
call.reject(ex.getLocalizedMessage(), ex);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
Activity activity = getActivity();
|
|
113
|
+
if (activity != null) {
|
|
114
|
+
activity.runOnUiThread(initOnMain);
|
|
115
|
+
} else {
|
|
116
|
+
new Handler(Looper.getMainLooper()).post(initOnMain);
|
|
81
117
|
}
|
|
82
118
|
}
|
|
83
119
|
|
|
@@ -93,7 +129,10 @@ public class AdMob extends Plugin {
|
|
|
93
129
|
call.resolve(response);
|
|
94
130
|
}
|
|
95
131
|
|
|
96
|
-
//
|
|
132
|
+
// ---------------------------------------------------------
|
|
133
|
+
// USER CONSENT
|
|
134
|
+
// ---------------------------------------------------------
|
|
135
|
+
|
|
97
136
|
@PluginMethod
|
|
98
137
|
public void requestConsentInfo(final PluginCall call) {
|
|
99
138
|
adConsentExecutor.requestConsentInfo(call, this::notifyListeners);
|
|
@@ -114,6 +153,10 @@ public class AdMob extends Plugin {
|
|
|
114
153
|
adConsentExecutor.resetConsentInfo(call, this::notifyListeners);
|
|
115
154
|
}
|
|
116
155
|
|
|
156
|
+
// ---------------------------------------------------------
|
|
157
|
+
// APP SETTINGS
|
|
158
|
+
// ---------------------------------------------------------
|
|
159
|
+
|
|
117
160
|
@PluginMethod
|
|
118
161
|
public void setApplicationMuted(final PluginCall call) {
|
|
119
162
|
Boolean muted = call.getBoolean("muted");
|
|
@@ -136,41 +179,48 @@ public class AdMob extends Plugin {
|
|
|
136
179
|
call.resolve();
|
|
137
180
|
}
|
|
138
181
|
|
|
139
|
-
//
|
|
182
|
+
// ---------------------------------------------------------
|
|
183
|
+
// BANNER ADS
|
|
184
|
+
// ---------------------------------------------------------
|
|
185
|
+
|
|
140
186
|
@PluginMethod
|
|
141
187
|
public void showBanner(final PluginCall call) {
|
|
142
188
|
bannerExecutor.showBanner(call);
|
|
143
189
|
}
|
|
144
190
|
|
|
145
|
-
// Hide the banner, remove it from screen, but can show it later
|
|
146
191
|
@PluginMethod
|
|
147
192
|
public void hideBanner(final PluginCall call) {
|
|
148
193
|
bannerExecutor.hideBanner(call);
|
|
149
194
|
}
|
|
150
195
|
|
|
151
|
-
// Resume the banner, show it after hide
|
|
152
196
|
@PluginMethod
|
|
153
197
|
public void resumeBanner(final PluginCall call) {
|
|
154
198
|
bannerExecutor.resumeBanner(call);
|
|
155
199
|
}
|
|
156
200
|
|
|
157
|
-
// Destroy the banner, remove it from screen.
|
|
158
201
|
@PluginMethod
|
|
159
202
|
public void removeBanner(final PluginCall call) {
|
|
160
203
|
bannerExecutor.removeBanner(call);
|
|
161
204
|
}
|
|
162
205
|
|
|
206
|
+
// ---------------------------------------------------------
|
|
207
|
+
// INTERSTITIAL ADS
|
|
208
|
+
// ---------------------------------------------------------
|
|
209
|
+
|
|
163
210
|
@PluginMethod
|
|
164
211
|
public void prepareInterstitial(final PluginCall call) {
|
|
165
212
|
adInterstitialExecutor.prepareInterstitial(call, this::notifyListeners);
|
|
166
213
|
}
|
|
167
214
|
|
|
168
|
-
// Show interstitial Ad
|
|
169
215
|
@PluginMethod
|
|
170
216
|
public void showInterstitial(final PluginCall call) {
|
|
171
217
|
adInterstitialExecutor.showInterstitial(call, this::notifyListeners);
|
|
172
218
|
}
|
|
173
219
|
|
|
220
|
+
// ---------------------------------------------------------
|
|
221
|
+
// REWARDED ADS
|
|
222
|
+
// ---------------------------------------------------------
|
|
223
|
+
|
|
174
224
|
@PluginMethod
|
|
175
225
|
public void prepareRewardVideoAd(final PluginCall call) {
|
|
176
226
|
adRewardExecutor.prepareRewardVideoAd(call, this::notifyListeners);
|
|
@@ -191,10 +241,10 @@ public class AdMob extends Plugin {
|
|
|
191
241
|
adRewardInterstitialExecutor.showRewardInterstitialAd(call, this::notifyListeners);
|
|
192
242
|
}
|
|
193
243
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
244
|
+
// ---------------------------------------------------------
|
|
245
|
+
// REQUEST CONFIGURATION
|
|
246
|
+
// ---------------------------------------------------------
|
|
247
|
+
|
|
198
248
|
private void setRequestConfiguration(final PluginCall call) {
|
|
199
249
|
// Testing Devices
|
|
200
250
|
final boolean initializeForTesting = call.getBoolean("initializeForTesting", false);
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
package com.getcapacitor.community.admob.appopen
|
|
2
|
+
|
|
3
|
+
import android.app.Activity
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import com.google.android.gms.ads.AdError
|
|
6
|
+
import com.google.android.gms.ads.AdRequest
|
|
7
|
+
import com.google.android.gms.ads.FullScreenContentCallback
|
|
8
|
+
import com.google.android.gms.ads.LoadAdError
|
|
9
|
+
import com.google.android.gms.ads.appopen.AppOpenAd
|
|
10
|
+
|
|
11
|
+
class AppOpenAdManager(val adUnitId: String) {
|
|
12
|
+
|
|
13
|
+
private var appOpenAd: AppOpenAd? = null
|
|
14
|
+
private var isLoadingAd = false
|
|
15
|
+
private var isShowingAd = false
|
|
16
|
+
|
|
17
|
+
val isAdLoaded: Boolean
|
|
18
|
+
get() = appOpenAd != null
|
|
19
|
+
|
|
20
|
+
fun loadAd(context: Context, onLoaded: () -> Unit, onFailed: (LoadAdError?) -> Unit) {
|
|
21
|
+
if (appOpenAd != null) {
|
|
22
|
+
onLoaded()
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (isLoadingAd) {
|
|
27
|
+
onFailed(null)
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
isLoadingAd = true
|
|
32
|
+
val request = AdRequest.Builder().build()
|
|
33
|
+
|
|
34
|
+
// play-services-ads 24.x: orientation overload removed; SDK picks orientation from the activity.
|
|
35
|
+
AppOpenAd.load(
|
|
36
|
+
context,
|
|
37
|
+
adUnitId,
|
|
38
|
+
request,
|
|
39
|
+
object : AppOpenAd.AppOpenAdLoadCallback() {
|
|
40
|
+
override fun onAdLoaded(ad: AppOpenAd) {
|
|
41
|
+
appOpenAd = ad
|
|
42
|
+
isLoadingAd = false
|
|
43
|
+
onLoaded()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
override fun onAdFailedToLoad(loadAdError: LoadAdError) {
|
|
47
|
+
isLoadingAd = false
|
|
48
|
+
onFailed(loadAdError)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
fun showAdIfAvailable(
|
|
55
|
+
activity: Activity,
|
|
56
|
+
onOpened: () -> Unit,
|
|
57
|
+
onClosed: () -> Unit,
|
|
58
|
+
onFailedToShow: (AdError?) -> Unit
|
|
59
|
+
) {
|
|
60
|
+
if (appOpenAd == null || isShowingAd) {
|
|
61
|
+
onFailedToShow(null)
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
isShowingAd = true
|
|
66
|
+
appOpenAd?.fullScreenContentCallback = object : FullScreenContentCallback() {
|
|
67
|
+
override fun onAdShowedFullScreenContent() {
|
|
68
|
+
onOpened()
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
override fun onAdDismissedFullScreenContent() {
|
|
72
|
+
appOpenAd = null
|
|
73
|
+
isShowingAd = false
|
|
74
|
+
onClosed()
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
override fun onAdFailedToShowFullScreenContent(adError: AdError) {
|
|
78
|
+
appOpenAd = null
|
|
79
|
+
isShowingAd = false
|
|
80
|
+
onFailedToShow(adError)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
appOpenAd?.show(activity)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
package com.getcapacitor.community.admob.appopen
|
|
2
|
+
|
|
3
|
+
import android.app.Activity
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import android.os.Handler
|
|
6
|
+
import android.os.Looper
|
|
7
|
+
import com.getcapacitor.JSObject
|
|
8
|
+
import com.getcapacitor.PluginCall
|
|
9
|
+
import com.getcapacitor.community.admob.models.AdMobPluginError
|
|
10
|
+
|
|
11
|
+
class AppOpenAdPlugin {
|
|
12
|
+
|
|
13
|
+
fun interface EventNotifier {
|
|
14
|
+
fun notify(eventName: String, data: JSObject)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
private var appOpenAdManager: AppOpenAdManager? = null
|
|
18
|
+
|
|
19
|
+
private fun runOnMain(activity: Activity?, runnable: Runnable) {
|
|
20
|
+
if (activity != null) {
|
|
21
|
+
activity.runOnUiThread(runnable)
|
|
22
|
+
} else {
|
|
23
|
+
Handler(Looper.getMainLooper()).post(runnable)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
fun loadAppOpen(context: Context?, activity: Activity?, call: PluginCall, notifier: EventNotifier) {
|
|
28
|
+
if (context == null) {
|
|
29
|
+
call.reject("Context is not available")
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
val adUnitId = call.getString("adId")
|
|
34
|
+
if (adUnitId == null) {
|
|
35
|
+
call.reject("adId is required")
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
val appContext = context.applicationContext
|
|
40
|
+
runOnMain(activity) {
|
|
41
|
+
if (appOpenAdManager == null || adUnitId != appOpenAdManager?.adUnitId) {
|
|
42
|
+
appOpenAdManager = AppOpenAdManager(adUnitId)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
appOpenAdManager?.loadAd(
|
|
46
|
+
appContext,
|
|
47
|
+
onLoaded = {
|
|
48
|
+
val adInfo = JSObject().apply {
|
|
49
|
+
put("adUnitId", adUnitId)
|
|
50
|
+
}
|
|
51
|
+
notifier.notify(AppOpenAdPluginEvents.Loaded, adInfo)
|
|
52
|
+
call.resolve(adInfo)
|
|
53
|
+
},
|
|
54
|
+
onFailed = { loadAdError ->
|
|
55
|
+
val errorMessage = loadAdError?.message ?: "Failed to load App Open Ad"
|
|
56
|
+
val errorCode = loadAdError?.code ?: -1
|
|
57
|
+
notifier.notify(AppOpenAdPluginEvents.FailedToLoad, AdMobPluginError(errorCode, errorMessage))
|
|
58
|
+
call.reject(errorMessage)
|
|
59
|
+
}
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
fun showAppOpen(activity: Activity?, call: PluginCall, notifier: EventNotifier) {
|
|
65
|
+
if (activity == null) {
|
|
66
|
+
call.reject("Activity is not available")
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
runOnMain(activity) {
|
|
71
|
+
if (appOpenAdManager == null || appOpenAdManager?.isAdLoaded != true) {
|
|
72
|
+
call.reject("App Open Ad is not loaded")
|
|
73
|
+
return@runOnMain
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
appOpenAdManager?.showAdIfAvailable(
|
|
77
|
+
activity,
|
|
78
|
+
onOpened = {
|
|
79
|
+
notifier.notify(AppOpenAdPluginEvents.Opened, JSObject())
|
|
80
|
+
},
|
|
81
|
+
onClosed = {
|
|
82
|
+
notifier.notify(AppOpenAdPluginEvents.Closed, JSObject())
|
|
83
|
+
call.resolve()
|
|
84
|
+
},
|
|
85
|
+
onFailedToShow = { adError ->
|
|
86
|
+
val errorMessage = adError?.message ?: "Failed to show App Open Ad"
|
|
87
|
+
val errorCode = adError?.code ?: -1
|
|
88
|
+
notifier.notify(AppOpenAdPluginEvents.FailedToShow, AdMobPluginError(errorCode, errorMessage))
|
|
89
|
+
call.reject(errorMessage)
|
|
90
|
+
}
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
fun isAppOpenLoaded(activity: Activity?, call: PluginCall) {
|
|
96
|
+
runOnMain(activity) {
|
|
97
|
+
val loaded = appOpenAdManager?.isAdLoaded ?: false
|
|
98
|
+
val result = JSObject().apply {
|
|
99
|
+
put("value", loaded)
|
|
100
|
+
}
|
|
101
|
+
call.resolve(result)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
package/android/src/main/java/com/getcapacitor/community/admob/appopen/AppOpenAdPluginEvents.kt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
package com.getcapacitor.community.admob.appopen
|
|
2
|
+
|
|
3
|
+
object AppOpenAdPluginEvents {
|
|
4
|
+
const val Loaded = "appOpenAdLoaded"
|
|
5
|
+
const val FailedToLoad = "appOpenAdFailedToLoad"
|
|
6
|
+
const val Opened = "appOpenAdOpened"
|
|
7
|
+
const val Closed = "appOpenAdClosed"
|
|
8
|
+
const val FailedToShow = "appOpenAdFailedToShow"
|
|
9
|
+
}
|