Tablet or Phone - Android

后端 未结 30 2709
难免孤独
难免孤独 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:20

    I know this is not directly an answer to your question, but other answers here give a good idea of how to identify screen size. You wrote in your question that you got problems with the tilting and this just happened to me as well.

    If you run the gyroscope (or rotation sensor) on a smartphone the x- and y-axis can be differently defined than on a tablet, according to the default orientation of that device (e.g. Samsung GS2 is default portrait, Samsung GT-7310 is default landscape, new Google Nexus 7 is default portrait, although it is a tablet!).

    Now if you want to use Gyroscope you might end up with a working solution for smartphones, but axis-confusion on some tablets or the other way round.

    If you use one of the solutions from above to only go for screen-size and then apply

    SensorManager.remapCoordinateSystem(inputRotationMatrix, SensorManager.AXIS_X, 
        SensorManager.AXIS_Y, outputRotationMatrix);
    

    to flip the axis if it has a large or xlarge screen-size this might work in 90% of the cases but for example on the Nexus 7 it will cause troubles (because it has default portrait orientation and a large screen-size).

    The simplest way to fix this is provided in the RotationVectorSample that ships with the API demos by setting the sceenOrientation to nosensor in your manifest:

    
    ...
    
    

提交回复
热议问题