Wednesday, 16 July 2025

How to download and install the Android Studio Narwhal

 We know that Android Studio has launched its new version which is Narwhal. So let's download it step by step.



1. At first type "download android studio" in Google search and hit Enter.


2. Then in the search result, select the first one as shown in the image.



3. This will take you to the official website of Android Studio. Here click on the "Download Android Studio Narwhal" button. It will show a pop-up of Terms & Conditions.



4. Read and tick the checkbox which says "I have read and agree with the above terms and conditions". Finally click the Download Android Studio for Windows button. 



5. Save the .exe file where ever you want. It will take time to download as per you internet speed.



6. Once the download is over, open the .exe file. You can open it directly by clicking on the Chrome's download history.



7. Now you will see a installer window. Just keep selecting the Next option every time which is the Recommended setting by Android.



8. You can set the path that you want by clicking the Browse option. If you are fine with the default one, then hit Next.



9. The progressive bar shows that the installation has started and once it will over, it will stop.

 



10. Now click the Next option again to complete the process.



11. Click the Finish button to finish the total installation. Selecting the checkbox Start Android Studio will start the Android Studio right away.



12. Congratulations! Android Studio installed and it is opening!





Sunday, 24 March 2024

Understanding the Android Studio Iguana

 Hi friends, as we know that Android always brings new things in its updates so today we will know what is in the Android Studio Iguana. Also we are going to open a project which will help us write code in Java and not in Kotlin. This is tricky, so be there!

The link to download Android Studio is THIS.

Here is the loading screen of the Android Studio Iguana with its version 2023.2.1 mentioned in it.



Once the loading is done, you will find the Welcome screen with various tabs. Let's start with Projects first:

On the left side we have Projects and other options. First lets see what is inside Project.
New Project: Nothing new, just create a new project either in Kotlin or Java (we will get to the point how we can create a Java project).

Open: Just open the existing Android Studio project from a directory.

Get from VCS: VCS is nothing but Version Control System. You can get a project downloaded through this and GIT would be a common example of it.

There are yet more actions to be performed. Clicking on the same you will find four more things to do:

Import an Android Code Sample: Here you have option to import code samples and run them.

Profile or Debug APK: This is a very interesting tool which will help you in debugging your apk with least efforts.

Virtual Device Manager: Nothing new in this, you know how to check your apps on various configurations. This is what it has!

SDK Manager: This is also inherited from the previous Android Studios. The software development kit that has various SDK platforms, tools etc. 


Here is a quick look of the welcome screen when we have at least one project.



Now comes the next option Customize:

Many user prefer customizing IDEs as per their comfort:

Color Theme: You can make your Android Studio Light, Dark, High contrast etc. The best from most of the developer's view would be Dark as it does not create eye itching issues. 

Sync with OS: By checking this option you don't have to manually change the theme color. It will. automatically select by observing your syste settings.


IDE font: The font size that you want to keep for your IDE. Don't make it 72. I did that and then could not able to change it for a long time because the IDE expanded so that it covered all of my screen.

Keymap: As you can see in the image, you have options to set your keymap to macOS or Eclipse or Visual Studio etc.


Plugins: Plugings are used to add new features or enhance the application. In this you will find various plugings such as Genymotion which will help your app run in various emulators. You can also create Flutter apps by installing this plugin.


Learn: Android Studio has a Learn option which will help us learning it through videos, web articles and also it has a keyboard shortcuts pdfs which will be very useful for all the Android developers.



Settings: The very left down bottom of the welcome screen, you will get a settings icon. Clicking it shows these four options:

Edit custom properties: Through this you have access to change the properties of Android Studio IDE.

Edit custom VM options: The virtual machine properties can be edited through this option.

Collect logs and Diagnostic Data: This has various checks asking you if you want to see the logs and analize the data.


Okay friends we just had a bird's eye on the basic Android Studio IDE. Now we will learn

