Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all 91519 articles
Browse latest View live

Why do I get an error of type Okhttp instead of http when I am trying to authenticate with Google?

$
0
0

Hi!I am trying to create google authentication and everything seems to work fine,I can see the details of the user when I debug the app but for some reason it just breaks with this error: "Java.IO.IOException: 'unexpected end of stream on com.android.okhttp.Address@e8dfea7b' ".I found a similar post which describes the same problem:https://stackoverflow.com/questions/54308376/how-to-fix-a-java-io-ioexception-unexpected-end-of-stream-on-connection-excep .I did exactly what it was suggested by checking,in the Advanced Properties of the Android app, the HttpClient which was set by default to Android along with SSL/TLS Implementation on Native TLS 1.2+.I checked to see if I have System.Net.Http in my assemblies and it is there but for some reason it still returns an OKHttp error and I don't understand why.I looked over similar issues from users that experienced the same problem and most of them had a problem with the Advanced Properties of the Android application which were easily resolvable or with OKHttp used with Retrofit(this is not my case).Did someone experienced a similar issue and has an efficient way of resolving this error?


Xamarin Forms - Navigation, DI and MVVM

$
0
0

Hi all. I've seen this post by @JamesMontemagno.

Nice one - so you can use the Microsoft Extensions in a consistent fashion across .Net Core apps and Xamarin, including a DI container and other goodies; and it's likely that more and more goodies will be added in future.

So I'd like to use that approach, and it's one less reason to take a dependency on a 3rd party MVVM framework.

However, looking at James' sample code, he's doing Navigation from within Views and not ViewModels, which people say breaks the purist MVVM approach.

Is that really so bad? If it's that bad, why hasn't XF been updated itself to include VM to VM Nav?

Thanks
Howard

Beta vs Live Apps

$
0
0

So if I store settings using xamarin essentials secure storage for in app purchases for example. Will testflight and google prerelease apps storage be separate from production apps? or should I use different keys for storage of beta versions?

Hide/show NavigationBar without moving the ContentPage up/down

$
0
0

Hi everyone!

I am using GestureRecognition (a tap on the screen) to make the NavigationBar appear and disappear.

The problem I found is that when I do this, the whole ContentPage moves down/up as the NavigationBar appears/disappears, but I need it to stay exactly on the same scroll position.

I thought about auto-scrolling up/down the exact height of the NavigationBar, but maybe there is another way?
The problem with this is that I need to get the NavigationBar height, and apparently is not that easy.

I found this post: https://forums.xamarin.com/discussion/comment/415161#Comment_415161
But I don't know how to access the variable.

Am I solving it the right way? If it is the right way, can someone help me to understand how to get the var Height from another class?

Thanks a lot!!

Custom font not working in ios

$
0
0

I am using custom fonts in my app. It works fine in android but in ios behaves weirdly. I have two labels with font size 50 and 32.
One with size 50 works fine but one with size 32 doesn't display correct font.

<Label Text="Welcome" FontSize="50" FontFamily="PunjabiFont"></Label>
<Label Text="Welcome" FontSize="32" FontFamily="PunjabiFont"></Label>

PDFSharp.netstandard - XFont Operation is not supported on this platform.

$
0
0

Hi all,

I want to use PDFSharp.netstandard on Android and iOS to create and save a PDF-file (not viewing), but I get a error which I cannot place.

I have the following example code:

But now I get the following error when I want to create this PDF:

Does someone know how to use this on Android and iOS?

Is that normal UWP very slow?

$
0
0

I never made a UWP app before, now using Xamarin made it.
But after I put it into real phone (Lumia 640XL). I found it's very slow.... My feel is slow as hell.

Open a Window may could use a lot of seconds....For example after login turn to main page:

MainPage main = new MainPage();
main.BindingContext = new MainPageViewModel();

CurrentNavigation.pushAsync(mian);

This will let me wait 5-10 seconds...Really? Ok, maybe there is some logic in ViewModel, like put some data from some static resources and put to the listview or bind some data to page like : {Binding }....But That's really too much than I every thought. even I saw some listview start load the list after page show up and you scroll it you can feel it. Maybe that's for performance inside of Xamarin. But really? I don't have any image.., even there is a Listview(just have some label and coupe of button in each listview item in the listview) after click start to load data. After I click it I'll wait to around 10 second ,and after the page got response, it will start loading the rest of the item. I mean after wait so long to stop freeze the page only load the top 20 items? and continue start load?(you can feel when scroll) ...

Anyway that's too bad...

Is there anyone could give me advice?

BTW: I'm not found any different with DEBUG and Release.... all slow...

How do reload page when click item menu in Xamarin.Form Shell Flyout

$
0
0

I'm using the Xamarin.Form Shell Flyout.

When click item menu, from the second time, the page don't reload.

How do reload page (reload data) when click item menu in Xamarin.Form Shell Flyout?

 <FlyoutItem Route="animals" Title="Animals" FlyoutDisplayOptions="AsMultipleItems">
            <ShellContent Route="Monkeys" Title="Monkeys" Icon="tab_feed.png" ContentTemplate="{DataTemplate local:MonkeysPage}"
 <FlyoutItem/>

Hi I want to convert entire Xamarin form in PDF . Is there any way to do this?

$
0
0

Hi I want to convert entire Xamarin form in PDF . Is there any way to do this without any third party paid library .

I have got a solution using syncfusion but this is not opensource .

Xamarin.Form data security

$
0
0

I am going to develop xamarin form app for both iOS and android. This app should not have login function and I want to keep the app data securely to prevent from reverse engineering. I would like to know how and where to keep the data securely.

I found these 2 approaches.

First approach

  • Consume data from API using Token and save data in sqlite database and then encrypt it. With this approach my first question is where to store the token securely? Should the whole database be encrypted using SQChiper or should only sensitive column be encrypted in term of performance and security? The data size is about more or less 1MB.

Second approach

  • Embedded the encrypted sqlite database in the app and decrypt it in the app. Again, the question is where to store the key securely to perform decryption of the data?

Both are not completely secure. Do you have a better way to implement this scenario.

ScrollToAsync doesn't run when I first start the app

$
0
0

Hi everyone!

So what I am trying to do here is to open the app in the exact same point that I left it last time.
My app consists in just a CarouselPage with several ContentPages, so I need to remember not only the current content page but also the position on the scrollview.

I am already able to open it in the right contentpage, but my issue is that if I close the app, every time I run it again, it doesn't scroll to the right position.
Instead, it opens on the top, and if I, for example, swipe forward to the next contentpage and then backwards (so the OnAppearing() executes again), then it scrolls to the expected position.

Is there any reason why the ScrollToAsync is not executed when the app is opened for the first time?

