Sketchware Tutorials

Admob banner ads in sketchware

Sketchware is a mobile-based programming tool app that has so many features , Well showcase hot show banner ads using shetcware today..

Advertisements

How to implement admob banner ads in sketchware

It is advisable that amateur developers should start coding with this drag and drop tool which is very much easier to use.

So today we learning how to implement

AdMob banner ads using sketchware

Firstly,

Launch your sketchware application

Advertisements

Create a new project

On the next page enter your preferred app name

Change your package name

Name your project

and click on “Create app”

Click on the three-dot on your home dashboard

Click on “library”option

Activate AdMob component

Check google developer page to get test ads unit

Place the ads unit

Copy banner ads unit and place according to the picture below

click add

Click on edit to activate ads unit for both Banner AD and Interstitial AD

It is very compulsory to add test device to prevent invalid activity on admob

Pick the same ad unit for both banner and interstitial for the use of this tutorial

click save and continue

On the sketchware activity choose “adview”

Drag it into  the activity

Click ” oncreate ” option to add some activity

Click the code icon and draw follow the following step

Click on view

search for “Adview load”

Drag the “Adview load” component to oncreate activity

Activate the adview widget by clicking the drop down arrow and ticking the adview

We are done

click on “run” to compile our code

After compiling the codes

Install the app on your phone

More practical on our youtube channel

watch and  subscribe to the channel

Some codes are below

                AD REQUEST WITH TEST DEVICE

adview1.loadAd(new AdRequest.Builder().addTestDevice(“CCF960FFA0705382F8AB610166D39739”)
.build());

                              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”>
<com.google.android.gms.ads.AdView
android:id=”@+id/adview1″
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
app:adSize=”SMART_BANNER”
app:adUnitId=”ca-app-pub-3940256099942544/6300978111″/>
</LinearLayout>

                        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 com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.AdRequest;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.DialogFragment;
public class MainActivity extends  Activity {
private AdView adview1;
@Override
protected void onCreate(Bundle _savedInstanceState) {
super.onCreate(_savedInstanceState);
setContentView(R.layout.main);
initialize(_savedInstanceState);
initializeLogic();
}
private void initialize(Bundle _savedInstanceState) {
adview1 = (AdView) findViewById(R.id.adview1);
}
private void initializeLogic() {
adview1.loadAd(new AdRequest.Builder().addTestDevice(“CCF960FFA0705382F8AB610166D39739”)
.build());
}
@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
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;
}
}

                 ANDROID MANIFEST.XML CODE

<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”/>
<application
android:allowBackup=”true”
android:label=”fgb”
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>

                           STYLE.XML CODE

<resources>
<stylename=”AppTheme”parent=”@android:style/Theme.Material.Light.DarkActionBar”>
<itemname=”android:colorPrimary”>@color/colorPrimary</item>
<itemname=”android:colorPrimaryDark”>@color/colorPrimaryDark</item>
<itemname=”android:colorAccent”>@color/colorAccent</item>
<itemname=”android:colorControlHighlight”>@color/colorControlHighlight</item>
<itemname=”android:colorControlNormal”>@color/colorControlNormal</item>
</style>
<stylename=”FullScreen”parent=”@android:style/Theme.Material.Light.NoActionBar.Fullscreen”>
<itemname=”android:colorPrimary”>@color/colorPrimary</item>
<itemname=”android:colorPrimaryDark”>@color/colorPrimaryDark</item>
<itemname=”android:colorAccent”>@color/colorAccent</item>
<itemname=”android:colorControlHighlight”>@color/colorControlHighlight</item>
<itemname=”android:colorControlNormal”>@color/colorControlNormal</item>
</style>
<stylename=”NoActionBar”parent=”@android:style/Theme.Material.Light.NoActionBar”>
<itemname=”android:colorPrimary”>@color/colorPrimary</item>
<itemname=”android:colorPrimaryDark”>@color/colorPrimaryDark</item>
<itemname=”android:colorAccent”>@color/colorAccent</item>
<itemname=”android:colorControlHighlight”>@color/colorControlHighlight</item>
<itemname=”android:colorControlNormal”>@color/colorControlNormal</item>
</style>
<stylename=”NoStatusBar”parent=”AppTheme”>
<itemname=”android:windowFullscreen”>true</item>
</style>
</resources>

                        COLOUR.XML CODE

<resources>
<colorname=”colorPrimary”>#008DCD</color>
<colorname=”colorPrimaryDark”>#0084C2</color>
<colorname=”colorAccent”>#008DCD</color>
<colorname=”colorControlHighlight”>#008DCD</color>
<colorname=”colorControlNormal”>#57BEEE</color>
</resources>

Advertisements

Leave a Reply

Your email address will not be published.

Back to top button