Showing posts with label win-universal-app. Show all posts
Showing posts with label win-universal-app. Show all posts

Tuesday, March 14, 2017

Cordova Windows 10 - Exception calling native with command - notification

Leave a Comment

I am having trouble with my Windows 10 cordova application.

I am trying to use the navigator.notification.confirm but it keeps throwing me this error

Exception calling native with command :: Notification :: confirm ::exception=WinRTError: The parameter is incorrect

I am running this command on another page and it is running fine. I don't know why it is working on one page and not another.

This is the code for my index page - WORKS FINE

navigator.notification.confirm(     'This will download new data, do you want to confirm?',     'callback',     'Are you sure?',     ['Refresh', 'Cancel'] ) 

However, the code below doesn't work at all and I don't know why at all

navigator.notification.confirm(     'Please select an option',     ImageCaptureInput.currentInstance.onConfirm2,     'Photo / video',     ['Photo','Cancel','Video']      ); 

I have this working on WP8, Android and iOS and it works fine. Windows 10 throws this unknown error. Having a Google around and a quick look on here didn't help at all.

Any help would be greatly appreciated.

EDIT:

I get these errors in the debug console in Visual Studio. It seems the error is only with the confirm function of the navigator.notification plugin.

0x800a139e - JavaScript runtime error: InvalidAccessError Exception was thrown at line 221, column 13 in ms-appx-web://cordova.platform.windowsUWP/www/plugins/cordova-plugin-dialogs/src/windows/NotificationProxy.js 0x80070057 - JavaScript runtime error: The parameter is incorrect. Exception was thrown at line 240, column 13 in ms-appx-web://cordova.platform.windowsUWP/www/plugins/cordova-plugin-dialogs/src/windows/NotificationProxy.js 

2ND EDIT

The error seems to be occurring when it gets to the showAsync() part of the function, shown below