Thank you very much!

    public partial class I : ContentPage
    {
        public I()
        {
            InitializeComponent();
        }

        protected override void OnAppearing()
        {
            base.OnAppearing();

            //Saves current page
            int CurrentChapter = MainCarouselPage.Capitulos.IndexOf(this);
            Preferences.Set("CurrentChapter", CurrentChapter);

            //Scrolls to las position
            int PosY = Preferences.Get("PositionY", 0);
            scrollView.ScrollToAsync(0, PosY , false);
        }

        private void ScrollView_Scrolled(object sender, ScrolledEventArgs e)
        {
            int PositionY = Convert.ToInt32(this.scrollView.ScrollY);
            Console.WriteLine("Position Y: " + PositionY);
            Preferences.Set("PositionY", PositionY);
        }

MVVM - What is the essential requirement for an application to be regarded as such

$
0
0

When I began looking at Xamarin Forms for the first time, one very basic tutorial specifically provided a case for MVVM - see image below. I know there is a division into Model, ViewModel and Views, which this example follows clearly. Occasionally it seems unclear whether other approaches are technically MVVM, for example when their structure isn't organised exactly in this form. In this case the principle logic is contained within MainPageViewModel.cs, with almost no code at all in MainPage.xaml.cs.

By contrast, could the following project within the Xamarin documentation be regarded as MVVM? It consists of a specific class for database operations (Data sub-folder) and another for defining the data (Models sub-folder), together with a main page which provides the necessary list functionality. It is split in a similar way, but is it MVVM?

Implement custom pin image and details

$
0
0

Going through a tutorial on building a map using Xamarin.Forms.Map. Managed to get my environment setup and working with a map using the below code in Visual Studio

`public partial class MapPage : ContentPage
{
public MapPage()
{
InitializeComponent();

        var ms = MapSpan.FromCenterAndRadius(new Position(123, -123), Distance.FromMiles(1));
        restaurantMap.MoveToRegion(ms);

    var cp = new CustomPin();

        cp.Position = new Position(_lat, _lng);
        cp.Label = rest.Name;
        cp.Address = rest.Address;

        restaurantMap.Pins.Add(cp);
    }
}
public class CustomPin : Pin
{
    public string Image { get; set; }
public string ShopsNearby {get; set;}
}`

So far all works as intended until i need to add more information to the popup when using Xamarin.Forms.Map.

I would now like to add further details for the restaurants when the icon is clicked including an image, so added a CustomPin class above. I cant find any examples of how i could build this in and how to build the appropriate popup to contain the additional information or image. Ive seen some similar threads but either they link to a 404 or the samples just didnt work with what i have above.

Could someone help me get back on track? Thanks

Zxing scanner stops scanning after sometimes. What could be the reason?

$
0
0

I have developed an app with Xamarin.Forms using zxing scanner to scan QR codes. The app uses front camera to scan QR codes and app will be keep open all time. App doesn't go to background. It is very simple and has only 3 pages that is scanning page (HomePage), success page & unsuccess page. After a successful or unsuccessful scan it sets the App's MainPage to scan page. It keeps working for many cycles until about 30 minutes but suddenly stops firing the Handle_On_Scan event. I can't figure out why. What could be happening and is there a way to fix this? Please help me.

public HomePage()
        {
            InitializeComponent();
            BindingContext = viewModel;

            //Scanner.AutoFocus();

            Scanner.Options = new ZXing.Mobile.MobileBarcodeScanningOptions
            {
                DelayBetweenAnalyzingFrames = 200,
                DelayBetweenContinuousScans = 200,
                PossibleFormats = new List<BarcodeFormat>
                {
                    BarcodeFormat.QR_CODE
                },
                TryHarder = true,
                UseFrontCameraIfAvailable = true
            };
        }

How can I the OS to check the crrent user access code

$
0
0

I am looking for a way to force the user to have to re-enter their pin code to check that they are the person using the phone currently


Help with setting info window with custom pins and image

$
0
0

``I have added the below class to my Android Project

public class CustomMapRenderer : MapRenderer, GoogleMap.IInfoWindowAdapter
    {
        //private List<CustomPin> _customPins = new List<CustomPin>();
        public CustomMapRenderer(Context context) : base(context)
        {
        }

        protected override void OnMapReady(GoogleMap map)
        {
            base.OnMapReady(map);

            NativeMap.SetInfoWindowAdapter(this);
        }

        // If you want to customize the pin itself
        protected override MarkerOptions CreateMarker(Pin pin)
        {
            var marker = base.CreateMarker(pin);
            //_customPins.Add(((CustomPin)pin)); // Not sure if i should assign this here

            if (pin is CustomPin customPin)
            {
                marker.SetPosition(new LatLng(pin.Position.Latitude, pin.Position.Longitude));
                marker.SetTitle(pin.Label);
                marker.SetSnippet(pin.Address);

                marker.SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueGreen));
            }

            return marker;
        }

        // To customize the info window
        // Follow the guide
        //private void OnInfoWindowClick(object sender, GoogleMap.InfoWindowClickEventArgs e)
        //{
        //    var customPin = GetCustomPin(e.Marker);
        //    if (customPin == null)
        //    {
        //        throw new Exception("Custom pin not found");
        //    }

        //    if (!string.IsNullOrWhiteSpace(customPin.Url))
        //    {
        //        var url = Android.Net.Uri.Parse(customPin.Url);
        //        var intent = new Intent(Intent.ActionView, url);
        //        intent.AddFlags(ActivityFlags.NewTask);
        //        Android.App.Application.Context.StartActivity(intent);
        //    }
        //}

        public Android.Views.View GetInfoContents(Marker marker)
        {
            var inflater = Android.App.Application.Context.GetSystemService(Context.LayoutInflaterService) as Android.Views.LayoutInflater;
            if (inflater != null)
            {
                Android.Views.View view;

                var customPin = GetCustomPin(marker);
                if (customPin == null)
                {
                    throw new Exception("Custom pin not found");
                }

                if (customPin.Name.Equals("Xamarin"))
                {
                    view = inflater.Inflate(Resource.Layout.XamarinMapInfoWindow, null); // XamarinMapInfoWindow Does NOT exist anywhere, same with other extensions below
                }
                else
                {
                    view = inflater.Inflate(Resource.Layout.MapInfoWindow, null);
                }

                var infoTitle = view.FindViewById<TextView>(Resource.Id.InfoWindowTitle);
                var infoSubtitle = view.FindViewById<TextView>(Resource.Id.InfoWindowSubtitle);

                if (infoTitle != null)
                {
                    infoTitle.Text = marker.Title;
                }
                if (infoSubtitle != null)
                {
                    infoSubtitle.Text = marker.Snippet;
                }

                return view;
            }
            return null;
        }

        public Android.Views.View GetInfoWindow(Marker marker)
        {
            //CustomPin GetCustomPin(Marker annotation)
            //{

            //    var position = new Position(annotation.Position.Latitude, annotation.Position.Longitude);
            //foreach (var pin in _customPins) // customPins does not exist
            //{
            //    if (pin.Position == position)
            //    {
            //        return pin;
            //    }
            //}
            //}
            return null;
        }

    }

