【发布时间】:2015-10-03 10:26:23
【问题描述】:
我正在开发android相机应用程序,我找到了一个代码:
http://examples.javacodegeeks.com/android/core/hardware/camera-hardware/android-camera-example/
但我遇到了两个我无法理解的问题。第一个在这部分:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
myContext = this;
initialize();
}
其实我没看懂什么是initialize(),它的作用是什么?我搜索了它,但我没有找到任何东西!
第二个问题在这部分:
public void onResume() {
super.onResume();
if (!hasCamera(myContext)) {
Toast toast = Toast.makeText(myContext, "Sorry, your phone does not have a camera!", Toast.LENGTH_LONG);
toast.show();
finish();
}
if (mCamera == null) {
//if the front facing camera does not exist
if (findFrontFacingCamera() 1) {
//release the old camera instance
//switch camera, from the front and the back and vice versa
releaseCamera();
chooseCamera();
} else {
Toast toast = Toast.makeText(myContext, "Sorry, your phone has only one camera!", Toast.LENGTH_LONG);
toast.show();
}
}
};
我没看懂这个表达式:if (findFrontFacingCamera() 1). 因为findFrontFacingCamera() 不是boolean 并且1 有问题!
【问题讨论】: