Sketchware Tutorials

How to show admob interstitial ads on sketchware

Make sure you’re using the latest sketchWare version and you can also get it in the play store to integrate AdMob ads

Advertisements

How to show admob interstitial ads on sketchware

 

The first thing to do is to get an AdMob test ads unit…

Test ads units are below

 

App Open ca-app-pub-3940256099942544/3419835294

Advertisements

 

Banner ca-app-pub-3940256099942544/6300978111

 

Interstitial ca-app-pub-3940256099942544/1033173712

 

Interstitial Video ca-app-pub-3940256099942544/8691691433

 

Rewarded ca-app-pub-3940256099942544/5224354917

 

Rewarded Interstitial ca-app-pub-3940256099942544/5354046379

 

Native Advanced ca-app-pub-3940256099942544/2247696110

 

Native Advanced Video ca-app-pub-3940256099942544/1044960115

 

Launch your sketchware Android application download

Click on the “+” icon to create new project for a new work page
Give your application your preferred name. This name should be unique to your app. Change package name to any name…

Click on the three dots to get access to some sketchware components… We need to activate AdMob component here.

Click on AdMob to activate Admob ads services and components
Check previous text for interstitial test ads unit.. insert it where needed..Click on next to activate ads unit
Copy admob ads Id and  ad unit name..Click add and click continue
Activate ads units
Make sure you add test device to prevent admob account termination…Click next
Make to enable all necessary units
Click and drag “Button” component… Check video below on how to align button
On button clicked activity…load interstitial on create and load interstitial on load…Back it
Enables admob interstitial components.. check video for proper tutorial on how to do it
Click on permission and the following permission… Access to Bluetooth… Access to internet
Access to internet permission is vital so we can connect to internet to request for ads
We can build our app now
In case of any error the source code of this code is below

Main activity.java code

package com.my.newproject;
import android.app.Activity;
import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import android.content.*;
import android.content.res.*;
import android.graphics.*;
import android.graphics.drawable.*;
import android.media.*;
import android.net.*;
import android.text.*;
import android.text.style.*;
import android.util.*;
import android.webkit.*;
import android.animation.*;
import android.view.animation.*;
import java.util.*;
import java.util.regex.*;
import java.text.*;
import org.json.*;
import android.widget.Button;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.AdListener;
import android.view.View;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.DialogFragment;
public class MainActivity extends  Activity {
private Button button1;
private InterstitialAd ai;
private AdListener _ai_ad_listener;
@Override
protected void onCreate(Bundle _savedInstanceState) {
super.onCreate(_savedInstanceState);
setContentView(R.layout.main);
initialize(_savedInstanceState);
initializeLogic();
}
private void initialize(Bundle _savedInstanceState) {
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View _view) {
ai = new InterstitialAd(getApplicationContext());
ai.setAdListener(_ai_ad_listener);
ai.setAdUnitId(“ca-app-pub-3940256099942544/1033173712”);
ai.loadAd(new AdRequest.Builder().addTestDevice(“1ED139233582AE549D34C5E5483FAEEB”)
.build());
}
});
_ai_ad_listener = new AdListener() {
@Override
public void onAdLoaded() {
ai.show();
}
@Override
public void onAdFailedToLoad(int _param1) {
final int _errorCode = _param1;
SketchwareUtil.showMessage(getApplicationContext(), “Ads fail load”);
}
@Override
public void onAdOpened() {
SketchwareUtil.showMessage(getApplicationContext(), “Ads shown”);
}
@Override
public void onAdClosed() {
SketchwareUtil.showMessage(getApplicationContext(), “ads closed”);
}
};
}
private void initializeLogic() {
}
@Override
switch (_requestCode) {
default:
break;
}
}
@Deprecated
public void showMessage(String _s) {
Toast.makeText(getApplicationContext(), _s, Toast.LENGTH_SHORT).show();
}
@Deprecated
public int getLocationX(View _v) {
int _location[] = new int[2];
_v.getLocationInWindow(_location);
return _location[0];
}
@Deprecated
public int getLocationY(View _v) {
int _location[] = new int[2];
_v.getLocationInWindow(_location);
return _location[1];
}
@Deprecated
Random random = new Random();
return random.nextInt(_max – _min + 1) + _min;
}
@Deprecated
public ArrayList<Double> getCheckedItemPositionsToArray(ListView _list) {
ArrayList<Double> _result = new ArrayList<Double>();
SparseBooleanArray _arr = _list.getCheckedItemPositions();
for (int _iIdx = 0; _iIdx < _arr.size(); _iIdx++) {
if (_arr.valueAt(_iIdx))
_result.add((double)_arr.keyAt(_iIdx));
}
return _result;
}
@Deprecated
public float getDip(int _input){
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, _input, getResources().getDisplayMetrics());
}
@Deprecated
public int getDisplayWidthPixels(){
return getResources().getDisplayMetrics().widthPixels;
}
@Deprecated
public int getDisplayHeightPixels(){
return getResources().getDisplayMetrics().heightPixels;
}
}

Main xml code

<LinearLayout
xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:app=”http://schemas.android.com/apk/res-auto”
xmlns:tools=”http://schemas.android.com/tools”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical”>
<Button
android:id=”@+id/button1″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginTop=”300dp”
android:padding=”8dp”
android:gravity=”center_horizontal”
android:text=”Button”
android:textSize=”12sp”
android:textColor=”#000000″
android:layout_gravity=”center_horizontal|center_vertical”/>
</LinearLayout>

Android manifest.xml

<manifest
xmlns:android=”http://schemas.android.com/apk/res/android”
package=”com.my.newproject”>
<uses-permissionandroid:name=”android.permission.INTERNET”/>
<uses-permissionandroid:name=”android.permission.ACCESS_NETWORK_STATE”/>
<uses-permissionandroid:name=”android.permission.INTERNET”/>
<application
android:allowBackup=”true”
android:label=”interstitial ads”
android:icon=”@drawable/app_icon”
android:largeHeap=”true”
android:usesCleartextTraffic=”true”
android:name=”.SketchApplication”
android:theme=”@style/AppTheme”>
<activity
android:name=”.MainActivity”
android:configChanges=”orientation|screenSize|keyboardHidden|smallestScreenSize|screenLayout”
android:hardwareAccelerated=”true”
android:supportsPictureInPicture=”true”
android:screenOrientation=”portrait”>
<intent-filter>
<actionandroid:name=”android.intent.action.MAIN”/>
<categoryandroid:name=”android.intent.category.LAUNCHER”/>
</intent-filter>
</activity>
<activity
android:name=”.DebugActivity”
android:screenOrientation=”portrait”/>
<activity
android:name=”com.google.android.gms.ads.AdActivity”
android:configChanges=”keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize”
android:theme=”@android:style/Theme.Translucent”/>
<meta-data
android:name=”com.google.android.gms.version”
android:value=”@integer/google_play_services_version”/>
<uses-library
android:name=”org.apache.http.legacy”
android:required=”false”/>
</application>
</manifest>

Onbutton click code

ai = new InterstitialAd(getApplicationContext());
ai.setAdListener(_ai_ad_listener);
ai.setAdUnitId(“ca-app-pub-3940256099942544/1033173712”);
ai.loadAd(new AdRequest.Builder().addTestDevice(“1ED139233582AE549D34C5E5483FAEEB”)
.build());
Download Android studio file here👇👇👇👇👇

 

Join our Telegram Channel here for more 

 

Advertisements

Leave a Reply

Your email address will not be published.

Back to top button