Im struggling to get this working and have been reading the documentation but something or another doesnt work or i get another error message. Ive put some comments on my code above where i have some issues. I cant find any namespace that needs to be imported so it makes me think im doing something wrong.

Front end declaration is

    <ContentPage.Content>
        <views:CustomMap x:Name="customMap" MapType="Street"/>
    </ContentPage.Content>

I have a class that attaches to the above Class in my Android project

    public class CustomMap : Map
    {
        public List<CustomPin> CustomPins { get; set; }
    }

public class CustomPin : Pin
{
    public string Name { get; set; }
    public string Url { get; set; }
    public string CustomImage {get; set;}
}

I followed the documentation to set the above but missing certain stuff i assume or the documentation isnt very clear to me.

In short i would like to show the customPin properties along with the Label and Address in a pop up when the user clicks an icon.
The second thing im attempting to achieve is to have a custom icon for the pins and again everything i try either doesnt work or i get a Java error stating to use a bitmap.

Would appreciate if someone could show me an example as all the ones i have seen either dont work or show up as deprecated/obsolete or doesnt exist with the code im using.

Thanks

Why is there not a way to set the icon for a Secondary ToolbarItem

$
0
0

I am trying to use the ToolbarItems to be able to navigate in my app. I am using the Order="Secondary" to have the ellipse icon and a drop menu. I have been using a lighter color for my BarBackgroundColor and the ellipse icon cannot be seen because it it white. How can I change the ellipse icon in a secondary toolbar item to black??? I have been looking everywhere for what should be a fairly accessible option.

Listview auto scroll one item at a time

$
0
0

I have listview which has a story with around 50-60 rows. I want to slowly scroll listview automatically.
So that user can continue to read without manually scrolling.

Android: Unable to resolve host ”covid19.mathdro.id“: No address associated with host

$
0
0

Hi,

I'm using the Xamarin form for building the App and using httpclient (modernhttpclient-updated nuget) for getting the API data from https://covid19.mathdro.id. When test the app ios is working but android throw an exception " Unable to resolve host ”covid19.mathdro.id“: No address associated with host". last time the android has no problem don't know maybe update mono or SDK can cause of this problem?

I'm also try changed back modernhttpclient to AndroidClientHandler, the issue same as above "unable to resolved host ....."

I was used "HTTPS" for accessing this api end point, https://covid19.mathdro.id/api/countries/ID (using postman and browser can be viewed)

Here is my current info: NUGET, Compile version target framework, Android Manifest, Android Build, VS 2019 updated, SDK updated, open jdk updated info, nslookup for checking "covid19.mathdro.id":

=================================
NUGET Xamarin Android and iOS (Shared Project):
Xamarin Forms 4.7.0.968
Xamarin Essential 1.5.3.2

NUGET for core app (.NET standard project):
Framework: .NET Standard Library 2.1.0
modernhttpclient-updated 3.4.3
polly 7.2.1
Newtonsoft.Json 12.0.3

=================================
Compile Android Version (Target Framework): Android 10.0 (Q)

=================================

Android Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.corona.news.kmedia">
  <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="30" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
  <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
  <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
  <uses-permission android:name="android.permission.WAKE_LOCK" />
  <uses-permission android:name="android.permission.GET_ACCOUNTS" />
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <uses-permission android:name="android.permission.CALL_PHONE" />
  <uses-permission android:name="android.permission.GET_TASKS" />
  <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
  <uses-permission android:name="android.permission.USE_BIOMETRIC" />
  <uses-permission android:name="android.permission.USE_FINGERPRINT" />
  <uses-permission android:name="android.permission.CAMERA" />
  <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
  <application android:label="CoronaNews.Droid"> 
                 
    </application>
</manifest>

================================
Android Build:

HttpClient Implementation: AndroidClientHandler (I tried another option: default and managed, no luck)
SSL/TLS Implementation: Native TLS 1.2+

