Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all 204402 articles
Browse latest View live

Timer Lag in Xamarin.Android App

$
0
0

We were developing a cross-platform app for iOS and Android which uses a timer (so we are using the Device.StartTimer Thread).
While testing our app against the google stopwatch, the iOS version of the app lines up perfectly (in a timespan of 150000 milliseconds), but the Android app falls 10000 milliseconds behind by the end of the 150000 milliseconds.
I have tried disabling the Mono Runtime, but the app still shows this behavior.
I would appreciate any help on this!


DismissViewController causes app to crash blaming 'unknown' orientation

$
0
0

Hi guys,
I spent now at least 8 hours with no success. I am creating a new controller like that:

var newVC = (MyNavigationController)Storyboard.InstantiateViewController("myNavigationController");
NavigationController.PresentViewController(newVC, true, null);

When a user clicks Cancel button on a view controller that is root view controller for MyNavigationController the following is run

NavigationController.PopViewController(true);

And then the application crashes with the following:
Foundation.MonoTouchException: Objective-C exception thrown. Name: UIApplicationInvalidInterfaceOrientation Reason: preferredInterfaceOrientationForPresentation 'unknown' must match a supported interface orientation: 'portrait, landscapeLeft, landscapeRight, portraitUpsideDown'!

What is the reason? What do I do wrong?

Timer lags in Xamarin android

$
0
0

We were developing a cross-platform app for iOS and Android which uses a timer (so we are using the Device.StartTimer Thread).
While testing our app against the google stopwatch, the iOS version of the app lines up perfectly (in a timespan of 150000 milliseconds), but the Android app falls 10000 milliseconds behind by the end of the 150000 milliseconds.
I have tried disabling the Mono Runtime, but the app still shows this behavior.
I would appreciate any help on this!

Timer lags in xamarin android

$
0
0

We were developing a cross-platform app for iOS and Android which uses a timer (so we are using the Device.StartTimer Thread).
While testing our app against the google stopwatch, the iOS version of the app lines up perfectly (in a timespan of 150000 milliseconds), but the Android app falls 10000 milliseconds behind by the end of the 150000 milliseconds.
I have tried disabling the Mono Runtime, but the app still shows this behavior.
I would appreciate any help on this!

Xamarin Forms upload/download files to Google Drive

$
0
0

Hi,

Pardon the ignorance but I am new to XF and am trying to wrap my head around this.

I had asked a previous question on uploading a file to OneDrive through my XF app. I got it to work and will post a solution.

The problem I am now facing is doing the same thing but for GoogleDrive. I have read much on how to do this and it seems very cumbersome. Has anyone successfully done this and if so is there a sample project any where.

After searching the web I did create a Drive API at console.developers.google.com

In my XF app I did this:

private static async Task SignInToGoogleDrive()
{
string[] Scopes = { DriveService.Scope.DriveReadonly, DriveService.Scope.DriveFile };

        GoogleWebAuthorizationBroker.Folder = "Google.Apis.Util.Store.FileDataStore";
        UserCredential credential;

        try
        {
            using (var stream = new FileStream(App.GoogleJsonFilePath, FileMode.Open, FileAccess.Read))
            {
                credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets, 
                    Scopes, "user", 
                    CancellationToken.None
                    );                   
            }

            // Create the service.
            var service = new DriveService(new Google.Apis.Services.BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = "GarageMaster",
            });

            // Define parameters of request.
            FilesResource.ListRequest listRequest = service.Files.List();
            listRequest.PageSize = 10;
            listRequest.Fields = "nextPageToken, files(id, name)";

            // List files.
            IList<Google.Apis.Drive.v3.Data.File> files = listRequest.Execute()
                .Files;
        }
        catch (Exception ex)
        {
            int testStop = 0;
        }

        int testStop1 = 0;
    }

I followed, what I think is correct, from the Google Api examples, and created a json file. I put it in my project and load it as a stream. That is what, in the above code, App.GoogleJsonFilePath is.

Now to be quite honest, I really don't know what this line does:

GoogleWebAuthorizationBroker.Folder = "Google.Apis.Util.Store.FileDataStore";

so I am going about this a bit blindly.

