PYes…. Now You can earn more Money with help of Google adMob its will show advertisement on your application which will get you paid. In this blog will Create Sample android application full code.
- First You Need Ad Mob account.
- Generate Code for advertisement.
- Generate AdUnitID use it in code.
- Create Android Application.
Follow The Steps to Create Bottom and FullScreen advertisement in android.
Step 1: Create android project and Use following code for MainActivity.java
package com.example.tejas.adbannerbottom; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.AdView; import com.google.android.gms.ads.InterstitialAd; public class MainActivity extends AppCompatActivity { private InterstitialAd mIntertitial; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); AdView adView = (AdView) findViewById(R.id.ad_view); //add the cast AdRequest adRequest = new AdRequest.Builder() .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) .build(); adView.loadAd(adRequest); mIntertitial=new InterstitialAd(this); mIntertitial.setAdUnitId("ca-app-pub-6619327831342547/5690314114"); AdRequest request=new AdRequest.Builder() .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) .build(); mIntertitial.loadAd(request); Button showAdButton=(Button)findViewById(R.id.retry_button); showAdButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mIntertitial.isLoaded()) { mIntertitial.show(); } } }); } } Step 2: Use Xml layout code for activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:ads="http://schemas.android.com/apk/res-auto" android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" tools:ignore="MergeRootFrame"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Tejas Gawali" android:id="@+id/textView" /> <com.google.android.gms.ads.AdView android:id="@+id/ad_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" ads:adSize="BANNER" ads:adUnitId="@string/banner_ad_unit_id"/> <TextView android:id="@+id/game_title" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginTop="50dp" android:text="Click Ad" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/timer" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/game_title" android:layout_centerHorizontal="true" android:textAppearance="?android:attr/textAppearanceLarge" /> <Button android:id="@+id/retry_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="Click here" /> </RelativeLayout> Step 3: You need to change Manifest.xml for getting some permissions.
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.tejas.adbannerbottom"> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <application android:allowBackup="true" android:icon="@drawable/logo" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <!--This meta-data tag is required to use Google Play services.--> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!--Include the AdActivity configChanges and theme. --> <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:theme="@android:style/Theme.Translucent" /> </application> </manifest> Step 4: Run the Code... Most Common Mistakes 1: Do edit Manifest.xml 2: while creating app or after creation of application click checkbox for admob integration. Go to Project Structure and Click Ads and Check the Checkbox of AdMob as it is given in the Below image.Please Post Comments if you want any other problems.