How to integration google ad in android app. Part - 1Android Development

How to integration google ad in android app. Part - 1Android Development
Dear, Friend in this blog we discussion google ad integration. Many companies work in client base & product base. Product base company in very very important ad integration in the app. Multiple types of AD available like a Facebook ad, start-up ad, google ad, etc. Today we learning google ad integration.
Type of Google AD:
- Banner AD
- Interstitial Ad
- Rewarded Video Ad
- Native Ad
1.Banner Ad
- Banner Ads occupy only a portion of the screen depending on the ad size that is created. It comes in multiple sizes Standard, Medium, Large, Full-Size, Leaderboard, and Smart Banner. Smart banners are very useful when you target multiple device sizes and fit the same ad depending on the screen size.
2.Interstitial Ads
- Interstitial ads occupy the full screen of the app. Basically, they will show on a timely basis, between screen transition or when the user is done with a task.
3.Rewarded Video Ad
4.Native Ad
Create a new project
- Create a new project in Android Studio from File ⇒ New Project.
AdMob
Interstitial
Welcome to Admob. Click on the below button to launch the Interstitial ad.
Show Interstitial Ad
Show Rewarded Video Ad
ca-app-pub-XXXXXXXX~XXXXXXXXXXX
ca-app-pub-XXXXXXXX~XXXXXXXXXXX
ca-app-pub-XXXXXXXX~XXXXXXXXXXX
ca-app-pub-XXXXXXXX~XXXXXXXXXXX
Create a class named MyApplication.java and extend the class from Application.In this application class, we have to globally initialize the AdMob App Id. Here we use MobileAds.initialize()
Open AndroidManifest.xml and add MyApplication to tag.
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544/6300978111"/>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544/6300978111"/>
How can I run my app on my phone without USB connection with my pcAndroid Development

How can I run my app on my phone without USB connection with my pcAndroid Development
We will learn to run the app without connecting a USB cable in this blog. The main purpose of this blog is to let users run apps without any restriction. Sometimes if the cable is connected with the device and if the device cable gets disturbed then the app not run properly.
Let's see how we can run the app without cable.
Step 1: Click File Menu => Settings
Step 2: Click Plugins
Step 3: Install ADB Wi-Fi Plugin
Notes:
- In the third image, I already installed the plugin in my android studio. But in your case, you may need to install it.
- Then your android studio restart.
After the restart, your android studio will show the "ADB Wifi" option showing as per the following image
Click ADB Wifi and the below screen will be displayed.
- Click to connect
- Make sure your device and pc are connected to the same wifi. Otherwise, it will not get connected.
- You will need to connect one time when the android studio is opened the first time.
How to create APK and Bundle in android javaAndroid Development

How to create APK and Bundle in android javaAndroid Development
APK can be created with two types:
1.Debug APK
2.Release APK
- Debug APK is very fast in building and Release APK is a little bit slow.
How to create Release APK File:
- Flowing below all steps
- Open android studio
- Click Build on the toolbar
- Click Generate Signed Bundle/APK.
- Select APK
- Click the Next button
- After clicking the next button, you will see the following dialog.
- Click the "Create new..." button, highlighted in the following image by a red circle if you are creating an APK for the first time. Otherwise, you can choose from existing.
- It will open one another dialog box
- Key store path in select save location .jks file
- Fill in all the information
- Set a valid name for key alias
- Set 100 as validity years
- Fill Certificate Information
- Click OK
- After you click on it, select "release" from the dialog box
- Select "V1 (Jar Signature)" & "V2 (Full APK Signature)" checkboxes
- Click Finish
- It will start the process of building your APK
How to create a debug .apk file
- Click Build and select Build Bundles(s)/APK(s)
- select "Build APK(s)" from the dialog box
- It will start the process of building your debug APK file creating
Useful Shortcut Keys for Android StudioAndroid Development