The above does compile, but when it gets to this line,
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(…..

flow goes to the Catch statement and the error is:

ex = {System.NotSupportedException: Failed to launch browser with "https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&response_type=code&client_id=6181........

I really don't know where to go from this point and any help would be appreciated.

Thanks.

Xamarin Forms - Unit testing a method using ServiceLocator

$
0
0

I am trying to unit test a method in my MyViewModel which extends from BaseViewModel. The BaseViewModel has a method like this

protected bool DoSomething()
{
   if (something)
   {
      ServiceLocator.Current.GetInstance ...; //ERROR
      return true;
   }
   else
   {
      return false;
   }
}

DoSomething is called pretty much in every view model. The app works as expected but I am trying to unit test (NUnit) and every method that calls DoSomething is failing in unit tests

The error I get is

error CS0119: 'ServiceLocator' is a type, which is not valid in the given context

Launching an UrhoSharp UWP app from another UWP app

$
0
0

Hello. I'm creating a UWP UrhoSharp app as well as another 2D (non-UrhoSharp) UWP app. I'd like the 2D UWP app to programmatically launch the UrhoSharp UWP app. I found a Microsoft blog discussing how UWP apps can launch and deep-link into each other (search for "Using cross-app communication to make apps work together (10 by 10)") which initially looked like exactly what I need. However, the problem is that in the blog they state that the app that is to be launched by another app needs to modify its "App.xaml.cs" file in order to handle the "OnActivated" event. In all the UrhoSharp tutorials I've been following online they all remove the "App.xaml" and "MainPage.xaml" classes in order to implement a different entry point, so it looks like this is going to be a problem. Can anyone provide some guidance as to how I can launch my UrhoSharp UWP app from my other UWP app?

Visual Studio 2017 fails to create an archive

$
0
0

HI guys,
I'm trying to create a package for my Android application but I received an error:

The selected build configuration is using the shared Mono runtime

but in Release mode this is unchecked. I deleted the .vs folder as a lot of guys suggested.


Prevent webview from loosing focus on iOS

$
0
0

I'm trying to create an editor using Xamarin Forms.
The editor is a webview with content editable and a toolbar below.

The way i'm doing it with the following structure:

Grid with two rows
-->WebView [Row 1]
-->ScrollView with horizontal Scroll [Row 2]
---->Stacklayout (with editor actions)
---------> Pick Photo
---------> Bold
---------> Underline
---------> ...

It works well on Android, when i tap on the buttons, it executes the javascript on the webview,the keyboard remains open and the webview doesn't loose focus.

On iOS the webview looses focus and the keyboard closes.
Like this:

https://drive.google.com/file/d/1gO2AdLUy2VYTVNyhAaypaGGQ2mT6RcJ5/view?usp=sharing

Any idea on how can i solve this ?

Xamarin.Forms Previewer Android is initialize forever

$
0
0

Hi,

As can see by the attached image Previewer on Android mode initialize forever.
No problem with iOS mode.

I am using VS 2017 with latest updates also all nuget packages are up to date.
Xamarin Android Settings is pointing to jdk1.8.0_131 version 64bit.
I have try Clean, Rebuild etc. but nothing get it to work.

Thanks for any advice,
AG

C++ OpenGL Lib in an OpenGLView?

$
0
0

Hi all -

I have a massive portable OpenGL library written in C++ that I currently use in Android Studio and XCode. This C++ library is basically the entire app while we use the Android/iOS dev environments for GUI only - events are passed down into this OpenGL lib to manipulate the app.

I've been poking around looking at cross-platform solutions as maintaining two copies of the GUI is becoming cumbersome - is it possible to render OpenGL elements natively through an OpenGLView in Xamarin.Forms (or any other view)? I'm assuming I'll have to put the actual binding logic into Xamarin.Android and Xamarin.iOS layers but am unable to find any examples of something like this.

I've looked at the mono sample SanAngeles and it looks close, but does anyone know how to do something like this in Xamarin.Forms?

Thanks!

NDK shared library link errors

$
0
0

Attemting to port C++ code to Android using VS2017 Xamarin Shared Library project, I get these link errors - seems like basic C runtime is missing in link step.
1> undefined reference to 'sqrt'
1> undefined reference to 'sqrt'
1> undefined reference to 'ceil'
1> undefined reference to 'ceil'
1> undefined reference to 'sqrt'
1> undefined reference to 'sqrt'
1> undefined reference to 'pow'
1> undefined reference to 'floor'
1> undefined reference to 'cos'
1> undefined reference to 'cos'
1> undefined reference to 'cos'
1> undefined reference to 'cos'
...etc

What is the name of the missing library?

How to get Firebase token after user Login?

$
0
0

Here i am getting firebase id token ,and it works fine-
public async override void OnTokenRefresh()
{
refreshedToken = FirebaseInstanceId.Instance.Token;
SendRegistrationToServer(refreshedToken);
}

but how to generate this token only when user login to the app(after click on login button)?
give me sample code for do this.

ACR User Dialogs not working in Android PCL

$
0
0

I am trying to use ACR User Dialog in my PCL Project. It works like a charm in my iOS project build but when I try to build my Android Project, it gives me the below error:

Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'AndHUD, Version=1.2.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'AndHUD.dll'
at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference)
at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(DirectoryAssemblyResolver resolver, ICollection`1 assemblies, AssemblyDefinition assembly, Boolean topLevel)
at Xamarin.Android.Tasks.ResolveAssemblies.Execute(DirectoryAssemblyResolver resolver) TimPapp.Droid

I already have AndHUD 1.2.0 package installed in NuGet. Any idea what can be the reason? Appreciate any help.

How to change the scrollbar color of a listview

$
0
0

Hi, I want to change the vertical scrollbar color of a list view in xamarin forms. How can i do this.

Please help me...


Can't Access CrossPushNotification

$
0
0

I have installed Xam.Plugin.PushNotification . And my project is shared Project but still unable to access CrossPushNotification, PushNotificationService..
Any suggestion please......

How can I access the contacts in a Xamarin Forms app?

$
0
0

I am currently working in a Xamarin Forms app and I am searching for a plugin or a code snippet that allows me to access the contacts in the phone of the user. I want to be able to scroll navigate in my app threw the contacts and also to give the option to the user to save them in a server. I have searched for plugins that can access the contacts but I have only found plugins that no longer are supported. Any ideas??

Trouble with xamarin android compilation

$
0
0
public class WebviewRendererEX : WebViewRenderer
    {

        Context _context;

        public WebviewRendererEX(Context context) : base(context)
        {
            _context = context;
        }

        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                CookieManager cm = CookieManager.Instance;
                cm.SetAcceptCookie(true);
                cm.SetAcceptThirdPartyCookies(Control, true);
                Control.Settings.JavaScriptEnabled = true;
                Control.Settings.DomStorageEnabled = true;
                Control.AddJavascriptInterface(this, "Android");
                Device.BeginInvokeOnMainThread(() =>
                {
                    Control.EvaluateJavascript("function someNavigate(dict){Android.navigateTo(dict);}", null);
                });    
            }
        }
    }
  public class WebViewJavaScriptInterface : Java.Lang.Object
    {

        private Context context;

        /*
         * Need a reference to the context in order to sent a post message
         */
        public WebViewJavaScriptInterface(Context context)
        {
            this.context = context;
        }

        /* 
         * This method can be called from Android. @JavascriptInterface 
         * required after SDK version 17. 
         */

        [Java.Interop.Export("navigateTo")]
        [JavascriptInterface]
        public void NavigateTo(Dictionary<string, object> dict)
        {

            Console.WriteLine(dict);

        }

    }

I have written the above code in webivew

On build, the compiler is throwing the following error:

Error       Failed to create JavaTypeInfo for class: App.Droid.Controls.WebViewJavaScriptInterface due to System.NullReferenceException: Object reference not set to an instance of an object.
   at Java.Interop.Tools.JavaCallableWrappers.JavaCallableWrapperGenerator.Signature..ctor(String name, String signature, String connector, String managedParameters, String outerType, String superCall)
   at Java.Interop.Tools.JavaCallableWrappers.JavaCallableWrapperGenerator.Signature..ctor(MethodDefinition method, ExportAttribute export)
   at Java.Interop.Tools.JavaCallableWrappers.JavaCallableWrapperGenerator.AddMethod(MethodDefinition registeredMethod, MethodDefinition implementedMethod)
   at Java.Interop.Tools.JavaCallableWrappers.JavaCallableWrapperGenerator..ctor(TypeDefinition type, String outerType, Action`2 log)
   at Java.Interop.Tools.JavaCallableWrappers.JavaCallableWrapperGenerator..ctor(TypeDefinition type, Action`2 log)
   at Xamarin.Android.Tasks.Generator.GenerateJavaSource(TaskLoggingHelper log, TypeDefinition t, String outputPath, String applicationJavaClass, Boolean useSharedRuntime, Boolean generateOnCreateOverrides, Boolean hasExportReference)  MGM.Droid           

Obviously I am doing something wrong, but I'm not really clear on what.. Any thoughts?

Thanks In Advance.

Flexlayout Drag and drop`?

$
0
0

Does flexlayout have drag and drop feature? i have seen on twitter, somebody posted a video for that but i cant find information about it now.
or any view in xamarin forms 3.5 has this ability?

is there a way to call function from appdelgate?

$
0
0

i dont know if this question difficult or not, but i want to call function from appdelgate to xamarin form, can someone help me figure it out?

Viewing all 204402 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>