Image Listener 无法从片段中选取图像

Image Listener unable to pick image from the fragment

Image available 侦听器拾取片段的图像,并在图像可用后立即连续调用 onimageavailble()。代码实例如下:

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();
}

setFragment()代码是:

    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();
   }

代码在 Android 上正确运行,所以我希望它在 Android Things 设备上实现,但我收到一条警告,指出“A TextureView 或子类只能在启用硬件加速的情况下使用 ' 并且永远不会调用 onimageavailble()。我对代码进行了必要的更改以解决警告,但 onimageavailble() 从未被调用。

在为 android 事情调试树莓派 3 中的代码时,我注意到片段中没有显示相机流,因为图像侦听器无法选择一个。

请给我提供这个问题的解决方案

您正在使用 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED(与 AndroidThings 0.3.0

R Pi 的硬件加速仅在 AndroidThings 中引入 0.5.0

在此处查看发行说明:

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.

请更新您正在使用的 AndroidThings 版本。