Tablet or Phone - Android

后端 未结 30 2525
难免孤独
难免孤独 2020-11-22 08:33

Is there a way to check if the user is using a tablet or a phone? I\'ve got problems with my tilt function and my new tablet (Transformer)

30条回答
  •  执笔经年
    2020-11-22 09:00

    there is no difference. You should define what you think is the difference, and check for that. Is a galaxy tab a phone? or a tablet? and why?

    You should define what specific features you are looking for, and code for that.

    It seems you are looking for 'tilt'. I think this is the same as the accelerometer (is that a word?). You can just check if the device supports it, using:

    public class Accel extends Activity implements SensorListener {
    ...
      SensorManager sensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE);
      boolean accelSupported = sensorMgr.registerListener(this,
            SENSOR_ACCELEROMETER,
            SENSOR_DELAY_UI);
    ...
    }
    

    (from http://stuffthathappens.com/blog/2009/03/15/android-accelerometer/ . i have not tested it)

提交回复
热议问题