android如何改变系统默认横竖屏方向

在android4.2sdk上,机器默认是横屏,横屏下camera位于机器右上角,安装竖屏APK后,APK旋转180度,需要将camera位置朝下使用。
这一点不符合消费者使用习惯,需要在竖屏APK的情况下,camera位置朝上。 强制改变屏幕启动的方向,我是改的out目录下的build.prop中的ro.sf.hwrotation=90//270,不过这样改,重力感应和camera,开机logo都要翻转方向
由此引出以下开机logo的修改,原生态的logo是ppm格式的,如何修改ppm格式呢,从网上查到的信息是通过代码
具体方法如下
1. pngtopnm logo_linux_clut224.png > logo_linux_clut224.pnm
2. pnmquant 224 logo_linux_clut224.pnm > logo_linux_clut224.pnm
3.pnmtoplainpnm logo_linux_clut224.pnm > logo_linux_clut224.ppm

要删除logo_linux_clut224.clogo_linux_clut224.o 文件,重新编译内核,
注意编译完内核后,也要将上层编译下在打包,不然第一次烧录和recovery时,logo还会出现原来的现象

以下为转载部分
如何改变android默认的横竖屏,修改源码一个地方就可以了。



[java] view plain copy print ?

  1. public int rotationForOrientationLw(int orientation, int lastRotation,
  2. boolean displayEnabled) {
  3. if (mPortraitRotation < 0) {
  4. // Initialize the rotation angles for each orientation once.
  5. Display d = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))
  6. .getDefaultDisplay();
  7. if (d.getWidth() > d.getHeight()) {
  8. mPortraitRotation = Surface.ROTATION_90;
  9. mLandscapeRotation = Surface.ROTATION_0;
  10. mUpsideDownRotation = Surface.ROTATION_270;
  11. mSeascapeRotation = Surface.ROTATION_180;
  12. } else {
  13. mPortraitRotation = Surface.ROTATION_0;
  14. mLandscapeRotation = Surface.ROTATION_90;
  15. mUpsideDownRotation = Surface.ROTATION_180;
  16. mSeascapeRotation = Surface.ROTATION_270;
  17. }
  18. }
  19. {
  20. Log.i(TAG, "MediaPlayer.is not PlayingVideo");
  21. synchronized (mLock) {
  22. switch (orientation) {
  23. case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
  24. //always return portrait if orientation set to portrait
  25. //return mPortraitRotation;
  26. return mUpsideDownRotation;
  27. case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
  28. //always return landscape if orientation set to landscape
  29. return mLandscapeRotation;
  30. case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
  31. //always return portrait if orientation set to portrait
  32. //return mUpsideDownRotation;
  33. return mPortraitRotation;
  34. case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
  35. //always return seascape if orientation set to reverse landscape
  36. return mSeascapeRotation;
  37. case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
  38. //return either landscape rotation based on the sensor
  39. mOrientationListener.setAllow180Rotation(
  40. isLandscapeOrSeascape(Surface.ROTATION_180));
  41. return getCurrentLandscapeRotation(lastRotation);
  42. case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
  43. mOrientationListener.setAllow180Rotation(
  44. !isLandscapeOrSeascape(Surface.ROTATION_180));
  45. return getCurrentPortraitRotation(lastRotation);
  46. }
  47. mOrientationListener.setAllow180Rotation(
  48. orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
  49. || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
  50. // case for nosensor meaning ignore sensor and consider only lid
  51. // or orientation sensor disabled
  52. //or case.unspecified
  53. if (mLidOpen) {
  54. return mLidOpenRotation;
  55. } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR && mCarDockRotation >= 0) {
  56. return mCarDockRotation;
  57. } else if (mDockMode == Intent.EXTRA_DOCK_STATE_DESK && mDeskDockRotation >= 0) {
  58. return mDeskDockRotation;
  59. } else {
  60. if (useSensorForOrientationLp(orientation)) {
  61. return mOrientationListener.getCurrentRotation(lastRotation);
  62. }
  63. return Surface.ROTATION_0;
  64. }
  65. }
  66. }
  67. }
