title: How to get camera2 preview frames programmatically(without layout) in Android?
body: <p>I've create a foreground service with the intention of getting frames from camera2 preview without displaying a layout to user. When I create a Textureview in the layout and use it, everything works fine and I can get the frames via calling getBitmap(int width, int height) of TextureView. I've saved the frames and I know it works fine. Here is my code:</p>
  <pre><code>textureView = mainActivity.findViewById(R.id.texture_view);
  surfaceTexture = textureView.getSurfaceTexture();
  surface = new Surface(surfaceTexture);
  </code></pre>
  <p>But I need my code to work without a layout. I've created a TextureView programmatically but when I run it and save the frames, they're blank. This is the code I run to make it work without layout:</p>
  <pre><code>textureView = new TextureView(context);
  textureView.setSurfaceTexture(new SurfaceTexture(100));
  surfaceTexture = textureView.getSurfaceTexture();
  surface = new Surface(surfaceTexture);
  </code></pre>
  <p>FYI, I run my code on a worker thread. I've also tried using Listeners of these objects but no luck. Can anyone point me in the right direction please?</p>