Monday, 30 July 2018

How to Integrate Google Banner AdMob in your App

AdMob is a platform mobile ad network that allows you to monetize your android app. By integrating Admob you can earn some money from your free app.

Integrating AdMob is such an easy task. FirstBannerAds app with one screen to show the Banner ads that AdMob supports.


A.) Create AdMob Account

Step-1. Sign into your AdMob account.
Step-2. Create a new App by giving the package name of the app you want to integrate AdMob.
Step-3. Select App and create a new ad unit.
Step-4. Select the Banner ad format and give the ad unit a name.
Step-5. Once the ad unit is created, copy both id and paste your android project/app:-
             App Id: ca-app-pub-XXXXXXXXX~XXXXXXXXX.
             Ad Unit Id: ca-app-pub-066XXXXXXX/XXXXXXXXXXX

See full android interview questions: Android Interview Questions

B.) Create New Project

Step-1. Create a new project in Android Studio
             File -> New Project -> Empty Activity.

Step-2. Open build.gradle(Project: FirstBannerAds) and add below code.

  allprojects {
     repositories {
         google()
         jcenter()
         maven {
            url "https://maven.google.com"
           }
       }
  }

Step-3. Open build.gradle(Module: App) and add play services dependency and click sync now.

 implementation 'com.android.support:appcompat-v7:26.1.0'
 implementation 'com.android.support:cardview-v7:26.1.0'
 implementation 'com.google.android.gms:play-services-ads:15.0.1'
 // play services dependency as AdMob requires it.

Step-4. Add below required uses-permission in AndroidManifest.xml.

 <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Step-4. Add below code in 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" 
   android:layout_height="match_parent" 
   android:layout_width="match_parent"
    android:padding="12dp" tools:context=".MainActivity">

    <TextView android:text="@string/hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView" 
       android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"        
        ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
    </com.google.android.gms.ads.AdView>

</RelativeLayout>


*Note: Ad Unit Id: ca-app-pub-3940256099942544/6300978111 testing AdMob. Be assure, before publish app on google play store change this Ad Unit Id to your own unit id.

Step-4. Add below code in MainActivity.java


package com.example.firstbannerads;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

public class MainActivity extends AppCompatActivity {

    private AdView mAdView;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        MobileAds.initialize(this, "ca-app-pub-XXXXXXXXX~XXXXXXXXX");

        mAdView = findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);

    }
}

Step-4. Now run the app.




See full android interview questions: Android Interview Questions





Tuesday, 24 July 2018

Android Interview Questions

Q. What is Android?
A. Android is an open-source, linux-based operating system that is used in mobiles, tablets, televisions etc.

In other words, Android is a software which comes with four major component.
1. Operating System(Linux O.S)
2. Library layer(Set of c/c++ programs written by Google)
3. API / Framwork layer(Written by Google)
4. Application layer(Eg. Message, Call, Alarm etc)

Require Software installation:-
1. JDK 1.8
2. Android Studio 2.0, 2.2.., 3.0, 3.1..
3. Android SDK 8.0/9.0(Minimum space 7GB)
4. GenyMotion s/w(Optional)

Q. Which kernel is used in Android?
A. Android is customized Linux 3.6 kernel

Q. What is ADT in Android?
A. ADT stands for Android Development Tool. It is used to develop the applications and test the applications.

Q. Who is the founder of Android?
A. Andy Rubin.

Q. What is Build.gradle?
A. Build.gradle is a predefined tool which comes along with android studio. This file build the application and generate .apk file.

Q. What is .apk file?
A. .apk is android application package. It is final install able file on the phones and tablets.

See full: Android Interview Questions

Q. What is ADB?
A. ADB is Android Debug Bridge tool. It is a tool which comes along with android studio. ADB establish connection between android studio and phone. It pushes .apk file to drive.

In other words, ADB stands for Android Debug Bridge. It is a command line tool that is used to communicate with the emulator instance.

Q. What is AAPT?
A. AAPT is an acronym for android asset packaging tool. It handles the packaging process.

Q. What is DDMS?
A. DDMS stands for Dalvik Debug Monitor Server. It gives the wide array of debugging features:

Port forwarding services
Screen capture
Thread and heap information
Network traffic tracking
Location data spoofing

Q. What is ANR?
A. ANR stands for Application Not Responding. It is a dialog box that appears if the application is no longer responding.

Q. What is broadcastreceiver in android?
A. It is a component of android which responds to system wide broadcast announcments.

It acts like a gateway between outside world and your application.

Q. Broadcast receiver runs in which thread, by default?
A. Default every component of android will run in Main thread (UI thread). So broadcast receiver also runs in main thread by default.

Q. Is it possible to start a service from a broadcast receiver?
A. Any component can communicate with other component. Only exception for this rule is don't bind to a service from a broad cast receiver. other wise one is free to start a service.

Q. What is content provider?
A. Content providers are used to share information between android applications.

Q. How to start a content provider using an intent?
A. For content provider we have to use content resolver to communicate.

Q. What is the use of content provider? Will it support shared preferences?
A. It is used to share an application's data with out side world. Right now there is no support for shared preferences.

Q. What is the difference between contentprovider and contentresolver?
A. Content provider is used to share private data with other applications.

Content resolver communicates from client end with content provider.

Q. What is the difference between cursor & contentvalues?
A. Cursor is buffer which holds rows(results) from db table on querying. Content values is used to pass data to SQLite functions.

Q. How to get contact phone number from contacts application's content provider?
A. Use ContactsContract.Contacts.URI and commonDataKinds. Phone.CONTENT_URI, then request it through content resolver.

Q. Where does the SQLite database of an android application get stored in memory?
A. By default it is stored in internal memory, but it is also possible to store it in sd card also.

Q. What is Intent?
A. Intent is a predefined class of android layer. Using intent we can start other activities.

In other words, it is a kind of message or information that is passed to the components. It is used to launch an activity, display a web page, send sms, send email etc.
Q. How do you pass data to other screens / activities?
A. By using,
1. Intent class
2. putExtra() method
3. startActivity() method

Q. What is Bundle?
A. Bundle is a predefined class of android layer. It is a container which carries data. Bundle will be created when we say putExtra() method.

Note: Internally bundle will use HashMap to store key value pairs.

Read more at: Android Interview Questions