Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: after installing an APK, the open button is disabled

I read in so many places that the problem is related to the manifest and the definition of the first activity. It seems that I'm doing fine but still the open button, after installing the APK, is disabled and I don't see the icon on the device

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

    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

    <activity
        android:name=".MapsActivity"
        android:label="@string/title_activity_maps">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="http"
                android:host="www.example.com"/>

        </intent-filter>
    </activity>
    <activity android:name=".DateSelectorActivity"
        android:label="@string/app_name">
    </activity>
</application>
like image 932
Amos Avatar asked Mar 18 '16 12:03

Amos


1 Answers

Your problem is this:

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="http"
            android:host="www.example.com"/>
    </intent-filter>

Here, you are saying that this activity will only be launched if:

  • the Intent has an action of MAIN or VIEW, and
  • the Intent has the categories of LAUNCHER or BROWSABLE, and
  • the Intent has a Uri with a scheme of http and a host of www.example.com

The home screen launcher and Settings app will not be creating such an Intent, and so they cannot launch this activity.

Either:

  • Remove the VIEW, BROWSABLE, and <data> portions of what you have, or
  • Move those into a separate <intent-filter>:

    <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.VIEW"/>
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="http"
            android:host="www.example.com"/>
    </intent-filter>
    

Multiple <intent-filter> elements represent an OR operation: an Intent that matches the first filter or the second filter will work for this activity.

like image 143
CommonsWare Avatar answered Oct 22 '22 00:10

CommonsWare