从一个服务,我正在启动一个活动,这个活动拍照然后完成,
我的问题 :
当屏幕关闭并且服务启动此活动时,活动根本不拍照,相机看起来像未初始化,这是我正在使用的代码:
@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...
}