Kamis, 11 Mei 2023

How to integrate Admob interstitial ads using​ AIDE?

AIDE can be used to integrate Admob Ads to a Sketchware project. Follow the steps below to integrate Admob interstitial ads to a sketchware project using AIDE.

Prerequisites
  • An Android project (Sketchware project)
  • AIDE with pro account key purchased
  • Account in Google developer console
  • Account in Admob
Before placing admob ads in an app, the app needs to be uploaded to google play store, however test ads can be tried in any app.

Always place the test ad ID before placing your ad unit ID. App ID and ad unit ID can be obtained by registering the app on Admob. But for using test ads no registration is required.

Do not click on your own Ads.

Export the Sketchware project

In Sketchware, under MY PROJECTS, go to project settings of the app to be exported, and click on Export to PC (Android Studio).
The exported file is a zip file. Create a new folder and decompress the contents of the zip file in it.

Check whether the res folder at location app/src/main/res contains only layout folder with all xml files or it contains all other folders like drawable, drawable-xhdpi, raw, values, values-v21. If all these folders are present then move to the next step of editing AndroidManifest.xml.

Edit the AndroidManifest.xml file

Open AIDE, browse to the AndroidManifest.xml file of the exported project and open it.

In manifest element, after package name, add following:
 android:versionCode="2"
 android:versionName="1.2"
Change version code and version name as per your project.
After that add the following permissions:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

In application element, add the following meta-data:
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

Also add the following activity:
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />

Save the file after editing.

Edit MainActivity.java file

Add the following code in imports:
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.AdListener;

After the code 'public class MainActivity extends Activity {' add the following code:
private InterstitialAd mInterstitialAd;

After that create and load ad by adding following code after line 'setContentView(R.layout.activity_main);' in onCreate event:
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
mInterstitialAd.loadAd(new AdRequest.Builder().build());

After testing with test ads replace the adUnitId with your own adUnitId.

Then after the code to create and load ad, add code for adListener just below it:

mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
Log.i("Ads", "onAdLoaded");
}

@Override
public void onAdFailedToLoad(int errorCode) {
// Code to be executed when an ad request fails.
Log.i("Ads", "onAdFailedToLoad");
}

@Override
public void onAdOpened() {
// Code to be executed when the ad is displayed.
Log.i("Ads", "onAdOpened");
}

@Override
public void onAdLeftApplication() {
// Code to be executed when the user has left the app.
Log.i("Ads", "onAdLeftApplication");
}

@Override
public void onAdClosed() {
// Code to be executed when when the interstitial ad is closed.
Log.i("Ads", "onAdClosed");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
}
});

Add code to show the ad

The code to display interstitial ads has to be added to the event or activity when the ad is intended to be displayed. The code for displaying ads is:
if (mInterstitialAd.isLoaded()) {
            mInterstitialAd.show();
        } else {
           Log.d("TAG", "The interstitial wasn't loaded yet.");

        }

If you want to display ads on page start then it should look like this:

@Override
public void onStart() {
super.onStart();
if (mInterstitialAd.isLoaded()) {
            mInterstitialAd.show();
        } else {
            Log.d("TAG", "The interstitial wasn't loaded yet.");
        }
}

Changes to build.gradle file

Navigate to app level build.gradle and Add following to project:
'com.google.android.gms:play-services-ads:+'

Also, in build.gradle file change version code and version name to same as in AndroidManifest.xml.
Save the file.

After this if you find no errors, then run the project. If you find the error 'R cannot be resolved', then go to AndroidManifest.xml and make any small change like removing a space and then save the file again. If you find any other error, try to resolve as per the error message.

Watch the video below to understand better:


This post is only regarding integration of Admob interstitial ads. The App ID and Ad unit ID used here are those for test ads and can be used in any android project. The ad unit ID for interstitial ads and banner ads are different.

For banner ads integration using AIDE click here.
Share:

0 komentar:

Posting Komentar

Alam terbuka mengasyikkan di Destinasi impian

Jasa Pembuatan Website Archives - Legenda Web

loading...

Archive

Cari Blog Ini

Diberdayakan oleh Blogger.

Mengenai Saya

Foto saya
Saya memiliki Jasa Pembuatan Website Terpercaya
www.legendaweb.com

Pernah mengerjakan seo untuk Agen Travel door to door ecopremieretransindo.com dan Agen Travel Jakarta Jogja jakjogtrans.com

Juga memegang SEO Biro jasa paspor

Selain Itu, kerjasama dengan Sewa Mobil Bali Mai Bali Trans dan Industri pariwisata trip Bali dari beautrip.id

Labels

Admob ads in Sketchware Admob Ads in Sketchware App admob ads using AIDE Admob banner ads using AIDE Admob interstitial Ads Android app Android change status bar color animation in Sketchware background music Change color of checkbox in Sketchware change color of Seekbar change color of Switch button change status bar color code for moving image with finger in android code Injection create and share text file in Sketchware create text file in Sketchware Custom listview in android Custom ListView in Sketchware CustomView in Sketchware Dictionary Android App Dictionary Android project Dictionary App Dictionary App in Sketchware drag image enable download from Sketchware enable download in webview enable download without code Injection Enable image upload enable upload from webview enable upload from webview in android enable upload in Sketchware enable upload in webview​ using AIDE enable upload using AIDE gif image in Android App gif image in webview how to use ListView in Sketchware how to use Spinner image zoom Integrate Admob Ads in Sketchware Intent large paragraphs in Sketchware larger texts in Edittext. limit input text length load image in webview make image fit screen make scrollbar invisible media player move image with finger notification icon in Android notification in Android Notifications in Sketchware open other apps retrieve APK file retrieve source code share button share button in Android App share button in Sketchware App Share text file Sketchware sound on off sound play pause soundpool Soundpool for Multiple sounds Sounds in Android App stopwatch Android App Stopwatch App string list timer use of list