private void startCameraSnappingThread() { mCameraThread = new Thread() { @Override public void run() { super.run(); while (isSnapping) { Log.d(LOG_TAG, "Attempting to take picture now."); try { // // http://stackoverflow.com/questions/15623944/how-to-autofocus-android-camera-automatically mCamera.autoFocus( new Camera.AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { if (success) { mCamera.takePicture(null, null, mPicture); } } }); runOnUiThread( new Runnable() { @Override public void run() { mNumberOfSnapsTaken++; mNumSnapET.setText(String.valueOf(mNumberOfSnapsTaken)); } }); } catch (Exception e) { e.printStackTrace(); Log.d(LOG_TAG, e.getMessage()); } try { sleep(mTimeLapseDelay); } catch (Exception e) { e.printStackTrace(); Log.d(LOG_TAG, "Not sleeping very well" + e.getMessage()); } Log.d(LOG_TAG, "NUMBER OF SNAPS: " + mNumberOfSnapsTaken); } } }; mCameraThread.start(); // Once the picture thread is running and if the network exists, start sending the pictures! // and listening for direction responses. if (testConnectivity()) { mSnapDisbatcher.start(); mDirectionListener.start(); } else { Toast.makeText(getApplicationContext(), "No network connection.", Toast.LENGTH_LONG).show(); stopSnapping(); } }