Application icon is not visible on android device

2019-05-17 08:56发布

问题:

I am working on a android game.

Its working fine but I have one question if I remove below line from my android manifest the my app icon is visible. If I do not remove these lines then my app icon does not visible on my android.

 <data android:host="mocha" android:path="/RTT/reset"
  android:scheme="content" />

Here is my original android manifest with which icon is not visible:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="ihpc.mocha.rtt"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="12" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_LOGS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <application
        android:name="com.game.rtt.RttGame"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:theme="@android:style/Theme.NoTitleBar" >
        <activity
            android:screenOrientation="sensorLandscape"
            android:name=".MainScene"
            android:label="@string/title_activity_main_scene" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

                 <!-- remove below lines to visible the icon start!!!-->
            <data
                android:host="mocha"
                android:path="/RTT/reset"
                android:scheme="content" />
             <!-- remove below lines to visible the icon end!!!-->
            </intent-filter>

        </activity>

      <activity
            android:name=".SessionTimeOutActivity"
            android:label="@string/app_name" 
            android:screenOrientation="reverseLandscape">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />

                <data
                    android:host="mocha"
                    android:path="/RTT/sessionTimeOut"
                    android:scheme="content" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Please let me know the reason for the same?

回答1:

As of "Using intent matching":

"Intents are matched against intent filters not only to discover a target component to activate, but also to discover something about the set of components on the device. For example, the Android system populates the application launcher, the top-level screen that shows the applications that are available for the user to launch, by finding all the activities with intent filters that specify the "android.intent.action.MAIN" action and "android.intent.category.LAUNCHER" category (as illustrated in the previous section). It then displays the icons and labels of those activities in the launcher. Similarly, it discovers the home screen by looking for the activity with "android.intent.category.HOME" in its filter."

The application launcher does not recognize your launcher activity cause you assume some data for your activity. Please add a new intent filter where you request the data.

Example:

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.SEND"/>
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="application/json"/>
        </intent-filter>


回答2:

It happens the same to me. You can fix it adding the data tag into another intent-filter like this:

        <activity
        android:screenOrientation="sensorLandscape"
        android:name=".MainScene"
        android:label="@string/title_activity_main_scene" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

            </intent-filter>
        <intent-filter>
          <data
            android:host="mocha"
            android:path="/RTT/reset"
            android:scheme="content" />
         <!-- remove below lines to visible the icon end!!!-->
        </intent-filter>

    </activity>


回答3:

I just added this line to the launcher activity in the Manifest and the icon showed up:

<category android:name="android.intent.category.DEFAULT" />

It looks like this:

<activity
            android:name=".MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>