From a Service, i am launching an Activity, this Activity Take a Picture then Finish,
My Problem :
When Screen is Off & the Service Start this Activity, the Activity does not Take Picture at All, Camera look like Not initialized, This is the Code i am using :
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
////Using those Flags to turn the Screen On & Dismiss the Keyguard & it Turn the Screen On with Success
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
////Tried Sleep Method after Turning the Screen On with no Luck
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Toast.makeText(this, "onCreate", Toast.LENGTH_SHORT).show();
if(camera != null){
camera.release();
camera = null;
}
///Camera Initialization & Take Picture but Nothing Happen if this Activity was Started when Screen was Off...
}
public void onPause(){
super.onPause();
Log.e("TAG", "onPause");
if(camera != null){
camera.release();
camera = null;
}
}
@Override
public void onResume(){
Toast.makeText(this, "On Resume", Toast.LENGTH_SHORT).show();
}
public void onDestroy(){
super.onDestroy();
if(camera != null){ surfaceHolder.removeCallback(this);
camera = null;}
}
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
Toast.makeText(this, "surfaceCreated", Toast.LENGTH_SHORT).show();
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
///Camera Initialization...
}