在 Camera.PictureCallback 中切换 Activity

发布于 2024-11-03 14:55:29 字数 615 浏览 1 评论 0原文

我有一个 Camera.PictureCallback 函数,当相机在 android 中拍照时会调用该函数,但我想知道如何访问相机所属的 Activity。这是我的代码:

public Camera camera = null;    

Camera.PictureCallback pictureCallbackJpeg = new Camera.PictureCallback()
{ 
    //PictureCallback(Activity a)
    //{
    //    
    //}
    // An attempt at creating a constructor...

    public void onPictureTaken(byte[] data, Camera c)
    {
        camera.startPreview();

        // would like to call activity method
    }
}

// Camera Initilisation

camera.takePicture(null, null, pictureCallbackJpeg);

我想切换活动并在这里调用我的主要活动的方法,但我不知道如何执行此操作。有什么想法吗?

I have a Camera.PictureCallback function that gets called when the camera takes a photo in android, but I am wondering how I can access the Activity that the camera is part of. Here is my code:

public Camera camera = null;    

Camera.PictureCallback pictureCallbackJpeg = new Camera.PictureCallback()
{ 
    //PictureCallback(Activity a)
    //{
    //    
    //}
    // An attempt at creating a constructor...

    public void onPictureTaken(byte[] data, Camera c)
    {
        camera.startPreview();

        // would like to call activity method
    }
}

// Camera Initilisation

camera.takePicture(null, null, pictureCallbackJpeg);

I would like to switch activities and also call a method my main activity here, but I cannot work out how I would do this. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁的新欢旧爱 2024-11-10 14:55:29

您可以采用需要在不同类中调用的方法/功能。将它们放在 AndroidUtils.java 之类的东西中。然后,您可以从 Activity 类 Camera.PictureCallback 调用通用方法。

这样就更干净了&您不必将一个对象传递给另一个对象只是为了调用公共方法。

You could take the methods/functionality that needed to be called in different classes & put them in some thing like AndroidUtils.java. You could then call the common method from the Activity class and the Camera.PictureCallback.

It just is cleaner that way & you don't have to pass an object to another just to call the common method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文