Необходимо добавить необходимые библиотеки. Есть вопрос, как установить их в локальный репозиторий here.
После того, как вы установили библиотеки и указали их в своем проекте андроида, вы сможете использовать AdMob. Следуйте описанию здесь, чтобы wrap the DukeScript MainActivity в вашей собственной MainActivity. Затем вы сможете создавать рекламу в методе onCreate as described here.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
public class AndroidMain extends Activity {
private InterstitialAd mInterstitialAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mInterstitialAd = new InterstitialAd(this.getApplicationContext());
mInterstitialAd.setAdUnitId("pub-99999999999999999/9999999999");
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("adb logcat will show you the id")
.build();
// Prepare an Interstitial Ad Listener
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
displayInterstitial();
}
@Override
public void onAdClosed() {
startActivity(new Intent(getApplicationContext(),
com.dukescript.presenters.Android.class));
finish();
}
});
mInterstitialAd.loadAd(adRequest);
}
public void displayInterstitial() {
// If Ads are loaded, show Interstitial else show nothing.
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
Toast.makeText(getApplication(), "The asd has not Loaded.", Toast.LENGTH_SHORT).show();
}
}
public static void main(String... args) throws Exception {
Main.onPageLoad();
}
}
Если вы закончили, что изменить ваш pom.xml включать не только банку, но и apklib из сервисов Google Play:
<groupId>com.google.android.gms</groupId>
<artifactId>google-play-services</artifactId>
<version>28.0.0</version>
<type>apklib</type>
</dependency>
<dependency>
<groupId>com.google.android.gms</groupId>
<artifactId>google-play-services</artifactId>
<version>28.0.0</version>
<type>jar</type>
</dependency>
Вы Виль также должны изменить свой AndroidManifest .xml и добавить некоторые разрешения и действия. Вот код для вашего приложения:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="web.aprendiendola.dictionaryweb.aprendiendola.dictionary.DiccionarioDeJava"
android:versionCode="1"
android:versionName="1.0-SNAPSHOT" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="DiccionarioDeJava"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
<activity android:name="web.aprendiendola.dictionaryweb.aprendiendola.dictionary.DiccionarioDeJava.AndroidMain"
android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.dukescript.presenters.Android"
android:configChanges="orientation|screenSize"
android:exported="false"
>
</activity>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<!-- Configuration section. Defines:
- the HTML page to load on start
- the class that contains the main initialization method
- name of the initialization method in the given class
-->
<meta-data android:name="loadPage" android:value="file:///android_asset/pages/index.html" />
<meta-data android:name="loadClass" android:value="web.aprendiendola.dictionaryweb.aprendiendola.dictionary.DiccionarioDeJava.AndroidMain" />
<meta-data android:name="invoke" android:value="main" />
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
</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"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
</manifest>
Это все, вы должны теперь иметь возможность показывать объявление. Это работает для меня с приложением, которое вы мне прислали.
Спасибо Так много мистера Эппле Это работало как шарм! –