androidandroid-fragmentsraspberry-pi3android-thingscamera-api

Image Listener unable to pick image from the fragment


Image available listener picks up an image of the fragment and onimageavailble() is invoked continuously as soon as the image is available. An instance of the code is as below:

protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(null);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
           WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    setContentView(R.layout.activity_camera);
    setFragment();
}

The setFragment() code is:

    protected void setFragment() {
        final Fragment fragment =
            CameraConnectionFragment.newInstance(
                new CameraConnectionFragment.ConnectionCallback() {
                  @Override
                  public void onPreviewSizeChosen(final Size size, final int rotation) {
                    CameraActivity.this.onPreviewSizeChosen(size, rotation);

                  }
                },
                this,
                getLayoutId(),
                getDesiredPreviewFrameSize());
        getFragmentManager()
            .beginTransaction()
            .replace(R.id.container, fragment)
            .commit();
   }

The code runs correctly on Android and so I wanted it to implement on Android Things device but I was getting a warning stating 'A TextureView or a subclass can only be used with hardware acceleration enabled' and the onimageavailble() is never called. I made required changes in the code to resolve the warning but still, onimageavailble() is never called.

On debugging the code in raspberry Pi3 for android things, I noticed that camera stream is not being displayed in the fragment because of which image listener is unable to pick one.

please provide me with the solution for this problem


Solution

  • You are using WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED (with AndroidThings 0.3.0)

    Hardware Acceleration for the R Pi was only introduced in AndroidThings 0.5.0

    See the release notes here:

    https://developer.android.com/things/preview/releases.html

    With the update to Android O, OpenGL ES 2.0 is now supported. Platforms with a GPU (such as Raspberry Pi 3) also now support hardware acceleration.

    Please update the version of AndroidThings you are using.