我从 onCreate() 方法运行以下代码。这段代码之外只是回调的许多对象声明和实例化。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
thisAct = this;
display = (TextureView)findViewById(R.id.display);
display.setSurfaceTextureListener(surfaceTextureListener);
db = openOrCreateDatabase("MyDatabase", Context.MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS Photos (ID INTEGER, location TEXT, size INTEGER)");
db.execSQL("CREATE TABLE IF NOT EXISTS Tags (ID INTEGER, tag TEXT)");
camMan = this.getSystemService(CameraManager.class);
new Thread(new Runnable(){
@Override
public void run() {
try {
String cm = camMan.getCameraIdList()[0];
if ( ContextCompat.checkSelfPermission(thisAct, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED ) {
ActivityCompat.requestPermissions((Activity)thisAct, new String[] { Manifest.permission.CAMERA }, CAMERA_REQUEST);
}
camMan.openCamera(cm, CDstateCallback, …Run Code Online (Sandbox Code Playgroud)