=== Visual Studio Community 2019 for Mac ===

Version 8.6.5 (build 23)
Installation UUID: 2774e73f-ab00-4072-8e8a-240175d71130
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)

Package version: 610000104

=== Mono Framework MDK ===

Runtime:
Mono 6.10.0.104 (2019-12/5d03a6fe116) (64-bit)
Package version: 610000104

=== Roslyn (Language Service) ===

3.6.0-3.20210.9+4eafdcb1bcbd8d3573f2ba6065e56d9b9ce4f8a3

=== NuGet ===

Version: 5.6.0.6591

=== .NET Core SDK ===

SDK: /usr/local/share/dotnet/sdk/3.1.301/Sdks
SDK Versions:
3.1.301
3.1.300
3.1.200
3.1.102
3.1.101
3.1.100
3.0.101
3.0.100
2.1.701
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/6.10.0/lib/mono/msbuild/Current/bin/Sdks

=== .NET Core Runtime ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
3.1.5
3.1.4
3.1.2
3.1.1
3.1.0
3.0.1
3.0.0
2.1.19
2.1.18
2.1.16
2.1.15
2.1.14
2.1.13
2.1.12

=== Xamarin.Profiler ===

Version: 1.6.12.26
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Apple Developer Tools ===

Xcode 11.5 (16139)
Build 11E608c

=== Xamarin.Mac ===

Xamarin.Mac not installed. Can't find /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/Version.

=== Xamarin.iOS ===

Version: 13.18.2.1 (Visual Studio Community)
Hash: 29c4ea731
Branch: d16-6
Build date: 2020-05-26 17:03:05-0400

=== Xamarin Designer ===

Version: 16.6.0.329
Hash: d4f8bcd13
Branch: remotes/origin/d16-6
Build date: 2020-04-24 02:16:02 UTC

=== Xamarin.Android ===

Version: 10.3.1.4 (Visual Studio Community)
Commit: xamarin-android/d16-6/3a10de9
Android SDK: /Users/kok.sang/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
6.0 (API level 23)
7.0 (API level 24)
7.1 (API level 25)
8.0 (API level 26)
8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 30.0.3
SDK Build Tools Version: 30.0.0

Build Information:
Mono: 165f4b0
Java.Interop: xamarin/java.interop/d16-6@2cab35c
ProGuard: xamarin/proguard/master@905836d
SQLite: xamarin/sqlite/3.31.1@49232bc
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-6@bfb66f3

=== Microsoft OpenJDK for Mobile ===

Java SDK: /Users/kok.sang/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android SDK Manager ===

Version: 16.6.0.50
Hash: 5901879
Branch: remotes/origin/d16-6
Build date: 2020-06-10 22:42:50 UTC

=== Android Device Manager ===

Version: 16.6.0.96
Hash: 6e8b80b
Branch: remotes/origin/d16-6
Build date: 2020-06-10 22:43:28 UTC

=== Build Information ===

Release ID: 806050023
Git revision: 5289d413b99fddfc20b4ecf3e445ccb822213427
Build date: 2020-06-18 12:08:30-04
Build branch: release-8.6
Xamarin extensions: 5289d413b99fddfc20b4ecf3e445ccb822213427

=== Operating System ===

Mac OS X 10.15.5
Darwin 19.5.0 Darwin Kernel Version 19.5.0
Tue May 26 20:41:44 PDT 2020
root:xnu-6153.121.2~2/RELEASE_X86_64 x86_64

=== Enabled user installed extensions ===

Android Signature Tool 2.2.0


Java SDK

microsoft_dist_openjdk_8.0.25

java version "1.8.0_221"
Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)


nslookup covid19.mathdro.id

Server: 192.168.8.1
Address: 192.168.8.1#53

Non-authoritative answer:
covid19.mathdro.id canonical name = alias.zeit.co.
Name: alias.zeit.co
Address: 76.76.21.21

Exception on reading css

$
0
0

Hi

I have added style sheet to my Xamarin Forms app. I have;

<Application ...">

<Application.Resources>
    <StyleSheet Source="/Assets/app.css" />
</Application.Resources>

I am getting exception on;

   global::Xamarin.Forms.Xaml.Extensions.LoadFromXaml(this, typeof(App));

in class App, method InitializeComponent.

I have tried various variations of path and moved css files to root etc but no luck. What am I doing wrong? The css seems to be at correct path. Screen below.

Thanks

Regards

Viewing all 91519 articles
Browse latest View live


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