Show back button in charm settings with my privacy page in windows store apps - xaml

I have a code which show privacy policy URL in charm settings bar.But what I need is like when user clicks on the privacy policy link it should open another page in charm settings with a back button.How to do the same in the below code
private async void OpenPrivacyPolicy(IUICommand command)
{
Uri uri = new Uri("https://sites.google.com/site/mysite/");
await Windows.System.Launcher.LaunchUriAsync(uri);
}

Finally I figured out the solution,thanks to windows 8.1 Appsetting sample app . First of all add a settingsFlyout XAML page to your project.I added the privacy flyout code in my app's home page like this
protected override void OnNavigatedTo(NavigationEventArgs e)
{
SettingsPane.GetForCurrentView().CommandsRequested += onCommandsRequested;
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
SettingsPane.GetForCurrentView().CommandsRequested -= onCommandsRequested;
}
void onCommandsRequested(SettingsPane settingsPane, SettingsPaneCommandsRequestedEventArgs e)
{
SettingsCommand defaultsCommand = new SettingsCommand("Privacy", "Privacy",
(handler) =>
{
Privacy sf = new Privacy();
sf.Show();
});
e.Request.ApplicationCommands.Add(defaultsCommand);
}
then in my Privacy.xaml page I added the following code
public Privacy()
{
this.InitializeComponent();
this.Loaded += (sender, e) =>
{
Window.Current.CoreWindow.Dispatcher.AcceleratorKeyActivated += SettingsFlyout1_AcceleratorKeyActivated;
};
this.Unloaded += (sender, e) =>
{
Window.Current.CoreWindow.Dispatcher.AcceleratorKeyActivated -= SettingsFlyout1_AcceleratorKeyActivated;
};
}
void SettingsFlyout1_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs args)
{
// Only investigate further when Left is pressed
if (args.EventType == CoreAcceleratorKeyEventType.SystemKeyDown &&
args.VirtualKey == VirtualKey.Left)
{
var coreWindow = Window.Current.CoreWindow;
var downState = CoreVirtualKeyStates.Down;
bool menuKey = (coreWindow.GetKeyState(VirtualKey.Menu) & downState) == downState;
bool controlKey = (coreWindow.GetKeyState(VirtualKey.Control) & downState) == downState;
bool shiftKey = (coreWindow.GetKeyState(VirtualKey.Shift) & downState) == downState;
if (menuKey && !controlKey && !shiftKey)
{
args.Handled = true;
this.Hide();
}
}
}
Thanks for all the help everyone! And this code works!If anyone facing difficulty just hit me ;)

Related

The video recording device is preempted by another immersive application

