3

We are adding Affdex Android SDK to our existing APP to detect the emotion of the user as a way to measure users' satisfaction when they use the APP.

We plan to use CameraDetector for this purpose so that we can monitor the users' emotion continuously: http://developer.affectiva.com/v3/android/analyze-camera/

CameraDetector requires a SurfaceView to work. To my understanding, SurfaceView is associated with Activity. When we transit to another Activity, the SurfaceView will get destroyed and we need to initialise it again. The question is similar to the following: Keeping Android camera open across activities

What is the best practice and recommendation for this kind of use case? Is there any workaround?

Community
  • 1
  • 1
Gary Mok
  • 31
  • 1
  • What is the issue you're running into with having each Activity create it's own SurfaceView (i.e. starting and stopping Affdex detection as part of each Activity's lifecycle). – Andy Dennie May 05 '16 at 13:43
  • Camera takes time to initialize and we may lost some emotion tracking data in between – Gary Mok May 05 '16 at 13:57
  • Maybe create the SurfaceView in the application class at startup and have each Activity add/remove it from its view hierarchy? I'm not sure if the Camera would like that. – Andy Dennie May 05 '16 at 14:46
  • do you want to show the camera preview to the user, or do you want to just process frames coming from the camera without showing anything? – Andy Dennie May 23 '16 at 19:02
  • we do not want to show the camera preview to the user – Gary Mok May 25 '16 at 00:44

2 Answers2

0

you can use an android service which is monitor user's emotion via affdex detector. so you need surface view that android service don't have. you can use overlay layout as a camera preview to use camera and affdex feed.

Payam
  • 36
  • 5
0

You can use a Service to process the preview frames outside the context of any particular Activity, and then feed the preview frames to the Affdex SDK using its FrameDetector class instead of CameraDetector. The main difference between the CameraDetector and the FrameDetector is that the CameraDetector does the work of integrating with the camera directly; while the FrameDetector can be fed frames from any source. By using the FrameDetector, you can control where the preview frames go.

Then, instead of connecting the camera preview output to a SurfaceView (which presents the problem of how to hide it), connect it to a "dummy" SurfaceTexture instead.

See https://github.com/Affectiva/android-sdk-samples/tree/master/ServiceFrameDetectorDemo for an example of this approach.

Andy Dennie
  • 6,012
  • 2
  • 32
  • 51