Android: Disable application for tablet
Asked Answered
P

4

26

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.

Petersen answered 14/8, 2013 at 10:42 Comment(3)
how you have tested it???by uploading it on play store??Asthenopia
Please check this link it might help you : developer.android.com/guide/topics/manifest/…Antisthenes
Akram : Yes i tested it. It is visible for tab. I tested from tab.Petersen
S
18

Include following in your Manifest:

<manifest ... >
<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="xxhdpi" />
    <screen android:screenSize="small" android:screenDensity="xxxhdpi" />
    <!-- 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="xxhdpi" />
    <screen android:screenSize="normal" android:screenDensity="xxxhdpi" />
</compatible-screens>
</manifest>

This will help you.

Sandell answered 4/2, 2014 at 9:53 Comment(5)
Don't forget to add xxhdpi, which was added in API 16Jauregui
@EduardK. but most of the xxhdpi devices belong to Tabs. so why to include that?Glyceride
@Glyceride because there are xxhdpi devices that are not tablets, such as Nexus 5.Jauregui
@Glyceride ...and the display technology is only improving, so it's likely we'll have more and more xxhdpi devices fitted into a medium screen bucket in the future.Jauregui
<!-- all normal size screens --> <screen android:screenSize="small" android:screenDensity="xhdpi" /> <screen android:screenSize="small" android:screenDensity="xxhdpi" /> <screen android:screenSize="small" android:screenDensity="xxxhdpi" /> This Value is repeating. Is this right ? Is it right that we replace the "small" with "Normal" for this 3 option?Erbil
M
38

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" />
Metagalaxy answered 20/7, 2014 at 22:45 Comment(7)
I was missing all kinds of devices, this fixed that! Thanks!Station
Will this work if my app already supports tablet and I don't want the tablets to get an update to a specific version ?Mccaslin
With this configuration, devices like Nexus 5x(~423 ppi) are not included. Tested. You still have to add xxhdpi.Barone
What is mean by <screen android:screenSize="normal" android:screenDensity="480" /> <screen android:screenSize="normal" android:screenDensity="560" /> <screen android:screenSize="normal" android:screenDensity="640" />Guereza
I believe it would be according to the API docs. The screenDensity attribute declares the dpi, and all of these are valid dpi values in the docs.Holyhead
I dont think is correct answer anymore. I could not install app on Samsung Galaxy S9+Manasseh
any new method now?Superficial
S
18

Include following in your Manifest:

<manifest ... >
<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="xxhdpi" />
    <screen android:screenSize="small" android:screenDensity="xxxhdpi" />
    <!-- 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="xxhdpi" />
    <screen android:screenSize="normal" android:screenDensity="xxxhdpi" />
</compatible-screens>
</manifest>

This will help you.

Sandell answered 4/2, 2014 at 9:53 Comment(5)
Don't forget to add xxhdpi, which was added in API 16Jauregui
@EduardK. but most of the xxhdpi devices belong to Tabs. so why to include that?Glyceride
@Glyceride because there are xxhdpi devices that are not tablets, such as Nexus 5.Jauregui
@Glyceride ...and the display technology is only improving, so it's likely we'll have more and more xxhdpi devices fitted into a medium screen bucket in the future.Jauregui
<!-- all normal size screens --> <screen android:screenSize="small" android:screenDensity="xhdpi" /> <screen android:screenSize="small" android:screenDensity="xxhdpi" /> <screen android:screenSize="small" android:screenDensity="xxxhdpi" /> This Value is repeating. Is this right ? Is it right that we replace the "small" with "Normal" for this 3 option?Erbil
N
14

If you want to restrict the app to handsets only use the <compatible-screens> tag in the Manifest. i.e.like this

<manifest ... >
    <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" />
        <!-- 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" />
    </compatible-screens>
    ...
    <application ... >
        ...
    <application>
</manifest>

For more info check Declaring an App is Only for Handsets

You should not use the <supports-screens> tag, if you want to restrict the app from tablets. It is clearly mentioned in the official doc

Caution: If you use the element for the reverse scenario (when your application is not compatible with larger screens) and set the larger screen size attributes to "false", then external services such as Google Play do not apply filtering. Your application will still be available to larger screens, but when it runs, it will not resize to fit the screen. Instead, the system will emulate a handset screen size (about 320dp x 480dp; see Screen Compatibility Mode for more information). If you want to prevent your application from being downloaded on larger screens, use , as discussed in the previous section about Declaring an App is Only for Handsets.

Neoterize answered 14/8, 2013 at 10:52 Comment(0)
T
1

please check if you have made layout for layout-large, layout-xlarge. if they are present your app will run on tablet, please remove that layout folder if present.

Transcontinental answered 14/8, 2013 at 10:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.