If your application runs on v2.2 or above you can rotate camera orientation to portrait using camera.setDisplayOrientation(90).
Prior to v2.2 the camera will only display in landscape orientation, so you're forced to set the activity to landscape orientation.
To support devices prior to v2.2 (API level 8) and after, one solution is to default the activity orientation to landscape in AndroidManifest.xml. Then at runtime check the API level and if froyo or above, change the activity orientation to portrait and rotate the camera display.
//in activity onCreate method
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO)
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
//After opening camera - call via reflection
Method rotateMethod = android.hardware.Camera.class.getMethod("setDisplayOrientation", int.class);
rotateMethod.invoke(mCamera, 90);
This is the most straightforward solution and hopefully as new devices come out v2.1 and below will drop off the radar.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…