Am I opening the camera for taking a picture, but the user has the possibility to stop the camera if he no longer wants to capture something, so I have a close button which is intended to close the camera, so that the camera preview should be stopped.
If I open the camera, close, open again, I will get the following exception once the close button is clicked for the second time:
System.Runtime.InteropServices.COMException: 'The video recording device is preempted by another immersive application.
I do not know, how the preview camera should be stopped, more than UWP docs say here: https://learn.microsoft.com/en-us/windows/uwp/audio-video-camera/simple-camera-preview-access
The code for stopping the camera preview:
private async Task CleanupCameraAsync()
{
if (_mediaCapture != null)
{
if (_isPreviewing)
{
await _mediaCapture.StopPreviewAsync();
}
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
CameraPreviewControl.Source = null;
if (_displayRequest != null)
{
_displayRequest.RequestRelease();
}
_mediaCapture.Dispose();
});
}
}
I tried to test your code snippet on my side and it can work well. I didn't get the above exception. I tested on the emulator build 15063 and build 14393. Since your code snippet is not the completed code, so I created a minimal project for testing as follows which can work well on my side. You may test it on your side and compare with your code if something wrong with your project.
XAML
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Padding="30">
<CaptureElement Name="PreviewControl" Stretch="Uniform"/>
<Button x:Name="btnpreview" Click="btnpreview_Click" Content="preview test"></Button>
<Button x:Name="btnstop" Click="btnstop_Click" Content="stop"></Button>
</StackPanel>
Code behind
private DeviceInformation _cameraDevice;
private MediaCapture _mediaCapture;
private InMemoryRandomAccessStream _ras;
private LowLagMediaRecording _recording;
private CameraRotationHelper _rotationHelper;
private readonly DisplayRequest _displayRequest = new DisplayRequest();
private bool _isPreviewing;
public MainPage()
{
this.InitializeComponent();
}
private async void btnstop_Click(object sender, RoutedEventArgs e)
{
if (_mediaCapture != null)
{
if (_isPreviewing)
{
await _mediaCapture.StopPreviewAsync();
_isPreviewing = false;
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
PreviewControl.Source = null;
if (_displayRequest != null)
{
_displayRequest.RequestRelease();
}
_mediaCapture.Dispose();
});
}
}
}
private async void btnpreview_Click(object sender, RoutedEventArgs e)
{
try
{
_mediaCapture = new MediaCapture();
var allVideoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
var desiredDevice = allVideoDevices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back);
_cameraDevice = desiredDevice ?? allVideoDevices.FirstOrDefault();
_rotationHelper = new CameraRotationHelper(_cameraDevice.EnclosureLocation);
_mediaCapture.Failed += MediaCapture_Failed;
var settings = new MediaCaptureInitializationSettings { VideoDeviceId = _cameraDevice.Id };
await _mediaCapture.InitializeAsync(settings);
PreviewControl.Source = _mediaCapture;
_displayRequest.RequestActive();
await _mediaCapture.StartPreviewAsync();
_isPreviewing = true;
}
catch (UnauthorizedAccessException)
{
// This will be thrown if the user denied access to the camera in privacy settings
System.Diagnostics.Debug.WriteLine("The app was denied access to the camera");
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("MediaCapture initialization failed. {0}", ex.Message);
}
}
If you still have issues, please provide a minimal reproduced project and the testing environment information. More details please reference the official sample.

how to make my flashlight not o open instantly when i open the program?

// Get the camera
private void getCamera() {
if (camera == null) {
try {
camera = Camera.open();
params = camera.getParameters();
} catch (RuntimeException e) {
Log.e("Camera Error. Failed to Open. Error: ", e.getMessage());
}
}
}
// Turning On flash
private void turnOnFlash() {
if (!isFlashOn) {
if (camera == null || params == null) {
return;
}
// play sound
playSound();
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(params);
camera.startPreview();
isFlashOn = true;
// changing button/switch image
toggleButtonImage();
}
}
My code that gets involved with flash on is above, any suggestions,how to make the flash not open the moment my app opens but only when i press the button
I would guess you are calling turnFlashOn() in onCreate() and don't have a button ClickListener. But it is possible you could be calling turnFlashOn() in onStart() or onResume().
To have it turn on with a button press you should do something like
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_view);
flashlight_button = (Button) findViewById(R.id.your_button);
flashlight_button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
getCamera();
turnOnFlash();
}
});
}
I built an open source flashlight for Android that you can check out at Flashlight by Joe github.

how to hide systemtray in landscape

How to change in windows phone the systemtray in portrait to show up and on landscape to hide?!
i have something like this now but it dont work:
void Pregled_OrientationChanged(object sender, OrientationChangedEventArgs e)
{
if (e.Orientation == PageOrientation.PortraitUp)
{
SystemTray.IsVisible = true;
}
else
{
SystemTray.IsVisible = false;
}
}
on the xaml page the shell:systemtray.isvisible="true" and it dont work. if i remove the visiblity from systemtray in xaml it is not shown at all.
i fixed it, it was an little bug in my code, i had to use PhoneApplicationPage_BeginLayoutChanged instead of Pregled_OrientationChanged i thought i can set the event handler name like i want... my mistake.
This code made it to work...
private void PhoneApplicationPage_BeginLayoutChanged (object sender, OrientationChangedEventArgs e)
{
if (e.Orientation == PageOrientation.PortraitUp)
{
SystemTray.IsVisible = true;
}
else
{
SystemTray.IsVisible = false;
}
}

