سؤال

How to separate android device as per the screen size. I have a apk which should run from Android version 3, but I want to run that application only on tablet not for normal devices. I am not sure how to do this stuff. I think

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

This code will help to do my need. But is there any other way to restrict the device when install from google play.

هل كانت مفيدة؟

المحلول

Very simple on your splash page or first page check device screen size-

 DisplayMetrics metrics = new DisplayMetrics();
    Display mDisplay = MainActivity.this.getWindowManager()
      .getDefaultDisplay();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    float screenDensity = metrics.density;
    float screenDensityDPI = metrics.densityDpi;
    int width = mDisplay.getWidth();
    int Height = mDisplay.getHeight();

    Log.e("Density:", String.valueOf(screenDensity + "---"
      + screenDensityDPI));

And if it is 1280*720 proceed else so a notification this app work only on Tablets..

Enjoy:)

Reference code-

نصائح أخرى

You are developing native or phonegap application?If it is phonegap app, you can use media queries to restrict the screen sizes.

Yes it is possible You may do like this :

Designing an android tablet-only app

Hope it helps :)

Try using this

DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);

    int widthInPixels = metrics.widthPixels;
    int heightInPixels = metrics.heightPixels;

    if (widthInPixels > 600 || heightInPixels > 600) {
        // This is a tablet dont run
    }

OR

if(tabletSize() > 6)
        Log.d("Testing", "Is Tablet ");
    else
        Log.d("Testing", "Not a Tablet ");

public double tabletSize() {

    double size = 0;
    try {
        // Compute screen size
        DisplayMetrics dm = getApplicationContext().getResources().getDisplayMetrics();
        float screenWidth = dm.widthPixels / dm.xdpi;
        float screenHeight = dm.heightPixels / dm.ydpi;
        size = Math.sqrt(Math.pow(screenWidth, 2) +
        Math.pow(screenHeight, 2));
    } catch (Exception e) {
        Log.e("Testing", "Exception " + e);
    }
    return size;
}

This will give you the size of the device in inch's so you can restrict it to a particular screen size (Normally a table is > 6)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top