Set FlashMode on Windows Phone 8 c# - c#

I'm making my first camera app. I'm trying to set the flash mode with this line of code:
camera.SetProperty(KnownCameraPhotoProperties.FlashMode, FlashMode.Auto);
but I get this exception:
ArgumentException: Value does not fall within the expected range
I've also tried to check the availability of the Flash but the result doesn't change
var supportedFlashModes = PhotoCaptureDevice.GetSupportedPropertyValues(CameraSensorLocation.Back, KnownCameraPhotoProperties.FlashMode);
if (supportedFlashModes.ToList().Contains((UInt32)FlashMode.Auto))
{
camera.SetProperty(KnownCameraPhotoProperties.FlashMode, FlashMode.Auto);
}
Any ideas?

You have to use
camera.SetProperty(KnownCameraPhotoProperties.FlashMode, FlashState.Auto);
and it will work. See http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj662940(v=vs.105).aspx for more details.

Related

UIAutomation throws AccessViolationException on Windows 11

The issue:
We have an application written in C# that uses UIAutomation to get the current text (either selected or the word behind the carret) in other applications (Word, OpenOffice, Notepad, etc.).
All is working great on Windows 10, even up to 21H2, last update check done today.
But we had several clients informing us that the application is closing abruptly on Windows 11.
After some debugging I've seen some System.AccessViolationException thrown when trying to use the TextPatternRange.GetText() method:
System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
What we've tried so far:
Setting uiaccess=true in manifest and signing the app : as mentionned here https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/350ceab8-436b-4ef1-8512-3fee4b470c0a/problem-with-manifest-and-uiaccess-set-to-true?forum=windowsgeneraldevelopmentissues => no changes (app is in C:\Program Files\
In addition to the above, I did try to set the level to "requireAdministrator" in the manifest, no changes either
As I've seen that it may come from a bug in Windows 11 (https://forum.emclient.com/t/emclient-9-0-1317-0-up-to-9-0-1361-0-password-correction-crashes-the-app/79904), I tried to install the 22H2 Preview release, still no changes.
Reproductible example
In order to be able to isolate the issue (and check it was not something else in our app that was causing the exception) I quickly made the following test (based on : How to get selected text of currently focused window? validated answer)
private void btnRefresh_Click(object sender, RoutedEventArgs e)
{
var p = Process.GetProcessesByName("notepad").FirstOrDefault();
var root = AutomationElement.FromHandle(p.MainWindowHandle);
var documentControl = new
PropertyCondition(AutomationElement.ControlTypeProperty,
ControlType.Document);
var textPatternAvailable = new PropertyCondition(AutomationElement.IsTextPatternAvailableProperty, true);
var findControl = new AndCondition(documentControl, textPatternAvailable);
var targetDocument = root.FindFirst(TreeScope.Descendants, findControl);
var textPattern = targetDocument.GetCurrentPattern(TextPattern.Pattern) as TextPattern;
string text = "";
foreach (var selection in textPattern.GetSelection())
{
text += selection.GetText(255);
Console.WriteLine($"Selection: \"{selection.GetText(255)}\"");
}
lblFocusedProcess.Content = p.ProcessName;
lblSelectedText.Content = text;
}
When pressing a button, this method is called and the results displayed in labels.
The method uses UIAutomation to get the notepad process and extract the selected text.
This works well in Windows 10 with latest update, crashes immediately on Windows 11 with the AccessViolationException.
On Windows 10 it works even without the uiaccess=true setting in the manifest.
Questions/Next steps
Do anyone know/has a clue about what can cause this?
Is Windows 11 way more regarding towards UIAutomation?
On my side I'll probably open an issue by Microsoft.
And one track we might follow is getting an EV and sign the app itself and the installer as it'll also enhance the installation process, removing the big red warnings. But as this is an app distributed for free we had not done it as it was working without it.
I'll also continue testing with the reproductible code and update this question should anything new appear.
I posted the same question on MSDN forums and got this answer:
https://learn.microsoft.com/en-us/answers/questions/915789/uiautomation-throws-accessviolationexception-on-wi.html
Using IUIautomation instead of System.Windows.Automation works on Windows 11.
So I'm marking this as solved but if anyone has another idea or knows what happens you're welcome to comment!

How to enable LightningProviders for GPIO?

I am trying to access the GPIO on my custom SBC using Windows 10 IoT Core. I have discovered that I must use LightningProviders to accomplish this . So I tried to follow this guide to use lightning providers properly.
I used very simple code:
if (LightningProvider.IsLightningEnabled)
{
LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
}
GpioStatus = "Initializing...";
var gpio = GpioController.GetDefault();
if (gpio == null)
{
GpioStatus = "There is no GPIO controller on this device.";
}
else
{
gpio.OpenPin(1).Write(GpioPinValue.High);
GpioStatus = gpio.OpenPin(1).Read().ToString();
}
Where GpioStatus is output text on a UI.
I discovered that if I run the LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider(); line outside of the enabled check, it picks up the GPIO controller and lets me detect how many pins I have and read them (All low). However I can't change the DriveMode or write to the pins without error. The error I get just says to Make sure the LightningProviders are enabled.
This brings me back to the guide I linked at the start. It suggests to enable DMAP drivers using the Device Portal for W10IoT or DMAPUtil.exe. I have tried both. In the Device Portal the area where it should be is just blank. And in the command line trying to use the DMAPUtil.exe only returns that dmaputil.exe is not available on this system.
Therefore I am asking if there is any other way to enable the LightningProviders or if there a way to know if they are incompatible with my board?
Thanks!
UPDATE
Also tried using the devcon.exe commands in the W10IoT Command line.
I am able to locate the Direct memory access controller but when i do devcon.exe enable *PNP0200 it says it is enabled but remains disabled when checked with devcon.exe status *PNP0200
Please confirm if you have added the IOT_DMAP_DRIVER feature in your OEMInput.xml, this feature will add the DMAP driver in the image. If IOT_DMAP_DRIVER is removed from the OEMInput.xml, the Default Driver Controller will be blank in device protal, and dmaputil will be not available on Windows IoT Core. Please see the IoT Core feature list.
Update:
You can download the source of Lighting Provider, and then deploy and debug in your custom image.

Set ring volume programatically on Android phone using Xamarin

The following code works well
AudioManager am = (AudioManager)this.GetSystemService(Context.AudioService);
am.RingerMode = RingerMode.Vibrate;
So after running it the ring volume gets to 0, but I would want to set it to a custom value like for instance "57".
To do this I used the following code:
AudioManager am = (AudioManager)this.GetSystemService(Context.AudioService);
am.SetStreamVolume(Stream.Ring, 57, 0);
After this code runs nothing changed to my ring volume, I expected that it will change to a "57" value.
I am using latest Xamarin libraries on a Android 7.0 version. I need to implement this only for Android.
Is this custom ring volume set a limitation ?
What should this am.SetStreamVolume(Stream.Ring, 57, 0); actually do (if it is not changing the ring volume of the phone).
You could use GetStreamMaxVolume firstly to get the maximum value for a particular stream, then set a proper number smaller than the maximum value.

C# Monotouch/Xamarin.iOS - AVPlayer Set Volume

I'm trying to control the volume of an AVPlayer in my iPhone app.
I seem to receive an "unrecognized selector sent to instance" error when trying to simply get the volume value, or even set it, from the AVPlayer.Volume property -
AVPlayer myAVPlayer = new AVPlayer();
var volume = myAVPlayer.Volume;
Any ideas how to make this work?
That's likely because you're using an older device (or simulator) version of iOS. The Volume property was added in iOS7.
There are other ways to set the volume - but you'll need to tell us more about what you're trying to accomplish.

Keep getting ArgumentOutOfRangeException On Phone not in Emulator

Heey,
I need some help on a Exception i keep hitting with my app,
The Exception fires in this piece of code
Map mapView = new Map()
{
CredentialsProvider = new ApplicationIdCredentialsProvider("OurKey"),
Margin = new Thickness(6.0),
IsEnabled = false,
Center = new GeoCoordinate(Convert.ToDouble(newEvent.EventLat), Convert.ToDouble(newEvent.EventLon)),
ZoomLevel = 15
};
Where i get an ArgumentOutOfRangeException on the Center = new GeoCoordinate piece containing the following info
The value of the parameter must be from -90.0 to 90.0.
Parameter name: Latitude
But the newEvent.EventLat is "51.4430624" so completely Valid to me isnt it?
Now the even weirder part is this happens only when i run it on my Nokia Lumia 800 when i fire it up on the emulator it just works fine.
So i really need help on this one i cant find anything on it on the internet.
But the newEvent.EventLat is "51.4430624" so completely Valid to me isnt it?
Unless your decimal separator on the phone is ,
Regional settings is a typical thing to get wrong between an emulator and the real thing.
Consider
//Convert.ToDouble(newEvent.EventLat)
double.Parse(newEvent.EventLat, CultureInfo.InvariantCulture)

Categories