Sharing video and photo in metro apps through share charm

i am trying to take a picture and video from within the app and trying to share it through share charm but i am having a problem doing that. After i take the pic ,the share charm says it has trouble sharing the image. This is my code .Can anybody please let me know what i am doing wrong.
namespace Temp
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class Page1 : Page
{
private StorageFile _photo; // Photo file to share
private StorageFile _video; // Video file to share
private async void OnCapturePhoto(object sender, TappedRoutedEventArgs e)
{
var camera = new CameraCaptureUI();
var file = await camera.CaptureFileAsync(CameraCaptureUIMode.Photo);
if (file != null)
{
_photo = file;
DataTransferManager.ShowShareUI();
}
}
private async void OnCaptureVideo(object sender, TappedRoutedEventArgs e)
{
var camera = new CameraCaptureUI();
camera.VideoSettings.Format = CameraCaptureUIVideoFormat.Wmv;
var file = await camera.CaptureFileAsync(CameraCaptureUIMode.Video);
if (file != null)
{
_video = file;
DataTransferManager.ShowShareUI();
}
}
void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
var request = args.Request;
if (_photo != null)
{
request.Data.Properties.Description = "Component photo";
var reference = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(_photo);
request.Data.Properties.Thumbnail = reference;
request.Data.SetBitmap(reference);
_photo = null;
}
else if (_video != null)
{
request.Data.Properties.Description = "Component video";
List<StorageFile> items = new List<StorageFile>();
items.Add(_video);
request.Data.SetStorageItems(items);
_video = null;
}
}
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
DataTransferManager.GetForCurrentView().DataRequested += OnDataRequested;
}
}
In order for your app to share, you must set the Title of the DataPackagePropertySet and at least one of the "SetXXX" methods. If you do not, you'll see the following message when trying to share "There was a problem with the data from ."
So add request.Data.Properties.Title = "Title_of_photo_or_video"; in OnDataRequested event.

How can i set settings propperties in charms bar in XAML, Windows 8?

I'm trying to get the charms bar working in windows 8, but i can't find any thing using google.
What i want is to let users acces settings and privacy policy throuw charms bar.
I all ready have this:
public MainPage()
{
this.InitializeComponent();
SettingsPane.GetForCurrentView().CommandsRequested += MainPage_CommandsRequested;
}
void MainPage_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
{
args.Request.ApplicationCommands.Add(new SettingsCommand("commandid", "Settings", DoOperation));
}
private async void DoOperation(IUICommand command)
{
//Show the Settings or Privacy Policy HERE!
}
I don't know how i can get my settings in place of: //Show the Settings or Privacy Policy HERE!
Any help or rather code samples would be greate.
It's better if you put the code in App.xaml.cs, here's a working example:
protected async override void OnLaunched(LaunchActivatedEventArgs args)
{ /....
SettingsPane.GetForCurrentView().CommandsRequested += OnCommandsRequested;
//before if (!rootFrame.Navigate(typeof...
}
void OnCommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
{
var privacy = new SettingsCommand("privacyPref", "Privacy Plicy",
(uiCommand) => { Windows.System.Launcher.LaunchUriAsync(new Uri("http://YOURURL.COM")); });
args.Request.ApplicationCommands.Add(privacy);
var preferences = new SettingsCommand("preferences", "Preferences", (handler) =>
{
var settings = new SettingsFlyout(); //Callisto extension
settings.Content = new PreferencesUserControl(); //Add New Element->User Control
settings.HeaderBrush = new SolidColorBrush(_background);
settings.Background = new SolidColorBrush(_background);
settings.HeaderText = "Preferences";
settings.IsOpen = true;
});
}
Here is the sample for App Setting.
When you fully understand this you can try to understand this sample
Which is better than above sample. Above sample is easy to understand as compared to this sample
There has been quite a few questions about Settings/About implementations. This is about the easiest I have found
http://blog.jerrynixon.com/2012/08/how-to-create-windows-8-settings-pane.html