I have a winform program, now I need to enhance feature communicate with UWP app, so I added reference Windows.DLL and did some change for winform program, now I can call UWP app thru the method Launcher.LaunchUriAsync(), but any an exception on method Launcher.LaunchUriForResultsAsync(),
Could you provide me some advice? Thanks in advance.
Exception:
The operation identifier is not valid. (Exception from HRESULT: 0x800710DD)
Some Code:
// The protocol handled by the launched app
Uri testAppUri = new Uri("etrace.scanner:");
var supportStatus = await Launcher.QueryUriSupportAsync(testAppUri, LaunchQuerySupportType.Uri, "80a2fbc7-843e-46ca-a740-cbb1bc604d33_y890260wv9vv0");
if (supportStatus != LaunchQuerySupportStatus.Available)
{
// Check the app available or not.
}
var inputData = new ValueSet();
inputData["TestData"] = "Test data";
var optionsE = new LauncherOptions { TargetApplicationPackageFamilyName = "80a2fbc7-843e-46ca-a740-cbb1bc604d33_y890260wv9vv0" };
// Call APP successully.
bool success = await Launcher.LaunchUriAsync(testAppUri, optionsE, inputData);
Debug.WriteLine(success);
// Got an exception:
var result = await Launcher.LaunchUriForResultsAsync(testAppUri, optionsE, inputData);
You can use AppServiceConnections.
https://learn.microsoft.com/en-us/windows/uwp/launch-resume/how-to-create-and-consume-an-app-service
They're for communication with other apps for UWP and they're supported in Win32 and work the same.
Related
I just started working on xamarin not long ago.
Now I met a problem on Xamarin consuming AX2012 Webservice.
I’m in a project that need an android device connect with AX2012 R3 Inbound port.
I made a very simple webservice like below and tested successfully by using C# project.
AX Webservice code
[SysEntryPointAttribute(true)]
public ItemNameAlias GetItemName(ItemId itemId)
{
return InventTable::find(itemId).NameAlias;
}
C# invoke code(successful)
static void Main(string[] args)
{
TestWebservice.TestWebserviceClient client = new TestWebservice.TestWebserviceClient();
TestWebservice.CallContext cpny = new TestWebservice.CallContext() { Company = "USMF" };
client.ClientCredentials.Windows.ClientCredential.UserName = #"sagcn\wangy";
client.ClientCredentials.Windows.ClientCredential.Password = "aoc-111";
string itemName = client.GetItemName(cpny, "C0004");
Console.WriteLine($"Item Name: {itemName}");
Console.ReadKey(false);
}
When I add this service reference to an Xamarin.form project, it was been used very like in C# project.
But when the code invoked the webservice function, it throws a System.NotImplementedException exception.
System.NotImplementedException
Message=The method or operation is not implemented.
Xamarin code (throw NotImplementedException exception)
private void Button_Clicked(object sender, EventArgs e)
{
string itemName = "";
Debug.WriteLine("Start");
ASMXService.TestWebserviceClient client = new ASMXService.TestWebserviceClient();
ASMXService.CallContext cpny = new ASMXService.CallContext() { Company = "USMF" };
client.ClientCredentials.Windows.ClientCredential.UserName = #"sagcn\wangy";
client.ClientCredentials.Windows.ClientCredential.Password = "aoc-111";
// throw exception here
itemName = client.GetItemName(cpny, "C0004");
Debug.WriteLine($"Item Name: {itemName}");
Debug.WriteLine("End");
}
I searched many places but still don’t know the reasons why.
Does anyone have the same experience or can give me some advice?
Thanks a million.
AX Webservice code
C# project add web reference
C# project code success
Xamarin add WCF Webservice
Xamarin add WCF Webservice2
Xamarin invoke webservice
Error exception
when I try to create a hotspot connection in my Xamarin.IOS project I get the following error returned in the description when using NEHotspotConfigurationManager :
Error Domain=NEHotspotConfigurationErrorDomain Code=8 \"internal error.\" UserInfo={NSLocalizedDescription=internal error.}
I have tried to connect to both the network in the office and my phone's wifi hotspot and both return the same message. I have enabled both the options "Accept WiFi Information" and "Hotspot" on both the App ID on the developer portal and also the same in the Entitlements.plist and still the same error. I'm using the code shown below.
public async void JoinNetwork()
{
NEHotspotConfiguration config = new NEHotspotConfiguration("CTIP");
config.JoinOnce = false;
var tcs = new TaskCompletionSource<NSError>();
NEHotspotConfigurationManager.SharedManager.ApplyConfiguration(config, err => tcs.SetResult(err));
var error = await tcs.Task;
if (error != null)
{
PAGE.IOSErrorAlert(error.Description, this);
return;
}
}
Try you code as below
NEHotspotConfiguration config = new NEHotspotConfiguration("CTIP" ,passphrase , false);
config.JoinOnce = true;
var tcs = new TaskCompletionSource<NSError>();
NEHotspotConfigurationManager.SharedManager.ApplyConfiguration(config, err =>
tcs.SetResult(err));
and try to restart your device ,this seems like a known issue on apple side .
Refer to
https://stackoverflow.com/a/47769497/8187800
https://developer.apple.com/forums/thread/107851
I am creating a BLE app where I am successfully connecting to a BLE device. I am able to read the GATT characteristics as well. But when I try to do write operation I get exception
Device xxx disconnected while writing characteristic with yyy
This is my code
private async Task<string> ProcessDeviceInformationService(IService deviceInfoService)
{
try
{
await adapter.ConnectToDeviceAsync(device);
var sb = new StringBuilder("Getting information from Device Information service: \n");
var characteristics = await deviceInfoService.GetCharacteristicsAsync();
var characteristic = await deviceInfoService.GetCharacteristicAsync(Guid.Parse("00002b0f-0000-1000-8000-00805f9b34fb"));
//{
try
{
deviceInfoService.GetCharacteristicAsync(GattCharacteristicIdentifiers.DataExchange);
if (characteristic != null)
{
var sbnew = new StringBuilder("BLE Characteristics\n");
byte[] senddata = Encoding.UTF8.GetBytes(string.IsNullOrEmpty(SendMessageLabel.Text) ? "0x21" : SendMessageLabel.Text);
await Task.Delay(300);
var newbytes = await characteristic.WriteAsync(senddata);
byte[] characteristicsvalue = characteristic.Value;
var str = Encoding.UTF8.GetString(characteristicsvalue);
sbnew.AppendLine($"Characteristics found on this device: {string.Join(", ", str.ToString())}");
CharactericsLabel.Text = sbnew.ToString();
}
}
catch (Exception ex)
{
return ex.Message;
}
return CharactericsLabel.Text;
}
catch (Exception ex)
{
return ex.ToString();
}
}
After some search I found that I need to pass hexadecimal value.Even I tried sending hexadecimal value as you can see in code but it's not working. For android its working fine but for iOS it is still showing this exception.I'm using device Iphone 8 plus and OS version of Iphone is 13.5.1.The write operation works in Light Blue app which I downloaded from App store for iOS. My write type is set to default which is write with response. But it is giving exception in my xamarin app only for the iOS part. I'm using latest stable version 2.1.1 of Plugin.BLE. I have no clue how to fix this any suggestions?
I fixed this exception by getting write without response for characteristic from the peripheral side.
I'm having trouble with a AudioGraph in a UWP app. My trouble is that when I'm adding adding an Outgoing Connection to my input device node I get a Exception thrown with HRESULT: 0x88960001.
Using trial and error I figured out that the problem is with the MediaEncoding profile I set on both the input and output node... but I have now 2 settings only work on one machine and the other only works on another machine... I needed the audio to be Single Channel, 16bit sample with a 16K sample in PCM.
The code I'm using is fairly simple and was based on samples that exist online, the thing is it works only on some microphones and not others... I needed it to be generic and have always the same output so that I can input that to my service endpoint.
I left the 2 AudioEncodingProperties settings there (one of them commented out)
var result = await AudioGraph.CreateAsync(
new AudioGraphSettings(AudioRenderCategory.Media));
if (result.Status == AudioGraphCreationStatus.Success)
{
this.graph = result.Graph;
var microphone = await DeviceInformation.CreateFromIdAsync(
MediaDevice.GetDefaultAudioCaptureId(AudioDeviceRole.Default));
// Low gives us 1 channel, 16-bits per sample, 16K sample rate.
var outProfile = MediaEncodingProfile.CreateWav(AudioEncodingQuality.Low);
//outProfile.Audio = AudioEncodingProperties.CreatePcm(16000, 1, 16);
outProfile.Audio = AudioEncodingProperties.CreatePcm(44100, 2, 32);
var inProfile = MediaEncodingProfile.CreateWav(AudioEncodingQuality.Low);
//inProfile.Audio = AudioEncodingProperties.CreatePcm(16000, 1, 16);
inProfile.Audio = AudioEncodingProperties.CreatePcm(44100, 2, 32);
var outputResult = await this.graph.CreateFileOutputNodeAsync(file,
outProfile);
if (outputResult.Status == AudioFileNodeCreationStatus.Success)
{
this.outputNode = outputResult.FileOutputNode;
var inputResult = await this.graph.CreateDeviceInputNodeAsync(
MediaCategory.Speech,
inProfile.Audio,
microphone);
if (inputResult.Status == AudioDeviceNodeCreationStatus.Success)
{
//EXEPTION IS THROWN HERE
inputResult.DeviceInputNode.AddOutgoingConnection(
this.outputNode);
this.graph.Start();
}
}
}
else
{
throw new Exception("Could not create AudioGraph");
}
Thank you guys for our help
Instead of constructing the inputResult with the inProfile.Audio object, try using the default encoding properties for the graph:
var enc = graph.EncodingProperties;
CreateAudioDeviceInputNodeResult deviceInputNodeResult = await graph.CreateDeviceInputNodeAsync(MediaCategory.Media, enc, this.outputNode);
I had a similar issue and this cleared things up, and allowed the audio to be input from any device without specifying the encoding profile.
I'm developing an UWP app for Desktop and Mobile. I'd like using DeviceConnectionChangeTrigger to identify when my BT device is in range, but when i try using it, I cannot register background task cause it keeps return System.ArgumentException "Value does not fall within the expected range." when executing "Register" method of BackgroundTaskBuilder.
code is very simple
var current = BackgroundExecutionManager.GetAccessStatus();
if (current == BackgroundAccessStatus.Unspecified || current == BackgroundAccessStatus.Denied)
{
var result = await BackgroundExecutionManager.RequestAccessAsync();
if (result == BackgroundAccessStatus.Denied || result == BackgroundAccessStatus.Unspecified)
throw new Exception("You cannot register Access");
}
//I tested it with BT and BTLE device but no luck
//var devices = await DeviceInformation.FindAllAsync(BluetoothLEDevice.GetDeviceSelector());
var devices = await DeviceInformation.FindAllAsync(BluetoothDevice.GetDeviceSelector());
var device = devices.FirstOrDefault();
if (device == null) throw new Exception("Device not found");
var trigger = await DeviceConnectionChangeTrigger.FromIdAsync(device.Id);
//trigger.MaintainConnection = true;
var builder = new BackgroundTaskBuilder
{
Name = "BluetoothConnectionWatcher",
TaskEntryPoint = typeof(BluetoothConnectionWatcherTask).FullName
};
builder.SetTrigger(trigger);
//error on next line!
var r = builder.Register();
My project has Bluetooth capabilities and one background task registered with Bluetooth property flagged.
All Bluetooth functionalities work well and I can communicate with devices without problem.
I tried several BT and BTLE device and for all of them seems I have the same problem.
I tried on Desktop and Mobile version of Windows 10 (both last fast insider build). Same problem.
The device.Id returned by code is similar to "Bluetooth#Bluetooth00:1a:7d:da:71:0a-fc:58:fa:4c:17:0a" for every BT device i tried (of course 2nd MAC address change based on device...)
Any advice?
Thanks in advance
As far as I know, with BLE you should use the Triggers designed for it. Thus if it is characteristics change you would want to get knowledge about, then you should use GattCharacteristicNotificationTrigger, and example on using it can be found from my blog.
Then if it just BLE device availability, and you can detect yours via scanrecord data, then do use the BluetoothLEAdvertisementWatcherTrigger instead. My Friend Juhana has example fro this in his blog.