gabriel119435
gabriel119435

Reputation: 6812

What in Android Manifest is mandatory?

I have the following activity in Manifest:

<activity
    android:name="com.your.package.name.YourActivity"
    android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

Is category name necessary? And about the android.intent.action? I mean, I see a lot of tutorials and most of them repeat the same rules about suggested names, and how I'm starting, I would like to know what I really can change without making any mistakes

Upvotes: 0

Views: 821

Answers (2)

Parveen Prajapati
Parveen Prajapati

Reputation: 83

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

    <uses-sdk
        android:minSdkVersion="15"
        android:targetSdkVersion="23" />


    <action android:name="android.intent.action.PHONE_STATE" />

    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.PREVENT_POWER_KEY" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />


    <uses-feature
        android:name="android.hardware.camera"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.camera.flash"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.camera.autofocus"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.location"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.location.gps"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.location.network"
        android:required="false" />

    <supports-screens
        android:anyDensity="true"
        android:largeScreens="true"
        android:normalScreens="true"
        android:resizeable="true"
        android:smallScreens="true"
        android:xlargeScreens="true" />
    <uses-feature
        android:name="android.hardware.touchscreen"
        android:required="false" />


    <application
        android:allowBackup="true"
        android:icon="@drawable/app_icon"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">


        <activity
            android:name=".Activity_Class.Splash_Screen"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".Activity_Class.Life_Screen"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar" />


        <activity
            android:name=".Activity_Class.Health_Screen"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar" />


        <activity
            android:name=".Activity_Class.Study_Screen"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar" />


        <activity
            android:name=".Activity_Class.Work_Screen"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar" />


        <activity
            android:name=".Activity_Class.Alarm_Screen"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar"
            android:windowSoftInputMode="stateHidden" />


        <activity
            android:name=".Activity_Class.CalendarView"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar" />


        <activity
            android:name=".Activity_Class.Alarm_Final_Screen"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar" />


        <activity
            android:name=".Activity_Class.View_Pager_Doc"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar" />


        <activity
            android:name=".Activity_Class.Sub_Category_Screen"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar" />


        <activity
            android:name=".Activity_Class.Alarm_Screen_for_user_Review"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar" />


        <activity
            android:name=".Activity_Class.Progress_Screen"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar" />


        <!-- <receiver android:name=".Activity_Class.commonFunctionalityController.AlarmReceiver" />-->
        <receiver
            android:name=".Activity_Class.commonFunctionalityController.AlarmReceiver"
            android:enabled="true"
            android:process=":remote">
            <intent-filter>
                <action android:name="com.elite.youvaa" />
                <action android:name="android.intent.action.DATE_CHANGED" />
                <action android:name="android.intent.action.NOTIFY" />
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.TIME_SET" />
                <action android:name="android.intent.action.TIMEZONE_CHANGED" />
                <action android:name="android.intent.action.TIME_TICK" />
                <action android:name="android.intent.action.REBOOT" />
            </intent-filter>
        </receiver>
        <service android:name=".Activity_Class.commonFunctionalityController.MyAlarmService"
            android:enabled="true" />


    </application>

</manifest>

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1006974

Is category name necessary? And about the android.intent.action?

All ordinary Android SDK applications need at least one <activity> with the <intent-filter> structure that you have in your question. That <intent-filter> says "hey, home screen (and anything else that behaves like a launcher), include an option to start this activity!".

If you have two or more <activity> elements in your manifest, you do not need that <intent-filter> on all of them. Most of the time, you do not want that <intent-filter> on all of them. Have it on your launcher activity, and skip (or alter) it on other activities as needed.

For example, in this sample app, I have two activities defined, but only one has the launcher <intent-filter>:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.commonsware.android.exint"
    android:versionCode="1"
    android:versionName="1.0">

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="11"/>

    <supports-screens
        android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name">
        <activity
            android:name="ExplicitIntentsDemoActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:name="OtherActivity"/>
    </application>

</manifest>

Upvotes: 2

Related Questions