Android: Disable application for tablet

Manoj Fegde picture Manoj Fegde · Aug 14, 2013 · Viewed 17k times · Source

I developed an application, Now i want to restrict the application for tablet.

Means the application should not run on any tablets. For that I specify the support-screens in Androidmenifest.XML file as:

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

<uses-sdk
    android:minSdkVersion="5"
    android:targetSdkVersion="17"
    android:maxSdkVersion="17" />

<supports-screens 
    android:smallScreens="true"
    android:normalScreens="true" 
    android:largeScreens="false"
    android:xlargeScreens="false"
    android:resizeable="true"
    android:anyDensity="true" />

<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<application
    android:icon="@drawable/appicon"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Black.NoTitleBar"
    android:allowBackup="true" >

    <activity
        android:name="com.abc.xyz.activities.hello"
        android:label="@string/title_activity_hello" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

</manifest>

Now the issue is that :

Application is running on tablet

 android:largeScreens="false"
 android:xlargeScreens="false"

After declaring above too.

Now what should i do. Please suggest me and guide me.

Answer

SharkAlley picture SharkAlley · Jul 21, 2014

This prevents access on tablets, but allows the new density buckets (xxhdpi and xxxhdpi) and avoids errors on projects that are compiled against lower SDKs. It should be a direct child of the <manifest> element in AndroidManifest.xml

<compatible-screens>
    <!-- all small size screens -->
    <screen android:screenSize="small" android:screenDensity="ldpi" />
    <screen android:screenSize="small" android:screenDensity="mdpi" />
    <screen android:screenSize="small" android:screenDensity="hdpi" />
    <screen android:screenSize="small" android:screenDensity="xhdpi" />
    <screen android:screenSize="small" android:screenDensity="480" />
    <screen android:screenSize="small" android:screenDensity="640" />

    <!-- all normal size screens -->
    <screen android:screenSize="normal" android:screenDensity="ldpi" />
    <screen android:screenSize="normal" android:screenDensity="mdpi" />
    <screen android:screenSize="normal" android:screenDensity="hdpi" />
    <screen android:screenSize="normal" android:screenDensity="xhdpi" />
    <screen android:screenSize="normal" android:screenDensity="480" />
    <screen android:screenSize="normal" android:screenDensity="560" />
    <screen android:screenSize="normal" android:screenDensity="640" />
</compatible-screens>

Update 8.8.2016 Add this line if you want to support Nexus-5x-like devices with 420 density

<screen android:screenSize="normal" android:screenDensity="420" />