Android Tutorial

Software Setup and Configuration

Android Studio

File Structure

Components

Core Topics

Layout

View

Button

Intent and Intent Filters

Toast

RecyclerView

Fragments

Adapters

Other UI Component

Image Loading Libraries

Date and Time

Material Design

Bars

Working with Google Maps

Chart

Animation

Database

Advance Android

Jetpack

Architecture

App Publish

App Monetization

The Android Application Manifest File

The Android Application Manifest file, often simply referred to as the manifest file, is an essential file in every Android application. It is named AndroidManifest.xml and resides at the root of your app module directory. This file provides essential information about the app to the Android system, which the system must have before it can run any app code.

Here's an overview of its primary roles and components:

  1. Package Name & Version:

    • Declares the unique package name of your app. This name serves as a unique identifier for your app on the device and in the Google Play Store.
    • Specifies version information with versionCode (an integer value) and versionName (a string) for your app.
  2. Components Declaration:

    • Registers the app's components (activities, services, broadcast receivers, and content providers). For example, each activity in the app must be declared with a <activity> element.
    • Some components can be declared as having specific capabilities or being able to handle specific intents through intent filters.
  3. Permissions:

    • Declares the permissions that the app needs to work correctly, like accessing the internet, reading contacts, etc.
    • Can also declare permissions that other apps must have if they want to interact with the components of this app.
  4. Features & Requirements:

    • Can specify hardware and software features used by the app, which can affect how the app is filtered on the Play Store. For instance, if an app uses the camera, it can be hidden from devices that don't have a camera.
  5. Intents & Intent Filters:

    • Specifies the types of intents that the components of your app can handle.
    • This is how you can define certain actions like VIEW, SEND, etc., that your app can handle, or declare custom intent actions that other apps can invoke.
  6. App Metadata:

    • Provides metadata about the application, like custom user permissions, or data that needs to be referred to by other components or apps.

Example:

Here's a simple AndroidManifest.xml file for an app with a single activity:

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

    <!-- Version information -->
    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="30" />

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

    <application
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

        <!-- Main activity declaration -->
        <activity android:name=".MainActivity">
            <intent-filter>
                <!-- This filter tells the system that this activity should be the starting point of the app -->
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
        <!-- Other components like services, receivers, etc. would be declared here -->

    </application>
</manifest>

When developing an Android app, you must keep the manifest file updated to ensure that it accurately describes your app's components, permissions, and other critical attributes. Android Studio provides a visual editor for the manifest file, but understanding the XML structure is essential for complex apps or manual modifications.

  1. Components of the AndroidManifest.xml file:

    • Description: The AndroidManifest.xml file is a crucial configuration file in every Android app. It declares essential information about the app, its components, permissions, and required features.
    • Code: (Basic structure)
      <?xml version="1.0" encoding="utf-8"?>
      <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.myapp">
          <!-- Components, permissions, and other declarations go here -->
      </manifest>
      
  2. AndroidManifest.xml file structure:

    • Description: The AndroidManifest.xml file follows a specific structure. It includes declarations for the app's package, application components (activities, services, broadcast receivers), permissions, and other settings.
    • Code: (Basic structure)
      <?xml version="1.0" encoding="utf-8"?>
      <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.myapp">
          <!-- Components, permissions, and other declarations go here -->
      </manifest>
      
  3. Permissions in AndroidManifest.xml explained:

    • Description: Permissions in AndroidManifest.xml specify the system features and resources an app requires. They are crucial for security and control access to sensitive functionalities.
    • Code:
      <uses-permission android:name="android.permission.INTERNET" />
      <uses-permission android:name="android.permission.CAMERA" />
      
  4. Adding activities to AndroidManifest.xml:

    • Description: Activities represent the various screens in an Android app. They need to be declared in the manifest file to be recognized by the system.
    • Code:
      <application>
          <activity android:name=".MainActivity">
              <intent-filter>
                  <action android:name="android.intent.action.MAIN" />
                  <category android:name="android.intent.category.LAUNCHER" />
              </intent-filter>
          </activity>
      </application>
      
  5. Application configuration in AndroidManifest.xml:

    • Description: The <application> element in AndroidManifest.xml allows you to configure global settings for your app, such as theme, icon, label, and more.
    • Code:
      <application
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme">
          <!-- Other components and configurations go here -->
      </application>
      
  6. AndroidManifest.xml uses-feature element:

    • Description: The <uses-feature> element in AndroidManifest.xml specifies the hardware and software features required by the app. It helps filter apps on the Play Store based on device capabilities.
    • Code:
      <uses-feature android:name="android.hardware.camera" />