Useful Shortcut Keys for Android StudioAndroid Development
- Shift+Shift — Search Every Where
- Ctrl+F — Find Text within a Single File
- Ctrl+Shift+F-Find Text in All Files
- Ctrl+R — Replace Selected Text in a Single File
- Ctrl+Shift+R — Replace Selected Text in all Files (Be Careful while Using This)
- Ctrl+Shift+A —Search for IDE Commands
- Ctrl+N — Navigate to Class
- Ctrl+Shift+N — Navigate to a File
- Ctrl+B — Jump to Declarations
- Alt+ ↑ — Jump to the Previous Method
- Alt+↓ — Jump to Next Method
- Ctrl+G — Jump to Line
- Ctrl+E — Recent Files
- Ctrl+Shift+Back Space — Jump to Last Edited Location
- Ctrl+B — Find Declarations
- Ctrl+Left Mouse(or)Ctrl+Alt+F7— Show Usage
- Alt + F7 / Ctrl + F7 — Find usages /Find usages in file
- Ctrl+Shift+B — Find Implementations
- F3 — Find Next
- Shift+F3 — Find Previous
- F11 — Toggle bookmark
- Ctrl+F11 — Toggle bookmark with the mnemonic(0–9 or A-Z)
- Ctrl +(0–9) — Go to numbered bookmark
- Shift+F11 — Show all Bookmarks
- Ctrl + Shift + F7 — Highlight usages in file
- Ctrl + W — Extend selection (selects a word->line->method->Class )
- Ctrl +Shift+ W — Decrease Selection
- Alt + J — Select next occurrence
- Ctrl + Alt + Shift + J — Select all occurrences
- Alt + Shift + J — Unselect occurrence
- Ctrl+Shift+V — Paste from recent buffers (from a History of Copied Contents)
- Ctrl+F6 — Refractor Code
- Ctrl+D — Duplicate a Line/Selected part
- Ctrl+Y — Delete a Line/Selected part
- Ctrl+Q — Quick Documentation
- Ctrl + Space — Code completion
- Ctrl+Shift+Space — Smart code completion (by expected type removes unrelated suggestions)
- Alt+Insert — Generate Code
- Ctrl+J — Insert Live template
- Ctrl + O — Override methods
- Ctrl + I — Implement methods
- Ctrl + Alt + T — Surround with…
- Ctrl + / — Comment / uncomment with line comment
- Ctrl + Shift + / — Comment / uncomment with block comment
- Ctrl+Alt+L — Reformat code
- Ctrl + F9 — Compile and Run Make a project
- Ctrl + Shift + F9 — Compile selected file, package or module
- Shift + F10 — Run
- Shift + F9 — Debug
- Ctrl + Shift + F10 — Run context configuration from editor
- F8 / F7 — Step over / into
- Shift + F7 / Shift + F8 — Smart step into/Step out
- Alt + F9 — Run to cursor
- Alt + F8 — Evaluate expression
- F9 — Resume program
- Ctrl + F8 — Toggle break point
- Ctrl + Shift + F8 — View breakpoints
How to create different type shape in android javaAndroid Development

How to create different type shape in android javaAndroid Development
- 1.Open android studio
- 2.Go to drawable
- 3.right click drawable menu
- flow below image steps:
- -Creating a capsule shape flow below code:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <corners android:bottomLeftRadius="30dp" android:bottomRightRadius="30dp" android:radius="60dp" android:topLeftRadius="30dp" android:topRightRadius="30dp" /> <solid android:color="#CFCFCF" /> <padding android:bottom="0dp" android:left="0dp" android:right="0dp" android:top="0dp" /> <size android:height="60dp" android:width="270dp" /> </shape>
- The below image is showing the shape corner radius
- -Solid means shape inner color “#CFCFCF”
- Its very simple shape width - height
How to create recycler view in android javaAndroid Development
How to create recycler view in android javaAndroid Development
- RecyclerView is used to show the data in the form of a scrollable list. It is a ViewGroup to display a large set of data. For each item in a large dataset, it displays a View. So RecyclerView is very useful no use the scrollable list.
- One reason is so we can create a List through the LinearLayout and the orientation can be vertical. For example, in the Facebook application, all parameters will be the same as share, comment, like, etc. Now if we will take LinearLayout, all the views will create separate views in the memory.
dependencies { implementation "androidx.recyclerview:recyclerview:1.1.0" }
- Androidx in recycler view dependencies: implementation "androidx.recyclerview:recyclerview:1.1.0"
- Your android studio, not androidx: implementation 'com.android.support:recyclerview-v7:28.0.0'
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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" tools:context=".MainActivity"> <androidx.recyclerview.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="match_parent" /> </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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" tools:context=".MainActivity"> <androidx.recyclerview.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="match_parent" /> </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <ImageView android:id="@+id/image" android:layout_width="300px" android:layout_height="300px" android:layout_marginLeft="10dp" android:layout_marginTop="10dp" android:src="@color/colorPrimaryDark" /> <TextView android:id="@+id/description" android:layout_width="250dp" android:layout_height="55dp" android:layout_toRightOf="@id/image" android:layout_marginLeft="15dp" android:layout_marginTop="35dp" android:text="abcd" android:textColor="#000" android:textSize="30sp" /> </RelativeLayout>
public class Data { public String name; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getImageId() { return imageId; } public void setImageId(int imageId) { this.imageId = imageId; } public int imageId; Data(String name, int imageId) { this.name = name; this.imageId = imageId; } }
public class RecyclerView_Adapter extends RecyclerView.Adapter<View_Holder> { List<Data> list = Collections.emptyList(); Context context; public RecyclerView_Adapter(List<Data> data, Application application) { this.list = data; this.context = application; } @NonNull @Override public View_Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { //Inflate the layout, initialize the View Holder View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_layout, parent, false); View_Holder holder = new View_Holder(v); return holder; } @Override public void onBindViewHolder(@NonNull View_Holder holder, int position) { //Use the provided View Holder on the onCreateViewHolder method to populate the current row on the RecyclerView holder.name.setText(list.get(position).name); holder.imageView.setImageResource(list.get(position).imageId); } @Override public int getItemCount() { return list.size(); } }
- onCreateViewHolder()- It inflates the row layout and initializes the view holder. It handles findViewById) (methods, find views once, and recycle them so that repetitive calls are avoided.
- onBindViewHolder()- It uses the onCreateViewHolder() View Holder to fill in the current RecyclerView row with data.
- getItemCount()- This method returns the collection size which contains the items that we wish to show.
import android.view.View; import android.widget.ImageView; import android.widget.TextView; import androidx.recyclerview.widget.RecyclerView; public class View_Holder extends RecyclerView.ViewHolder { TextView name; ImageView imageView; View_Holder(View itemView) { super(itemView); name = (TextView) itemView.findViewById(R.id.name); imageView = (ImageView) itemView.findViewById(R.id.image); } }
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); List<Data> data = fill_with_data(); RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView); RecyclerView_Adapter adapter = new RecyclerView_Adapter(data, getApplication()); recyclerView.setAdapter(adapter); recyclerView.setLayoutManager(new LinearLayoutManager(this)); } public List<Data> fill_with_data() { List<Data> data = new ArrayList<>(); data.add(new Data("Android", R.drawable.c)); data.add(new Data("Kotlin", R.drawable.cc)); data.add(new Data("Kotlin", R.drawable.ccc)); return data; } }
How to create any API response model class in android javaAndroid Development

