I am working on a Xamarin Cross Platform App and I have a problem when I try to obtain my gps coords. I have this code to get the gps information:
protected async override void OnAppearing()
{
position = await GetPosition();
map.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(position.Latitude, position.Longitude), Distance.FromMiles(0.3)));
}
async Task<Plugin.Geolocator.Abstractions.Position> GetPosition()
{
var locator = CrossGeolocator.Current;
locator.DesiredAccuracy = 50;
Plugin.Geolocator.Abstractions.Position position = await locator.GetPositionAsync(TimeSpan.FromSeconds(5));
return position;
}
When it reaches the line:
Plugin.Geolocator.Abstractions.Position position = await locator.GetPositionAsync(TimeSpan.FromSeconds(5));
It gives me this exception:
Java.Lang.ClassNotFoundException: Didn't find class
"md57251f317a80041e1a60080af127573bd.GeolocationSingleListener" on
path: DexPathList[[zip file
"/data/app/com.companyname.PruebaMapas-1/base.apk"],nativeLibraryDirectories=[/data/app/com.companyname.PruebaMapas-1/lib/x86,
/system/fake-libs,
/data/app/com.companyname.PruebaMapas-1/base.apk!/lib/x86,
/system/lib, /vendor/lib]]
I don't know why. I add the "Plugin.Geolocator" using NuGet and it is on my PruebaMapas project and on my PruebaMapas.Android project too.
Can anyone help me? Thanks a lot!
Did your application works without using GeoPlugin ? If not it can be similar to this so u can try this solution. This is known issue in Xamarin android 8.1.
Related
I'm trying to implement a simple Dialog with a text input in Android Xamarin, using a DisplayPromptAsync:
private async void ShowDialogAsync() {
string result = await DisplayPromptAsync("Question 1", "What's your name?");
}
Source: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/pop-ups
But I'm getting the next error:
CS0103 The name 'DisplayPromptAsync' does not exist in the current context
And it doesn't give me the option to import any library. My version of Xamarin Forms is 4.6.0.726
It's something I'm missing...?
Thanks in advance...
In the ViewModel, just add the App.Current.MainPage before the call of DisplayPromptAsync:
private async void ShowDialogAsync() {
string result = await App.Current.MainPage.DisplayPromptAsync("Question 1", "What's your name?");
// OK
if (result != null)
{
// do something here
} else {
// do something else here
}
}
Thanks to Jason for his reply...
Update NuGet for Xamarin.Forms
I have updated NuGet for Xamarin.Forms from 4.2.X to 4.3.X in all projects and now it works. Apparently in 4.2.X the method "appears" available with intellisense, but at runtime it fails with the mentioned error. Updating all NuGet packages seemed to solve the problem.
I want to open a PWM pin to my buzzer. But If I try to call the pwmController.OpenPin(6) method, the app crashes with an System.Runtime.InteropServices.SEHException.
I had already double checked the sample sources like the ms-iot-samples. But I cannot see what my problems are.
An idea was that some permissions are missing, but if I try to add for exmaple <iot:Capability Name="lowLevelDevices" />, I cannot longer build the application.
Source
private PwmPin buzzerPin;
private PwmController pwmController;
public RainbowHAT()
{
// ... do something else
InitAsync();
}
private async void InitAsync()
{
Logger.Log(this, "Init");
// Setup PWM controller.
if (LightningProvider.IsLightningEnabled)
{
LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
}
var pwmControllers = await PwmController.GetControllersAsync(LightningPwmProvider.GetPwmProvider());
if (pwmControllers == null || pwmControllers.Count < 2)
{
throw new OperationCanceledException("Operation canceled due missing GPIO controller");
}
pwmController = pwmControllers[1];
pwmController.SetDesiredFrequency(50);
// Setup buzzer
buzzerPin = pwmController.OpenPin(13); <-- CRASH
buzzerPin.SetActiveDutyCyclePercentage(0.05);
buzzerPin.Start();
}
I also tried the following tip to reduce the min required Windows version, but this does not help, too.
PWM Controller needs Lightning support. So you need to set the controller driver as Direct Memory Mapped Driver. Here is a sample about PWM on Raspberry Pi.
You also need to modify the code as following:
private async void InitAsync()
{
Logger.Log(this, "Init");
// Setup PWM controller.
if (LightningProvider.IsLightningEnabled)
{
var pwmControllers = await PwmController.GetControllersAsync(LightningPwmProvider.GetPwmProvider());
if (pwmControllers == null || pwmControllers.Count < 2)
{
throw new OperationCanceledException("Operation canceled due missing GPIO controller");
}
pwmController = pwmControllers[1];
pwmController.SetDesiredFrequency(50);
// Setup buzzer
buzzerPin = pwmController.OpenPin(13);
buzzerPin.SetActiveDutyCyclePercentage(0.05);
buzzerPin.Start();
}
}
Update
I've checked with the different version of unity, it is working with Unity 2018.2.6f1 Personal which is installed on another laptop. But I've Unity 2018.2.12f1 Personal which gives the error. Is it a unity error?
I am using basic free plan of vuforia and working with Cloud recognition with vuforia. Cloud recognition part is working fine and trackable handler print the cloud recognized image name too. But when I trying to enable tracking for the tacked image target, it is only working for the very first image. After the first one, it gives the following error:
TargetSearchResult cloud-image-name could not be enabled for tracking.
UnityEngine.Debug:LogError(Object)
Vuforia.TargetFinder:EnableTracking(TargetSearchResult, GameObject)
CloudRec:OnNewSearchResult(TargetSearchResult) (at
Assets/Scripts/CloudRec.cs:66)
Vuforia.ObjectRecoBehaviour:Update()
Above error indicates the following line as the issue:
m_ObjectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
ImageTargetBehaviour imageTargetBehaviour = (ImageTargetBehaviour)m_ObjectTracker.TargetFinder.EnableTracking(targetSearchResult, ImageTargetTemplate.gameObject);
Tech version:
Vuforia version: 7.5.20 |
Unity 2018.2.12f1 Personal
Full code is here:
public class CloudRec : MonoBehaviour, ICloudRecoEventHandler
{
private CloudRecoBehaviour mCloudRecoBehaviour;
private bool mIsScanning = false;
private string mTargetMetadata = "";
public ImageTargetBehaviour ImageTargetTemplate;
ObjectTracker m_ObjectTracker;
TargetFinder m_TargetFinder;
// Use this for initialization
void Start()
{
// register this event handler at the cloud reco behaviour
mCloudRecoBehaviour = GetComponent<CloudRecoBehaviour>();
if (mCloudRecoBehaviour)
{
mCloudRecoBehaviour.RegisterEventHandler(this);
}
}
public void OnInitialized()
{
m_ObjectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
Debug.Log("Cloud Reco initialized");
}
public void OnInitError(TargetFinder.InitState initError)
{
Debug.Log("Cloud Reco init error " + initError.ToString());
}
public void OnUpdateError(TargetFinder.UpdateState updateError)
{
Debug.Log("Cloud Reco update error " + updateError.ToString());
}
public void OnStateChanged(bool scanning)
{
mIsScanning = scanning;
if (scanning)
{
// clear all known trackables
ObjectTracker tracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
tracker.TargetFinder.ClearTrackables(false);
}
}
// Here we handle a cloud target recognition event
public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult)
{
GameObject newImageTarget = Instantiate(ImageTargetTemplate.gameObject) as GameObject;
GameObject augmentation = null;
if (augmentation != null)
augmentation.transform.SetParent(newImageTarget.transform);
if (ImageTargetTemplate)
{
m_ObjectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
ImageTargetBehaviour imageTargetBehaviour = (ImageTargetBehaviour)m_ObjectTracker.TargetFinder.EnableTracking(targetSearchResult, ImageTargetTemplate.gameObject);
//ImageTracker imageTracker = TrackerManager.Instance.GetTracker<ImageTracker>();
//ImageTargetBehaviour imageTargetBehaviour = (ImageTargetBehaviour)imageTracker.TargetFinder.EnableTracking(targetSearchResult, newImageTarget);
}
if (mIsScanning)
{
mCloudRecoBehaviour.CloudRecoEnabled = true;
}
}
// Update is called once per frame
void Update()
{
}
public void OnInitialized(TargetFinder targetFinder)
{
m_ObjectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
m_TargetFinder = targetFinder;
}
}
After almost a week of the search, I got the error cause. When running with unity the error occurs but when I build to Android or iOS it is working fine. So stopped doubt on the code and it made me think out of the box. So I decided to test on various versions of unity and vuforia with the same machine. It doesn't help to overcome the error. Eventually, I've tested with other machines and I got the error cause. It's because of hardware compatibility.
In my case, I am using mac pro-2009 mid which is not supporting ObjectTracking But I tested with the same code and same versions of tech on MacBook Air 2017 and Mac Pro mid-2014 it is working fine. So I conclude this as a hardware compatibility issue!
I am working in UWP and trying to make the following tutorial example work. In summary i am trying to get a frame from a MediaCapture and display it to an Image UWP Control element.
var previewProperties = _mediaCapture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties;
VideoFrame videoFrame = new VideoFrame(BitmapPixelFormat.Bgra8, (int)previewProperties.Width, (int)previewProperties.Height);
var source = new SoftwareBitmapSource();
var previewFrame = await _mediaCapture.GetPreviewFrameAsync(videoFrame);
SoftwareBitmap previewBitmap = videoFrame.SoftwareBitmap;
await source.SetBitmapAsync(previewBitmap);
img.Source = source;
When the GetPreviewFrameASync function is execute i get a runtime exception reffering Invalid parameter type. Have anyone experiencing the same problem before and what was the cause of it?
Thanks in advance
Turns out there was absolutely no problem with my code,but somehow the CAMERA was to blame for the error. Many others that ran my project had no issues and when I changed my camera everything was fine.If you are unlucky enough to experience the same problem try running it with another cam.
I have tested your segment code and reproduced your issue, the problem is you have not started previewing before GetPreviewFrameASync method executed. The following is the method of starting to preview.
private async Task StartPreviewAsync()
{
try
{
_mediaCapture = new MediaCapture();
await _mediaCapture.InitializeAsync();
_displayRequest.RequestActive();
DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape;
}
catch (UnauthorizedAccessException)
{
}
try
{
PreviewControl.Source = _mediaCapture;
await _mediaCapture.StartPreviewAsync();
_isPreviewing = true;
}
catch (System.IO.FileLoadException)
{
}
}
For more please refer to Basic photo, video, and audio capture with MediaCapture. I have upload code sample to github. Please check!
I'm using ZXing.Net.Mobile and have the following code to scan the QR code.
await scanner.Scan().ContinueWith(t =>
{
if (t.Result != null)
HandleScanResult(t.Result);
});
scanner.UseCustomOverlay = false;
scanner.ScanContinuously(async (res) =>
{
var msg = "Found Barcode: " + res.Text;
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
{
ViewHelper.showMessage(msg, "");
});
});
I've tried both ContinueWith and ScanContinuosly but none of them work.
I get a camera view with red line but it does not scan the QR code.
Where am I going wrong.
I suppose you're using the ZXing.NET package?
Mike Taulty wrote a whole blog post series on an app with Scanning on Windows 8.1, then porting it to Windows 10 and even running it on HoloLens. The final post also has a small companion app that runs on UWP for simple scanning (with speech to command the app to scan).
In that sample, he's using following method:
ZXingQrCodeScanner.ScanFirstCameraForQrCode(
result =>
{
this.txtResult.Text = result?.Text ?? "none";
},
TimeSpan.FromSeconds(30));
There’s an assumption that the first camera found on the system should be used for QR code scanning but the classes that underpin this would allow for taking a more flexible approach and that ScanFirstCameraForQrCode function expands out into the following steps below
public static class ZXingQrCodeScanner
{
public static async void ScanFirstCameraForQrCode(
Action<Result> resultCallback,
TimeSpan timeout)
{
Result result = null;
var mediaFrameSourceFinder = new MediaFrameSourceFinder();
// We want a source of media frame groups which contains a color video
// preview (and we'll take the first one).
var populated = await mediaFrameSourceFinder.PopulateAsync(
MediaFrameSourceFinder.ColorVideoPreviewFilter,
MediaFrameSourceFinder.FirstOrDefault);
if (populated)
{
// We'll take the first video capture device.
var videoCaptureDevice =
await VideoCaptureDeviceFinder.FindFirstOrDefaultAsync();
if (videoCaptureDevice != null)
{
// Make a processor which will pull frames from the camera and run
// ZXing over them to look for QR codes.
var frameProcessor = new QrCaptureFrameProcessor(
mediaFrameSourceFinder,
videoCaptureDevice,
MediaEncodingSubtypes.Bgra8);
// Remember to ask for auto-focus on the video capture device.
frameProcessor.SetVideoDeviceControllerInitialiser(
vd => vd.Focus.TrySetAuto(true));
// Process frames for up to 30 seconds to see if we get any QR codes...
await frameProcessor.ProcessFramesAsync(timeout);
// See what result we got.
result = frameProcessor.QrZxingResult;
}
}
// Call back with whatever result we got.
resultCallback(result);
}
}
Source:
Mike Taulty's blog post
Sample app on GitHub
I hope this approach helps you forward.
You can try my ready solution:
Barcode_Scanner_UWP on GitHub
I'v tried to make adoption of VideoScanZXingWinRT repo
Both of them are using ZXing.Net
But in compare with old Mike Taulty sample could catch QR "on the fly"