【发布时间】:2012-10-20 23:04:52
【问题描述】:
我想通过本机检测屏幕旋转。
例如,当触摸事件发生时,我们可以通过 /dev/input/event* 事件设备进行检测
这可能吗?
我的意思是,不使用 java。只需使用本机方法。
WindowManager wm = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
Display disp = wm.getDefaultDisplay();
int rotation = disp.getRotation(); // Android 2.2
Log.i( "Rotation", "rotation : " + rotation );
switch ( rotation )
{
case Surface.ROTATION_0:
Log.i( "Roation", "Portrait : 0" );
break;
case Surface.ROTATION_90:
Log.i( "Roation", "Landscape : 90" );
break;
case Surface.ROTATION_180:
Log.i( "Roation", "Portrait : 180" );
break;
case Surface.ROTATION_270:
Log.i( "Roation", "Landscape : 270" );
break;
}
【问题讨论】:
-
您无法从运行在受保护设备(即尚未植根的消费设备)上的应用程序访问 /dev/input 文件。
标签: android android-ndk