How to create a project that will allow us to write code in Java.

At first when you open Android Studio and click on New Project you will see that there is no way to code in Java because there will be only Kotlin to code. Those who are Java fans would really have tough time here. So let's see what is needed to get the Java environment working!

After clicking on New Project, we often click on Empty Activity or Basic Views Activity. This creates a Kotlin project. We only have to click the Empty Views Activity to create one for Java.


After clicking the Next button, on configuration screen you have to Select Java for the Language option. At last in Build configuration language, select Groovy DSL (build.gradle).



Congratulations! You can now code in Java for Android Studio.








Sunday, 5 July 2020

Updated: Super fast way to implement latest Admob banner and Interstitial ads

I have something very cool for those who want to implement Admob ads in their Android apps.

This is just a five step process:
1) Add buildscript in build.gradle (project)
2) Add the dependency of Admob in build.gradle (module)
3) Initialize ads,
4) You only have to create an object of AdvertiseUtil.java class which has everything set,
5) Paste the banner ad's small code in your layout,
6) Just call the banner or interstitial ad whichever you want.
You are done!


------------------------------------------ build.gradle (project) ----------------------------------
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
}

plugins {
alias(libs.plugins.androidApplication) apply false
}
------------------------------------------------------------------------

------------------------------------------ build.gradle (module) ----------------------------------
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.app.yourappname"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.google.android.gms:play-services-ads:23.1.0'
}
------------------------------------------------------------------------


-------------------------------- string.xml ---------------------------
<resources>
<string name="app_name">WhatAnAndroid</string>

<!-- Admob Test Ads-->
<string name="ad_app_id">ca-app-pub-3940256099942544~3347511713</string>
<string name="ad_native">ca-app-pub-3940256099942544/2247696110</string>
<string name="ad_interstitial">ca-app-pub-3940256099942544/1033173712</string>
<string name="ad_banner">ca-app-pub-3940256099942544/6300978111</string>
<string name="ad_rewarded">ca-app-pub-3940256099942544/5224354917</string>
<!-- Admob Test Ads-->

</resources>
-------------------------------------------------

------------------------------ admob_ads_activity.xml -----------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_rll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/colorPrimary">

<RelativeLayout
android:gravity="center"
android:id="@+id/aaa_topBannerAdViewRL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"/>

<RelativeLayout
android:id="@+id/aaa_bottomBannerAdViewRL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
</RelativeLayout>
</RelativeLayout>
-------------------------------------------------

------------------------------------- AdvertiseUtil.java ---------------------------------

package app;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.LoadAdError;
import com.google.android.gms.ads.interstitial.InterstitialAd;
import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;
import com.prashantsj.apps.AdmobAdsActivity.R;
public class AdvertiseUtil {

private Context context;
private AdRequest adRequest;
private InterstitialAd mInterstitialAd;
private static final String TAG = "Advertise Util";

public AdvertiseUtil(Context context) {
this.context = context;
}

/********************BANNER***********************/

private AdView adView;

public void loadBannerAd(RelativeLayout layout) {
// Create a new ad view.
adView = new AdView(context.getApplicationContext());
adView.setAdUnitId(context.getString(R.string.AD_BANNER_ID));
adView.setAdSize(AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(context.getApplicationContext(), AdSize.FULL_WIDTH));

// Replace ad container with new ad view.
// adContainerView.removeAllViews();
// adContainerView.addView(adView);showBanner();
layout.addView(adView);
showBanner();
}

public void showBanner() {
AdRequest adRequest = new AdRequest.Builder()
// .addTestDevice("3E98B8F108178758")
.build();
adView.loadAd(adRequest);
}

public void onResumeBanner(){
if(adView!=null)
adView.resume();
}

public void onPauseBanner(){
if(adView!=null)
adView.pause();
}

public void onDestroyBanner(){
if(adView!=null)
adView.destroy();
}

/*********************************************/

/*********************INTERSTITIAL*************************/

public void loadInterstitialAd() {
adRequest = new AdRequest.Builder().build();
InterstitialAd.load(context,context.getString(R.string.AD_INTERSTITIAL_ID), adRequest,
new InterstitialAdLoadCallback() {
@Override
public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
// The mInterstitialAd reference will be null until
// an ad is loaded.
mInterstitialAd = interstitialAd;

Log.i(TAG, "onAdLoaded");
}

@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
// Handle the error
Log.d(TAG, loadAdError.toString());
mInterstitialAd = null;
}
});
}