confirm:function(win, loseX, args) {      if (isAlertShowing) {         var later = function () {             module.exports.confirm(win, loseX, args);         };         alertStack.push(later);         return;     }      isAlertShowing = true;      try {         var message = args[0];         var _title = args[1];         var buttons = args[2];          var md = new Windows.UI.Popups.MessageDialog(message, _title);          buttons.forEach(function(buttonLabel) {             md.commands.append(new Windows.UI.Popups.UICommand(buttonLabel));         });          md.showAsync().then(function(res) {             isAlertShowing = false;             var result = res ? buttons.indexOf(res.label) + 1 : 0;             if (win) {                 win(result);             }             if (alertStack.length) {                 setTimeout(alertStack.shift(), 0);             }          });     } catch (e) {         // set isAlertShowing flag back to false in case of exception         isAlertShowing = false;         if (alertStack.length) {             setTimeout(alertStack.shift(), 0);         }         // rethrow exception         throw e;     } }, 

0 Answers

Read More

Friday, May 6, 2016

Xamarin UWP custom CommandBar

1 comment

I'd like to create a custom CommandBar for the UWP part of my Xamarin project.

I want to make a logo on a background color. The only way to get this, is making a visualbrush or grid, to contain both the background color and the picture.

I've read it can be done like so;

<Window.Resources>     <VisualBrush x:Key="myBrush">         <VisualBrush.Visual>             <Grid>                 <Rectangle Fill="Red" />                 <Image Source="troll.png" />             </Grid>         </VisualBrush.Visual>     </VisualBrush> </Window.Resources> 

I need to add this commandbar during runtime like so:

var _globalAppBar = new CommandBar(); _globalAppBar.Background = [Link  to above layout] 

Questions:

  1. How or where can I add this in my Xamarin UWP project? Add a XAML file?

  2. How can I link during run time to the layout? Or is there a better way to do this?

0 Answers

Read More

Tuesday, May 3, 2016

Windows UWA (IoT) Bluetooth RfcommService

Leave a Comment

I'm trying to establish a communication between two windows 10 devices:

  1. Raspberry PI 2 B + Bluetooth dongle
  2. Surface pro

Server at raspberry pi:

private readonly Guid _rfcommChatServiceUuid = Guid.Parse("34B1CF4D-1069-4AD6-89B6-E161D79BE4D8");  private async void CreateServer()     {         _provider = await RfcommServiceProvider.CreateAsync(RfcommServiceId.FromUuid(_rfcommChatServiceUuid));         _listener = new StreamSocketListener();          _listener.ConnectionReceived += OnConnectionReceived;         await _listener.BindServiceNameAsync(_provider.ServiceId.AsString(),SocketProtectionLevel.BluetoothEncryptionAllowNullAuthentication);          InitializeServiceSdpAttributes(_provider);         _provider.StartAdvertising(_listener);     }      const uint SERVICE_VERSION_ATTRIBUTE_ID = 0x0300;     const byte SERVICE_VERSION_ATTRIBUTE_TYPE = 0x0A;   // UINT32     const uint SERVICE_VERSION = 200;     void InitializeServiceSdpAttributes(RfcommServiceProvider provider)     {         var writer = new DataWriter();         writer.WriteByte(SERVICE_VERSION_ATTRIBUTE_TYPE);         writer.WriteUInt32(SERVICE_VERSION);         var data = writer.DetachBuffer();         provider.SdpRawAttributes.Add(SERVICE_VERSION_ATTRIBUTE_ID, data);     }   async void OnConnectionReceived( StreamSocketListener listener, StreamSocketListenerConnectionReceivedEventArgs args)     {          _provider.StopAdvertising();         _listener.Dispose();         _listener = null;         _socket = args.Socket; 

The client at surface:

   var services = await DeviceInformation.FindAllAsync(               RfcommDeviceService.GetDeviceSelector(RfcommServiceId.FromUuid(_rfcommChatServiceUuid))); 

The services collection is empty.

What is wrong with that?

Thanks

1 Answers

Answers 1

I think it is worth trying to hard code the address in client side. There is a sample C code of RFCOMM connections for both server and client.

The Bluetooth RFCOMM chat sample for Windows(universal) is here.

Read More

Friday, April 22, 2016

How to resolve the dll conflict of installing Microsoft.Xaml.Behaviors.Uwp.Managed?

Leave a Comment

I'm migrating my WinPhone8.1 project to UWP and I found some incompatibility of the behaviors in the xaml. It seems that I need to install Microsoft.Xaml.Behaviors.Uwp.Managed and Microsoft.Xaml.Behaviors.Uwp.Native. However, after installation, I got compilation error like this:An assembly with the same simple name 'Microsoft.Xaml.Interactivity' has already been imported. Try removing one of the references... I think xaml.interactivity is provided by the framework and I cann't see it in the references in solution explorer. I'm wondering if any one can give some idea on this. Here is a screenshot of the references excluding my own dlls. enter image description here

Code snippet

        <interactivity:Interaction.Behaviors>             <core:EventTriggerBehavior                 EventName="ItemClick">                 <core:InvokeCommandAction                     Command="{Binding ViewSomeCommand}"                     InputConverter="{StaticResource ItemClickedToSomeConverter}" />             </core:EventTriggerBehavior>         </interactivity:Interaction.Behaviors> 

2 Answers

Answers 1

Only install Microsoft.Xaml.Behaviors.Uwp.Managed will solve the problem

Answers 2

enter image description here

i tried it and worked with me.

Read More

Wednesday, April 20, 2016

Why would dragging a Xamarin scrollview not work when the mouse does work

Leave a Comment

I have a very simple Xamarin forms app which contains a scrollview, and inside is a stacklayout.

When deployed on Windows, the mouse works correctly to scroll the scrollview with a scrollbar. However, touch/drag does not work at all to scroll the same control. Do I have to do something special to enable touch/drag to scroll? I figured this would just work.

I'm not sure even where to start troubleshooting.

I am targeting Windows 10. Other platforms optional at this point.

The structure of UI classes I have is this:

ContentPage.Content = StackLayout1 StackLayout1.Children = { StackLayout2, Scrollview } StackLayout2 contains an entry field and two buttons ScrollView, which is the problem, contains another StackLayout Inside that I have some labels and some grids 

Following is a simplified repro. Running in the android emulator on my (touch capable) dev machine scrolling with touch works, running in the Windows 8.1 emulator, scrolling only works with a mouse, not with touch.

 public App() {          StackLayout sl = new StackLayout();          for (int i = 1; i < 20; i++) {             sl.Children.Add( new Label { Text = "Label1", FontSize = 50, HeightRequest = 100 } );         }          ScrollView sv = new ScrollView { VerticalOptions = LayoutOptions.FillAndExpand };          sv.Content = sl;          ContentPage cp = new ContentPage();         cp.Content = sv;          MainPage = cp;       } 

Does Xamarin not handle Windows devices with touch, like Surface or other windows tablets? Or?

1 Answers

Answers 1

There is an overriden method from Activity which is: public boolean onTouchEvent(MotionEvent event)

This is the general method that interprets all the touch events from the whole screen.

As you know every View has its own onTouchEvent() method that you could implement in order to add some custom implementation.It appears that these touch events go from the "inside" elements to the "outside" elements. I mean parent-child relations.

So in our case, the ScrollView returns true when the touch events are a horizontal. The activity's touch event will be handled only if the ScrollView touch event is not handled by itself then you are fine. Otherwise you have to override and implement the on touch event of scroll view and in some cases you have to return false so as for the whole layout to implement it.

Read More

Saturday, April 16, 2016

Extent of Windows UWP Ink Additions

Leave a Comment

From highlights of Microsoft Build 2016, I saw Microsoft was pushing its new Ink API. What exactly are the new additions? Can Ink

-Understand handwriting and digitize it?

-Understand Math/Equations and digitize it (ie Latex)?

Are there any other APIs that can do this for UWP or Unity?

How would I go about creating one myself? Jeans link refers to custom recognition. Is this what I'm looking for? I feel like there should be an option to add symbols to the lookup dictionary.

1 Answers

Answers 1

Yes for the first point, you can convert ink strokes to text using handwriting recognition.

Recognize ink strokes

For math and equations, didn't see any default Recognizer at the moment.

Read More

Tuesday, March 29, 2016

Auto focus camera without preview

Leave a Comment

I am running Win10 IoT on a pi 2. I need to be able to take pictures that are focused but cannot get the focus working. The application is a background app so I don't have a way of previewing the camera on a display. Is there any way of doing this? Currently I have

await _mediaCapture.StartPreviewAsync(); _mediaCapture.VideoDeviceController.FocusControl.Configure(new FocusSettings {     Mode = FocusMode.Continuous,     WaitForFocus = true }); await _mediaCapture.VideoDeviceController.FocusControl.FocusAsync(); await _mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream); await _mediaCapture.StopPreviewAsync(); 

but I am getting the error

WinRT information: Preview sink not set

when I try to focus. All of the examples I've seen online show that the preview is output to a control and I assume it wires a sink up automagically. Is there a way to do this manually through code? Possibly without the preview?

1 Answers

Answers 1

I wonder if the code may work even without FocusControl.

I propose you follow Customer Media Sink implementation example and use of StartPreviewToCustomSinkIdAsync method described at http://www.codeproject.com/Tips/772038/Custom-Media-Sink-for-Use-with-Media-Foundation-To

Read More

Friday, March 18, 2016

Windows Cordova App (Universal 10 Phone & 8.1 Phone) Building and Packaging Issue

Leave a Comment

I have an issue with packaging a Cordova Windows app targeting Windows Phone 10 Universal Phone and Windows Phone 8.1.

My app is developed in JS & HTML targeting iOS, Android and Windows with Cordova. When building & packaging on Windows I have the following issues:

  1. I could not create a bundle which would be recognized as supporting multiple languages by the windows store. I had the following resource token in the appxmanifest: <Resource Language="x-generate"> but then it would only detect my default language which I set to de-CH. I then replaced this token with the actual language tokens: <Resource Language="de-CH"><Resource Language="fr-CH">.... When building, VS2015 would complain that there are no resources for the default language and I had the same Issue as before, the app would only be recognized as supporting 1 language. After googling around a bit and taking a look at the Localization Example I added the following to my CordovaApp.Windows.jsproj (WinPhone10) and CordovaApp.Phone.jsproj (WinPhone8.1) File:

    <ItemGroup>   <Content Include="strings\de-CH\resources.json" />   <Content Include="strings\fr-CH\resources.json" />   <Content Include="strings\it-CH\resources.json" />   <Content Include="strings\en-US\resources.json" /> </ItemGroup> 

    and

    <ItemGroup>   <PRIResource Include="strings\de-CH\resources.resjson" />   <Content Include="strings\de-CH\resources.json" />   ...[These two lines repeated for every other language]... </ItemGroup> 

    I of course also created this folder structure (strings\de-CH\..., etc.) in my project. The .json and .resjson files only contain the following content: {} as I do not use the native localization features. This did actually work and the store correctly identified the app as being multilingual. BUT it started building _language-fr.appx, etc. binaries and added them to the bundle. The problem with this is that I only target the arm architecture as one of the plugins I use needs to be built against specific architectures and does not support the neutral target. But strangely the Windows Phone 10 Universal bundle now contains the _language-x.appx files compiled as neutral: Bundle contents on the Windows Store show neutral appx This breaks the display of the Supported processors section on the Windows Store as this now lists neutral, arm or x86, x64, arm depending on which platform you look at it. What can I do to fix this? I need the store to recognize the different languages but without building against neutral.

  2. My second issue is in regard to the Supported operating systems section in the Windows Store. Here I have the issue that it shows:

    Windows Phone 10 Windows Phone 8.1 Windows Phone 8 

    And for a while it also showed Windows Phone 7 which mysteriously disappeared... But I still only target the first two. As you can see from the screenshot above, the store recognized the Windows Phone 8.1 build correctly and I only uploaded the two visible builds. I do not want to target Windows Phone 8. For the Windows Phone 10 appxmanifest I have the following entry:

    <Dependencies>   <TargetDeviceFamily MaxVersionTested="10.0.10586.29" MinVersion="10.0.10586.0" /> </Dependencies> 

    Which was mostly default, I only adjusted the MaxVersionTested and added the Name="Windows.Mobile" (I did not yet build & submit with the Name property set like this), just to be on the safe side. In the Windows Phone 8.1 appxmanifest I've had the following entry:

    <Prerequisites>   <OSMinVersion>6.3.1</OSMinVersion>   <OSMaxVersionTested>6.3.1</OSMaxVersionTested> </Prerequisites> 

    I checked the Version codes for Windows Phone 8.1 and they look very different. These versions look like normal Windows 8.1 version codes. The Windows Phone 8.1 version codes are longer but the properties in the appxmanifest only allow versions with 3 places. Would it help or even work if I changed it to the following:

    <Prerequisites>   <OSMinVersion>8.10.14147</OSMinVersion>   <OSMaxVersionTested>8.10.15148</OSMaxVersionTested> </Prerequisites> 

Just to be clear, the appxmanifests of the project are:

package.phone.appxmanifest for Windows Phone 8.1 package.windows10.appxmanifest for Windows Phone 10 Universal 

It would be great if someone could help me with these two issues. Thanks a lot in advance!

0 Answers

Read More

Saturday, March 12, 2016

How to create an installer for a Windows 10 HWA bundle?

Leave a Comment

I've built a Windows 10 Hosted Web App (HWA) using MS Visual Studio 2015. Now, I've investigated if there is a way to create a standalone installer for it - which bundles the generated .appx and related files into a one-click executable. Sadly, so far, I've only succeded to sideload the HWA bundle by using the provided PowerShell script.

In this context, I've looked at the NSIS (Nullsoft Scriptable Install System) to create an Installer for this HWA. So far there seems to be only "preliminary Windows 10 support" according to the latest changelogs (see section Version F.2 3.0 Beta 2).

So my questions are:

  1. How can I create a standalone installer without the need to invoke PowerShell installation routines?
  2. What does "preliminary Windows 10 support" mean for appxapplications?

Note:

I'm interested in non-Windows-Store based approaches as the app should only be distributed to a group of verified customers by local installation.

EDIT-1:

I'm open to ideas on other (non NSIS-based) installer creation approaches.

1 Answers

Answers 1

NSIS does not support HWA apps out of the box. If you know which Windows APIs to call you could probably use the System plugin or create a custom NSIS plugin. I had a quick look on MSDN but I could not find which API you are supposed to call to sideload apps.

The part about preliminary Windows 10 support has nothing to do with Modern apps. It is mostly about general compatibility and version checking.

Read More