[admob][android] Support multiple test devices
This commit is contained in:
parent
e52e01f735
commit
c710f135ce
|
@ -49,10 +49,6 @@ class RNFirebaseAdMobUtils {
|
||||||
static AdRequest.Builder buildRequest(ReadableMap request) {
|
static AdRequest.Builder buildRequest(ReadableMap request) {
|
||||||
AdRequest.Builder requestBuilder = new AdRequest.Builder();
|
AdRequest.Builder requestBuilder = new AdRequest.Builder();
|
||||||
|
|
||||||
if (request.hasKey("testDevice")) {
|
|
||||||
requestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request.hasKey("isDesignedForFamilies")) {
|
if (request.hasKey("isDesignedForFamilies")) {
|
||||||
requestBuilder.setIsDesignedForFamilies(request.getBoolean("isDesignedForFamilies"));
|
requestBuilder.setIsDesignedForFamilies(request.getBoolean("isDesignedForFamilies"));
|
||||||
}
|
}
|
||||||
|
@ -84,6 +80,19 @@ class RNFirebaseAdMobUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle testDevices array
|
||||||
|
ReadableArray testDevices = request.getArray("keywords");
|
||||||
|
List<Object> testDevicesList = Utils.recursivelyDeconstructReadableArray(testDevices);
|
||||||
|
|
||||||
|
for (Object deviceId : testDevicesList) {
|
||||||
|
if (deviceId == "DEVICE_ID_EMULATOR") {
|
||||||
|
requestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
|
||||||
|
} else {
|
||||||
|
requestBuilder.addTestDevice((String) deviceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle keywords array
|
||||||
ReadableArray keywords = request.getArray("keywords");
|
ReadableArray keywords = request.getArray("keywords");
|
||||||
List<Object> keywordsList = Utils.recursivelyDeconstructReadableArray(keywords);
|
List<Object> keywordsList = Utils.recursivelyDeconstructReadableArray(keywords);
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ export default class AdRequest {
|
||||||
constructor() {
|
constructor() {
|
||||||
this._props = {
|
this._props = {
|
||||||
keywords: [],
|
keywords: [],
|
||||||
|
testDevices: [],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,8 +11,8 @@ export default class AdRequest {
|
||||||
return this._props;
|
return this._props;
|
||||||
}
|
}
|
||||||
|
|
||||||
addTestDevice() {
|
addTestDevice(deviceId?: string) {
|
||||||
this._props.testDevice = true;
|
this._props.testDevices.push(deviceId ? deviceId : 'DEVICE_ID_EMULATOR');
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,7 @@ export default function addTests({ before, fdescribe, describe, it, firebase })
|
||||||
const build = request.build();
|
const build = request.build();
|
||||||
|
|
||||||
build.should.have.property('keywords').and.be.a.Array();
|
build.should.have.property('keywords').and.be.a.Array();
|
||||||
|
build.should.have.property('testDevices').and.be.a.Array();
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -65,6 +66,7 @@ export default function addTests({ before, fdescribe, describe, it, firebase })
|
||||||
|
|
||||||
request
|
request
|
||||||
.addTestDevice()
|
.addTestDevice()
|
||||||
|
.addTestDevice('foobar')
|
||||||
.addKeyword('foo')
|
.addKeyword('foo')
|
||||||
.addKeyword('bar')
|
.addKeyword('bar')
|
||||||
// .setBirthday() // TODO
|
// .setBirthday() // TODO
|
||||||
|
@ -78,8 +80,10 @@ export default function addTests({ before, fdescribe, describe, it, firebase })
|
||||||
const build = request.build();
|
const build = request.build();
|
||||||
|
|
||||||
build.should.have.property('keywords').and.be.a.Array();
|
build.should.have.property('keywords').and.be.a.Array();
|
||||||
|
build.should.have.property('testDevices').and.be.a.Array();
|
||||||
build.keywords.should.containEql('foo');
|
build.keywords.should.containEql('foo');
|
||||||
build.keywords.should.containEql('bar');
|
build.keywords.should.containEql('bar');
|
||||||
|
build.testDevices.should.containEql('foobar');
|
||||||
build.should.have.property('contentUrl').and.be.a.equal('http://google.com');
|
build.should.have.property('contentUrl').and.be.a.equal('http://google.com');
|
||||||
build.should.have.property('gender').and.be.a.equal('female');
|
build.should.have.property('gender').and.be.a.equal('female');
|
||||||
build.should.have.property('requestAgent').and.be.a.equal('foobar');
|
build.should.have.property('requestAgent').and.be.a.equal('foobar');
|
||||||
|
|
Loading…
Reference in New Issue