public int rotationForOrientationLw(int orientation, int lastRotation, boolean displayEnabled) {if (mPortraitRotation < 0) { // Initialize the rotation angles for each orientation once. Display d = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay(); if (d.getWidth() > d.getHeight()) { mPortraitRotation = Surface.ROTATION_90; mLandscapeRotation = Surface.ROTATION_0; mUpsideDownRotation = Surface.ROTATION_270; mSeascapeRotation = Surface.ROTATION_180; } else { mPortraitRotation = Surface.ROTATION_0; mLandscapeRotation = Surface.ROTATION_90; mUpsideDownRotation = Surface.ROTATION_180; mSeascapeRotation = Surface.ROTATION_270; } }{ Log.i(TAG, "MediaPlayer.is not PlayingVideo"); synchronized (mLock) { switch (orientation) { case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: //always return portrait if orientation set to portrait //return mPortraitRotation; return mUpsideDownRotation; case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: //always return landscape if orientation set to landscape return mLandscapeRotation; case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: //always return portrait if orientation set to portrait //return mUpsideDownRotation; return mPortraitRotation; case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: //always return seascape if orientation set to reverse landscape return mSeascapeRotation; case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: //return either landscape rotation based on the sensor mOrientationListener.setAllow180Rotation( isLandscapeOrSeascape(Surface.ROTATION_180)); return getCurrentLandscapeRotation(lastRotation); case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: mOrientationListener.setAllow180Rotation( !isLandscapeOrSeascape(Surface.ROTATION_180)); return getCurrentPortraitRotation(lastRotation); }mOrientationListener.setAllow180Rotation( orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); // case for nosensor meaning ignore sensor and consider only lid // or orientation sensor disabled //or case.unspecified if (mLidOpen) { return mLidOpenRotation; } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR && mCarDockRotation >= 0) { return mCarDockRotation; } else if (mDockMode == Intent.EXTRA_DOCK_STATE_DESK && mDeskDockRotation >= 0) { return mDeskDockRotation; } else { if (useSensorForOrientationLp(orientation)) { return mOrientationListener.getCurrentRotation(lastRotation); } return Surface.ROTATION_0; } } } }


修改上面倒数一行代码把return Surface.ROTATION_0改为你要的方向,记得这个要和上面的匹配,宽高不同,Surface.ROTATION_0也不同。因为代码开头就有

[java] view plain copy print ?
  1. if (mPortraitRotation < 0) {
  2. // Initialize the rotation angles for each orientation once.
  3. Display d = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))
  4. .getDefaultDisplay();
  5. if (d.getWidth() > d.getHeight()) {
  6. mPortraitRotation = Surface.ROTATION_90;
  7. mLandscapeRotation = Surface.ROTATION_0;
  8. mUpsideDownRotation = Surface.ROTATION_270;
  9. mSeascapeRotation = Surface.ROTATION_180;
  10. } else {
  11. mPortraitRotation = Surface.ROTATION_0;
  12. mLandscapeRotation = Surface.ROTATION_90;
  13. mUpsideDownRotation = Surface.ROTATION_180;
  14. mSeascapeRotation = Surface.ROTATION_270;
  15. }
  16. }
if (mPortraitRotation < 0) { // Initialize the rotation angles for each orientation once. Display d = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay(); if (d.getWidth() > d.getHeight()) { mPortraitRotation = Surface.ROTATION_90; mLandscapeRotation = Surface.ROTATION_0; mUpsideDownRotation = Surface.ROTATION_270; mSeascapeRotation = Surface.ROTATION_180; } else { mPortraitRotation = Surface.ROTATION_0; mLandscapeRotation = Surface.ROTATION_90; mUpsideDownRotation = Surface.ROTATION_180; mSeascapeRotation = Surface.ROTATION_270; } }






【android如何改变系统默认横竖屏方向】


    推荐阅读