Use the native Admob SDK with Axway Hyperloop. Right now this module is Android only, and only supports Interstitial Ads.
- Copy the
titanium-admob
folder to yourlib/
(Alloy) or yourResources/
(Classic) directory. - Copy the example code to your Titanium app (in case of a Classic app adjust the code to fit your needs).
- Include the
hyperloop
andti.playservices
modules in your tiapp.xml. - Adjust
tiapp.xml
to support the ad type as explained below. - Make sure you have
<transpile>true</transpile>
added in tiapp to support ES6. - Go for it!
You need to add a manifest to your app with an extra activity to support Interstitial ads. It should look like this:
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest android:installLocation="auto" android:versionCode="1"
android:versionName="1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<application>
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
<activity
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:name="com.google.android.gms.ads.AdActivity"/>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
</manifest>
</android>
Right here we're creating a new ad using the Google Default app/ad ID's. As soon as the onAdLoaded
event is fired, you can show the ad using ad.show();
Check the sample how it's implemented.
import { ADTYPES, AdView } from 'titanium-admob';
const appAd = new AdView({
adType: ADTYPES.AD_TYPE_INTERSTITIAL,
appId: 'ca-app-pub-3940256099942544~3347511713',
adId: 'ca-app-pub-3940256099942544/1033173712',
onAdLoaded : () => {
alert('ad loaded!');
},
onAdClosed: () => {
setTimeout(() => {
appAd.load();
},2500);
}
});
const ad = appAd.ad;
In this example we're loading a new ad after 2,5 seconds after the ad has closed, but you're free to pre-load whenever your want. Keep in mind it might take some time before the ad is loaded.
Look at the native docs to see any other specifications and notes.
MIT
© 2018 by Appcelerator