In my android app i m using the camera and starting it programmatically .I run my code on samsung gt-s5360 ,but the view is rotated by 90 degree anti clock wise.my code works fine on HTC wildfire-s.On this device the camera view is showing correctly without rotating the view .But it is not showing the correct view on each device.So how can i write the code that works for all devices(android) .My android jar is 2.2 and API level is 8.Please help me .Here is my code.
public class AndroidCamera extends Activity implements SurfaceHolder.Callback{
int rotate=90;
Camera camera;
SurfaceView surfaceView;
SurfaceHolder surfaceHolder;
boolean previewing = false;
LayoutInflater controlInflater = null;
public static ArrayList<Activity> activities=new ArrayList<Activity>();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
activities.add(this);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
surfaceView = (SurfaceView)findViewById(R.id.camerapreview);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
Intent i=new Intent();
i.setClassName("a.b.c","a.b.c.DialPad");
startActivity(i);
}
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub
//this.camera.setDisplayOrientation(90);
if(previewing){
camera.stopPreview();
previewing = false;
}
if (camera != null){
try {
camera.setPreviewDisplay(surfaceHolder);
camera.startPreview();
//camera.setDisplayOrientation(90);
previewing = true;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
camera = Camera.open();
camera.setDisplayOrientation(rotate);
//Parameters p= camera.getParameters();
//p.setRotation(90);
/*if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
{
p.set("orientation", "portrait");
p.set("rotation",90);
Toast.makeText(getApplicationContext(), "Potrait Mode", Toast.LENGTH_SHORT).show();
}
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
{
p.set("orientation", "landscape");
p.set("rotation", 90);
Toast.makeText(getApplicationContext(), "Landscape Mode", Toast.LENGTH_SHORT).show();
}*/
}
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
camera.stopPreview();
camera.release();
camera = null;
previewing = false;
}