【发布时间】:2013-06-28 12:23:50
【问题描述】:
我的应用程序被允许使用闪光灯和相机,但它没有打开。该设备是 Nexus 三星。
我尝试设置FlashModeOn,但它不起作用。请帮帮我。
[Activity(Label = "TurnOnLight", MainLauncher = true, Icon = "@drawable/icon")]
public class Activity1 : Activity
{
public void initCamera()
{
var b = FindViewById<Button>(Resource.Id.MyButton);
try
{
if (!hasCamera)
{
mcamera = Camera.Open();
hasCamera = true;
p=mcamera.GetParameters();
var s = p.Get(Camera.Parameters.FlashModeOn);
p.Set(Camera.Parameters.FlashModeTorch,0);
mcamera.SetParameters(p);
mcamera.StartPreview();
}
else
{
}
}
catch (Exception exception)
{
hasCamera = false;
}
}
【问题讨论】:
-
Mojtaba,我对 Android 了解不多,尤其不知道如何使用相机,但根据我在 StackOverflow 上看到的其他答案,您的代码似乎是正确的。我唯一的问题是,当您开始活动并调用
initCamera()时,hasCamera是否实际上是错误的。如果hasCamera为真,那么它永远不会尝试打开闪光灯。你确定它会进入这段代码吗? -
请您发表评论,当然可以