- Home /
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.
This was my first question.
Why did not you answer me?
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?
There appear to be three missing answers on this page.
Answer by imen · Feb 09, 2015 at 11:42 AM
Hello Iranian,
Did you add your "open" method in your Android Activity ??
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.
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.
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" />
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.
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?
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);
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
With WebCamTexture you can just take screenshot, I think that you can't manipulate camera's option with this object.
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.
Your answer
Follow this Question
Related Questions
QR-Code Decoding for iOS and Android 0 Answers
Webcam Texture and Flashlite (Android) 3 Answers
Multiple Plugins on Android 3 Answers
Android Plugin: Load assets from APK, but have low-level access to AssetManager. 0 Answers
Create a ListView in Unity Android app: use UnityGUI or Android plugin? 0 Answers