How to restrict app to Android phones only

前端 未结 4 1936
抹茶落季
抹茶落季 2020-12-01 14:50

Hello I am targeting users to Android phones only. I want to restrict the app to install on Android phones ony not on phablets and tablets.

<
相关标签:
4条回答
  • 2020-12-01 14:59

    Quoting the documentation:

    Because the system generally scales applications to fit larger screens well, you shouldn't need to filter your application from larger screens. As long as you follow the Best Practices for Screen Independence, your application should work well on larger screens such as tablets. However, you might discover that your application can't scale up well or perhaps you've decided to publish two versions of your application for different screen configurations. In such a case, you can use the <compatible-screens> element to manage the distribution of your application based on combinations of screen size and density. External services such as Google Play use this information to apply filtering to your application, so that only devices that have a screen configuration with which you declare compatibility can download your application.

    Bear in mind that <compatible-screens> requires you to whitelist every screen size and density that you are supporting (and we get a new density every year or so), and you are limited to the classic screen size buckets (small, normal, large, xlarge). The documentation's sample is missing some densities:

    <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>
    

    You will need to add additional elements if are willing to support tvdpi, xxhdpi, and xxxhdpi devices.

    Quoting the documentation for <compatible-screens>:

    Caution: Normally, you should not use this manifest element. Using this element can dramatically reduce the potential user base for your application, by not allowing users to install your application if they have a device with a screen configuration that you have not listed. You should use it only as a last resort, when the application absolutely does not work with specific screen configurations. Instead of using this element, you should follow the guide to Supporting Multiple Screens to provide scalable support for multiple screens using alternative layouts and bitmaps for different screen sizes and densities.

    And bear in mind that marketing terms like "phablet" is ill-defined, and so your app may wind up shipping on some devices that you happen to think is a phablet or that somebody else thinks is a phablet.

    0 讨论(0)
  • 2020-12-01 15:05

    It really depends on what your are thinking about phone/phablets.

    There is an official guide that will explain a lot better than me, but essentially, you could do the following to restrict your app to handset devices only.

    AndroidManifest.xml

    <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>
    
    0 讨论(0)
  • 2020-12-01 15:09

    An alternative is to test of the feature android.hardware.telephony

    <uses-feature android:name="android.hardware.telephony" android:required="true" />
    

    This would limit the app to phones.. of course phablets would be included in that, but it would be (IMHO) a better solution than the ever changing screen resolution approach..

    0 讨论(0)
  • 2020-12-01 15:11

    Because of the high densities of new devices such as Nexus 5X, Nexus 6P and the Samsung Galaxy S6 we had to adapt the manifest as following:

    <compatible-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="420" />
        <screen android:screenSize="small" android:screenDensity="480" />
        <screen android:screenSize="small" android:screenDensity="560" />
        <screen android:screenSize="small" android:screenDensity="640" />
        <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="420" />
        <screen android:screenSize="normal" android:screenDensity="480" />
        <screen android:screenSize="normal" android:screenDensity="560" />
        <screen android:screenSize="normal" android:screenDensity="640" />
        <screen android:screenSize="large" android:screenDensity="ldpi" />
        <screen android:screenSize="large" android:screenDensity="mdpi" />
        <screen android:screenSize="large" android:screenDensity="hdpi" />
        <screen android:screenSize="large" android:screenDensity="xhdpi" />
        <screen android:screenSize="large" android:screenDensity="420" />
        <screen android:screenSize="large" android:screenDensity="480" />
        <screen android:screenSize="large" android:screenDensity="560" />
        <screen android:screenSize="large" android:screenDensity="640" />
    </compatible-screens>
    
    0 讨论(0)
提交回复
热议问题