public void showInterstitialAd() {
if (mInterstitialAd != null) {
mInterstitialAd.show((Activity)context);
loadInterstitialAd();
} else {
Log.d("TAG", "The interstitial ad wasn't ready yet.");
}
}
/*******************************************************/
}

public class AdvertiseUtil {

private Context context;
private InterstitialAd mInterstitialAd;
public AdvertiseUtil(Context context) {
this.context = context;
}

/********************BANNER***********************/

private AdView adView;

public AdView loadBannerAd() {
adView = new AdView(context);
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId(context.getString(R.string.ad_bannerad));
showBanner();
return adView;
}

public void showBanner() {
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
}

public void onResumeBanner(){
if(adView!=null)
adView.resume();
}

public void onPauseBanner(){
if(adView!=null)
adView.pause();
}

public void onDestroyBanner(){
if(adView!=null)
adView.destroy();
}

/*********************************************/

/*********************INTERSTITIAL*************************/

public void loadInterstitialAd() {
AdRequest adRequest = new AdRequest.Builder().build();
InterstitialAd.load(this.context, context.getString(R.string.ad_interstitial), adRequest,
             new InterstitialAdLoadCallback() {
@OptIn(markerClass = UnstableApi.class) @Override
public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
// The mInterstitialAd reference will be null until
// an ad is loaded.
mInterstitialAd = interstitialAd;
Log.i("Interstitial Ad Loaded", "onAdLoaded");
}

@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
// Handle the error
// Log.i("", loadAdError.toString());
mInterstitialAd = null;
}
});
}

public void showInterstitialAd() {
if (mInterstitialAd != null) {
mInterstitialAd.show((Activity) context);
loadInterstitialAd();
}
}

/*******************************************************/
}
-------------------------------------------------

------------------------------------- AdmobAdsActivity.java --------------------------
package com.app.yourappname;

import android.os.Bundle;
import android.widget.RelativeLayout;

import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
import com.app.yourappname.AdvertiseUtil;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class AdmobAdsActivity extends AppCompatActivity {

private AdvertiseUtil au;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.admob_ads_activity);
MobileAds.initialize(this, initializationStatus -> {
        });

au = new AdvertiseUtil(this);

RelativeLayout topBanner = findViewById(R.id.aaa_topBannerAdViewRL);
RelativeLayout bottomBanner = findViewById(R.id.aaa_bottomBannerAdViewRL);

au.loadBannerAd(topBanner);
au.loadBannerAd(bottomBanner);

au.loadInterstitialAd();
}

@Override
public void onUserInteraction() {
super.onUserInteraction();

if(au!=null) au.showInterstitialAd();
}

@Override
protected void onPause() {
super.onPause();
if(au!=null) au.onPauseBanner();
}

@Override
protected void onResume() {
super.onResume();
if(au!=null) au.onResumeBanner();
}

@Override
protected void onDestroy() {
super.onDestroy();
if(au!=null) au.onDestroyBanner();
}
}
-------------------------------------------------

According to the new admob implementation rules, you need to add the app id in manifes
-------------------------- Declare the Activity name and internet permissions in manifest file-----------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app.yourappname">

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

<application
    android:hardwareAccelerated="true"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:targetApi="31">
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="@string/ad_app_id"/>
<activity android:name=".AdmobAdsActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>