Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How to access the mobile device Camera without using TCameraComponent


This question is answered.


Permlink Replies: 3 - Last Post: Dec 1, 2015 2:24 PM Last Post By: E Spelt
Anupama Annambh...

Posts: 24
Registered: 1/16/15
How to access the mobile device Camera without using TCameraComponent  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 2, 2015 10:52 AM
Just like one can access WiFi state via the WiFi service, is it possible to access the device's camera using a service?
- to take picture
- to record a video etc.
- pick front / back camera

e.g.
#include <Androidapi.JNI.Hardware.HPP>
_di_JObject obj = SharedActivityContext()->getSystemService(TJContext::JavaClass->CAMERA_SERVICE);

C++ Builder XE8 is throwing a compile time error "no member named 'CAMERA_SERVICE' in 'Androidapi::Jni::Graphicscontentviewtext::JContextClass'"

Rad Studio wiki has sample that performs the taks I want but using a CameraComponentForm
URL - http://docwiki.embarcadero.com/CodeExamples/XE8/en/FMX.Mobile.CameraComponent_Sample

Is it the only means to get control over the device's camera?

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: How to access the mobile device Camera without using TCameraComponent
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 2, 2015 11:37 AM   in response to: Anupama Annambh... in response to: Anupama Annambh...
Anupama wrote:

Just like one can access WiFi state via the WiFi service, is it
possible to access the device's camera using a service?

Technically yes, but you will have to set it up manually.

#include <Androidapi.JNI.Hardware.HPP>

The Camera interfaces defined in that unit are for the older Camera API that
was deprecated in Android Lollipop. Use TJCamera::JavaClass->open() to get
a JCamera object to access the camera.

The newer camera API added in Lollipop is exposed via the CameraManager service
that you are looking for, but Embarcadero has not wrapped that newer API
yet. So you will have to access it directly in your own code.

C++ Builder XE8 is throwing a compile time error "no member named
'CAMERA_SERVICE' in 'Androidapi::Jni::Graphicscontentviewtext::JContextClass'"

Because there is no such value defined in the TJContext class, because Embarcadero
does not support that API yet. However, getSystemService() takes a string
as input, so just pass the name of the service you want to access:

_di_JObject obj = SharedActivityContext()->getSystemService(StringToJString(L"camera"));


Embarcadero does not provide a definition for the CameraManager or CameraDevice
interfaces, so you will have to define them manually in your own code, or
use Embarcadero's Java2OP tool to generate the definitions:

http://docwiki.embarcadero.com/RADStudio/XE8/en/Java2OP.exe,_the_Native_Bridge_File_Generator_for_Android

--
Remy Lebeau (TeamB)
Anupama Annambh...

Posts: 24
Registered: 1/16/15
Re: How to access the mobile device Camera without using TCameraComponent  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 3, 2015 4:48 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Great! I did not know this was a work around. That worked perfectly.

Thanks a ton Remy Lebeau
E Spelt

Posts: 24
Registered: 12/26/09
Re: How to access the mobile device Camera without using TCameraComponent  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 1, 2015 2:24 PM   in response to: Anupama Annambh... in response to: Anupama Annambh...
Anupama Annambhatla wrote:
Great! I did not know this was a work around. That worked perfectly.

Thanks a ton Remy Lebeau

Hi can you share a sample app or snippets of how you did it?

Thanks!
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02