Android Development's post

post

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

- In this ad, shows a video type ad.

4.Native Ad

- In this app in full description ad showing.

Create a new project 

- Create a new project in Android Studio from File ⇒ New Project.

- Open build. Gradle and add play services dependency as AdMob requires it.

compile ‘com.google.android.gms:play-services-ads:11.8.0’

build.gradle
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:26.1.0'
    compile 'com.android.support:design:26.1.0'
 
    compile 'ccom.google.android.gms:play-services-ads:11.8.0'
}

Add the App ID and Ad unit IDs to your strings.xml. 

    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() 


MyApplication.java
 
public class MyApplication extends Application {
 
    @Override
    public void onCreate() {
        super.onCreate();
         MobileAds.initialize(this, getString(R.string.admob_app_id));
    }
}

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"/>

January 18, 20212 minutesauthorPankaj Valani
post

Basically, it works like a stack where each view is stacked on top of the other.

Create a drawable file for shadow view and assign the name image_shadow and add the below code in this file.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="10dp" />
    <gradient
    android:angle="270"
    android:centerX="300%"
    android:endColor="#99000000"
    android:startColor="#00000000"
    android:type="linear" />
    <size
    android:width="270dp"
    android:height="60dp" />
    <stroke
    android:width="1dp"
    android:color="#878787" />
</shape>

Now, open xml file and add the below code into it, and set this drawable file as view background.

<androidx.appcompat.widget.LinearLayoutCompat
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity">
<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <androidx.appcompat.widget.AppCompatImageView
        android:id="@+id/imageView"
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:scaleType="centerCrop"
        android:src="@drawable/shopping_image"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"/>
    <View android:id="@+id/view"
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:background="@drawable/image_shadow"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"/>
    <androidx.appcompat.widget.AppCompatTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:textColor="@android:color/white"
        android:text="Write your text here"
        android:textSize="25sp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="@+id/view"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.appcompat.widget.LinearLayoutCompat>

That's it. You should be ready to go.

January 11, 20211 minuteauthorVivek Beladiya
post

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.
January 11, 20211 minuteauthorPankaj Valani
post
Snackbars are fairly common in the Android app. Almost every app uses a snack bar to display some information about what's going on in the app. You can consider Snackbar as an alternative or the best version of Toasts in Android.

Step 1:- Using a normal Snackbar

To use Snackbar in your app, you just have to have the material design dependency in your app. Add Material design dependency to your build.Gradle app-level.

dependencies {
    implementation "com.google.android.material:$latest_version"
}
And then you can use the snack bar just like toast. For example:

Snackbar.make(view, "Show some message here", Snackbar.LENGTH_SHORT).show()
Step 2: Working with the MainActivity.xml


<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.application.snackbarapp.MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="show snackbar" />

    </RelativeLayout>

</android.support.design.widget.CoordinatorLayout>
Step 3: Creating a custom layout for a snack bar

Under Layout, the folder creates a layout for the snack bar that must be inflated when creating a snack bar under the mainactivity.java file.

import android.graphics.Color;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    private CoordinatorLayout coordinatorLayout;
    private Button button;

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

        coordinatorLayout = findViewById(R.id.coordinatorLayout);
        button = findViewById(R.id.button);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showSnackbar();
            }
        });
    }

    public void showSnackbar() {
        Snackbar snackbar = Snackbar.make(coordinatorLayout, "Marked as Read", Snackbar.LENGTH_INDEFINITE)
                .setAction("UNDO", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Snackbar snackbar1 = Snackbar.make(coordinatorLayout, "Undo successful", Snackbar.LENGTH_SHORT);
                        snackbar1.show();
                    }
                })
                .setActionTextColor(Color.RED);

        snackbar.show();
    }
}

January 02, 20211 minuteauthorVivek Beladiya
post
While developing apps in Android Studio, developers can create an APK file and share it with other developers or to QA people for testing purposes.
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.
    c1.PNG 14.37 KB
  •  Select APK 
  • Click the Next button
    c2.PNG 14.5 KB
  • 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.
    c3.PNG 13.29 KB
  • 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 
January 01, 20211 minuteauthorPankaj Valani
post
Hello, friend short cut way all people like. but remember a short cut is improved your self and save time it's a very good way. so in this blog learning the android studio shortcut key.use all short cut key and save time and performance improve 

image1.png 70.61 KB
Search Keys :


  • 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
Navigation Keys  :

  • 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
BookMark Keys :

  • 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
Selection Keys :

  • 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)
Editing Keys :

  • 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
Run  :

  • 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
Debugging  :

  • 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

December 25, 20202 minutesauthorPankaj Valani
post
what is a SplashScreen?

A splash screen is a screen that appears when you open an app on your mobile device. So, we can say that it is the first impression for the user. It is commonly used to show an application logo or an image associated with an application.



















Implementation

So instead of using a layout file, we'll refer to the splash screen as the background of the activity theme. first, create an XML drawable splash_background.xml inside res/drawable folder in

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@color/white" />
    
    <item
        android:drawable="@drawable/ic_icon_vector"
        android:gravity="center" />

</layer-list>
 next step, set splash_groundground.xml as the background for your splash activity in the theme. Add a new splash to your splash activity.


<!-- Splash Screen theme. -->
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/splash_background</item>
</style>
Add your theme to AndroidManifest.xml as your splash activity theme.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.exmple.splash">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme">
        
        <activity
            android:name=".SplashActivity"
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
Create a blank activity for SplashActivity.java without XML. This class will only redirect to MainActivity.java.

public class SplashActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        startActivity(new Intent(SplashActivity.this, MainActivity.class));
        finish();
    }
}



December 25, 20201 minuteauthorVivek Beladiya
post
Hello, wonderfully friends today in this blog in learning in android XML file creating different type shape creating. A shape is an XML file that defines a geometric shape, including strokes, colors, and gradients


First Creating .xml file :

  • 1.Open android studio
  • 2.Go to drawable 
  • 3.right click drawable menu
  •  flow below image steps:


Now friend starts coding :


  • -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>


Corners:

  • The below image is showing the shape corner radius
Solid :

  • -Solid means shape inner color “#CFCFCF”

Padding:

- There is always confusion developer between padding and margin. Both provide extra space/gap inside or outside the container. In simple words, margin means to push outside, whereas padding means to push inside.

Size:

  •  Its very simple shape width - height 
December 21, 20201 minuteauthorPankaj Valani