How to create any API response model class in android javaAndroid Development
- Developer use API calling retrofit, volley JSON or other tools but API response check-in postman time confusion how to creating this response model class
- So a friend in this topic I will try your confusion remove flow below all steps and 5 min inner creating a wonderful model class
- Location in the android studio:
- Open android studio
- Go to File
- Go to Setting
- Click plugin
- check the below image && click and install RoboPOJOGenerator then your android studio restart
- Open android studio
- Go to File
- Select directory below the image in showing related select any one directory
- Right-click - select New - then below showing "RoboPOJOGenerator"
- Postman response copy
- Paste this response in "RoboPOJOGenerator" in one black color dialog showing in android studio
- Left top side one cursor visible on this area in paste this response
- Select "GSON" option in "RoboPOJOGenerator"
- Last click generate button after a few moments your model class is ready
Facebook Login With Firebase In Android JavaAndroid Development

Facebook Login With Firebase In Android JavaAndroid Development
- This library user for firebase integration dependencies
{ implementation 'com.google.firebase:firebase-auth:19.4.0' }
- This permission use internet connection checking
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.INTERNET" />
<com.facebook.login.widget.LoginButton android:id="@+id/login_button" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:visibility="gone" />
- This permission user for user data get. Without this permission user data not meet
“loginButton” This button is Facebook button
- LoginManager.getInstance().logInWithReadPermissions(FacebookLoginActivity.this, Arrays.asList("email", "public_profile"));
- loginButton.setReadPermissions("email", "public_profile");
void initializeAuthentication(){ FirebaseAuth mAuth = FirebaseAuth.getInstance(); GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(getString(R.string.default_web_client_id)) .requestEmail() .build(); mGoogleSignInClient = GoogleSignIn.getClient(this, gso); }
- This function user login result return
void faceBookLogin(LoginResult loginResult){ setFacebookData(loginResult); Profile profile = Profile.getCurrentProfile(); if (profile != null) { String avatar = ImageRequest.getProfilePictureUri(profile.getId(), 200, 200).toString(); } handleFacebookAccessToken(loginResult.getAccessToken()); }
- This token return firebase login fails or not an event
private void handleFacebookAccessToken(AccessToken token) { AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); mAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { FirebaseUser user = mAuth.getCurrentUser(); user.getIdToken(true).addOnCompleteListener(new OnCompleteListener<GetTokenResult>() { @Override public void onComplete(@NonNull Task<GetTokenResult> task) { String token = task.getResult().getToken(); } }); } else { String errorCode = String.valueOf(task.getException()); Toast.makeText(FacebookLoginActivity.this, "Login failed.", Toast.LENGTH_SHORT).show(); } } }); }
- “Default_web_client_id” this keyword, not changes because creating google-services.json file time automatically this keyword in add values so this key work put at its
