• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by aminzamani6868 · Feb 09, 2015 at 12:19 AM · androidplugindevicewebcamflashlight

Turn your Android device webcam (Camera) , flash light

Hello to all dear friends

I am Iranian. I am weak in English. The question text was translated by Google Translate.

The first question in the forum.

I'm making a game or app for Android with Unity.

At the same time I need to start my webcam device and flash light.

I can tell by the webcam into a texture.


 WebCamDevice[] devices;
 WebCamTexture texture;
  
 devices = WebCamTexture.devices;
  
 if (devices.Length == 2) {
 texture = new WebCamTexture (devices [1].name, 1024, 768, 100000000);
  
 texture.Play ();
  
 this.renderer.material.mainTexture = texture;
 }



You can also create a plug-in to Eclipse,

Turn your Android device with Flash light through it.


 AndroidJavaObject camera;
  
  AndroidJavaClass cameraClass = new AndroidJavaClass("android.hardware.Camera");
  
  int camID = 0;
  camera = cameraClass.CallStatic<AndroidJavaObject>("open", camID);
  
  if (camera != null){
  AndroidJavaObject cameraParameters = camera.Call<AndroidJavaObject>("getParameters");
  cameraParameters.Call("setFlashMode","torch");
  camera.Call("setParameters",cameraParameters);
  }



But now the problem is, I had the great test, I found a code that only allow access to the camera is turned off. If the code is used to take the first turning on the device Nvrflsh,


 camera = cameraClass.CallStatic<AndroidJavaObject>("open", camID);



The second code to turn on your webcam or camera is not running.


 texture.Play ();



And vice versa.

Now, dear friends help me. How do I do (webcam) and (flash light) on my Android device ????

Excuse me for disturbing text !

I am waiting for a response.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image aminzamani6868 · Feb 09, 2015 at 11:26 AM 0
Share

This was my first question.

Why did not you answer me?

avatar image aminzamani6868 · Feb 10, 2015 at 10:56 AM 0
Share

Hello again

I saw the review (Android camera app) to capture interesting.

I like to play in Unity camera or webcam is activated.

I do not want another program I use to take photos.

This way you just described above and Training (Android camera app) to run and open.

But it is not my intention.

I want the camera or webcam is displayed on my game, like my own example and example.

I want the camera flash light while running my webcam.

That is not the way to do this?

avatar image meat5000 ♦ · Feb 10, 2015 at 04:18 PM 1
Share

There appear to be three missing answers on this page.

6 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by imen · Feb 09, 2015 at 11:42 AM

Hello Iranian,

Did you add your "open" method in your Android Activity ??

Comment
Add comment · Show 9 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image aminzamani6868 · Feb 09, 2015 at 12:45 PM 0
Share

Hello my friend

I do not get it !!

I want to light up the flash and camera android open at once, but I do not succeed.

Can someone hold me to introduce the project to do.

I looked at the code and learn project.

avatar image aminzamani6868 · Feb 09, 2015 at 01:22 PM 0
Share

Hello my friend

I do not get it !!

I want to light up the flash and camera android open at once, but I do not succeed.

Can someone hold me to introduce the project to do.

I looked at the code and learn project.

avatar image imen · Feb 09, 2015 at 03:09 PM 1
Share

Hello again, To turn on your camera, you need to do that from your Android project. So Unity will just call the Android method that turn on your camera

In this example we have the method "launch".

Unity Code

 #if UNITY_ANDROID
             AndroidJavaClass androidJavaClass = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
             AndroidJavaObject androidJavaObject = androidJavaClass.GetStatic<AndroidJavaObject> ("currentActivity");
             androidJavaObject.Call ("launch");
             #endif

Generate your Android project from unity and add this method to your UnityPlayerNativeActivity.java

 public void Launch() {
         Intent takePictureIntent = new Intent($$anonymous$$ediaStore.ACTION_I$$anonymous$$AGE_CAPTURE);
         // Ensure that there's a camera activity to handle the intent
         if (takePictureIntent.resolveActivity(getPackage$$anonymous$$anager()) != null) {
             // Create the File where the photo should go
             File photoFile = null;
             try {
                 photoFile = createImageFile();
                 // Continue only if the File was successfully created
                 takePictureIntent.putExtra($$anonymous$$ediaStore.EXTRA_OUTPUT,    Uri.fromFile(photoFile));
                 startActivityForResult(takePictureIntent,TA$$anonymous$$E_PICTURE_REQUEST_CODE);
 
             } catch (IOException ex) {
                 // Error occurred while creating the File
 
             }
 
         }
     }

Finally, don't forget to allow your camera access from your Android$$anonymous$$anifest.xml :

 <uses-permission android:name="android.permission.CA$$anonymous$$ERA" />
 <uses-feature android:name="android.hardware.camera" />
 <uses-feature android:name="android.hardware.camera.autofocus" />





avatar image aminzamani6868 · Feb 09, 2015 at 11:40 PM 0
Share

Thank you, kind friend

In this way you program your Android device like a camera will help to have a picture taken and stored somewhere in the track called Unity.

It is standard procedure that most of the methods used.

I thought I saw the way you've presented it is best to take photos of the facilities is higher.

So I am using the same method you.

Thank you very much my friend.

avatar image aminzamani6868 · Feb 10, 2015 at 10:59 AM 0
Share

Hello again

I saw the review (Android camera app) to capture interesting.

I like to play in Unity camera or webcam is activated.

I do not want another program I use to take photos.

This way you just described above and Training (Android camera app) to run and open.

But it is not my intention.

I want the camera or webcam is displayed on my game, like my own example and example.

I want the camera flash light while running my webcam.

That is not the way to do this?

Show more comments
avatar image
0

Answer by abdulthegamer · Aug 19, 2015 at 12:23 PM

Just paste this line and you phone will start flashing.. C#

CameraDevice.Instance.SetFlashTorchMode(true);

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by aminzamani6868 · Feb 10, 2015 at 06:43 PM

Unfortunately I can not speak French.

I would not use the code below in the Unity.

 WebCamDevice[] devices;
 WebCamTexture texture;
 devices = WebCamTexture.devices;
 if (devices.Length == 2) {
 texture = new WebCamTexture (devices [1].name, 1024, 768, 100000000);
 texture.Play ();
 this.renderer.material.mainTexture = texture;
 }


And the Now I want (camera flash light) torch on

I hope you understand

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image imen · Feb 11, 2015 at 07:55 AM 1
Share

With WebCamTexture you can just take screenshot, I think that you can't manipulate camera's option with this object.

avatar image
0

Answer by Lanre · Mar 17, 2016 at 06:27 PM

Have you checked out NatCam? It supports flash and many other features. And running the camera while flash is on is planned for the upcoming version.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by crispybeans · Mar 21, 2016 at 02:24 PM

There is as well Camera Capture Kit which allows you to use the Native camera functionality in Unity.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

QR-Code Decoding for iOS and Android 0 Answers

Webcam Texture and Flashlite (Android) 3 Answers

Creating Unity Plugin 1 Answer

How can I know if I'm calling a plugin correctly? 0 Answers

Game Thrive (One Signal) causes game to crash when calling init method. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges