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

Xamarin.Forms.Maps repeated authentication error

$
0
0

Hi all,
I am having some trouble integrating google maps with the Xamarin maps SDK, I have already contacted google on the matter but they said they can only help if it is part of the google maps SDK itself. The reason why I am using Xamarin.Maps over the google play service maps are because I am building this application to work cross-platform and I doubt that the google play services maps will work on both iOS and Android (Not building for Windows Phones).

The problem I am having is that I am getting the same authentication error every single time causing the maps to not display any of the data itself. I followed the guide on Xamarin.Forms Map Initialization but still have nothing.
I have checked the API key many times and even created new ones just encase I did the setup wrong on the google console end. As well as this I have also checked all my authentication information to the same degree, I am certain the data I have entered isn't wrong. Can anyone provide any insight to if I have entered the data in the wrong manner or if there is simply something deeper going on here!
~Thanks - Alex

Right now I am debugging on android so I just want to get it working there first

The Error (API key removed):
11-07 16:18:31.173 E/Google Maps Android API( 6862): Authorization failure. Please see developers.google/maps/documentation/android-api/start for how to correctly set up the map.
11-07 16:18:31.176 E/Google Maps Android API( 6862): In the Google Developer Console (console.developers.google)
11-07 16:18:31.176 E/Google Maps Android API( 6862): Ensure that the "Google Maps Android API v2" is enabled.
11-07 16:18:31.176 E/Google Maps Android API( 6862): Ensure that the following Android Key exists:
11-07 16:18:31.176 E/Google Maps Android API( 6862): API Key: AIzaSyBpwq(The full API key is here just censored for the forums)
11-07 16:18:31.176 E/Google Maps Android API( 6862): Android Application (;): 42:DF:8F:89:DE:8A:48:25:34:(Full cert is here but censored for forms);com.IFDS.carapp


Xamarin form (Android) App runs on debug but crashes on release mode

$
0
0

My Xamarin application works perfectly on debug mode but crashes on release mod.
Microsoft Visual Studio Community 2019 Version 16.4.5
Xamarin.Forms 4.4.0.991640
i did not get any error in debug mode
Could any one help me to know what is the problem i tried every thing on google
you can try the app from the link
github.com/dannykhreet/Math-Yos

I tried the app on android (10, 9 ) did not working in release mode

Navigation using Xamarin Forms and MVVM

$
0
0

I am new to Xamarin development and I am trying to implement the MVVM design pattern. When a button is clicked, I am running a command to login. If login is successful, I want to show the next page. However, I'm not sure how to do this without violating the MVVM pattern.

I have searched and seen lots of posts related, and many people just recommend passing in the INavigation to the ViewModel and do the PushAsync call from there. This seems like it violates the pattern to me since the ViewModel shouldn't know anything about the view layer.

Surprisingly, I haven't found any official docs yet that describe the best practice for this. Can anyone suggest the best way to navigate using ViewModels and MVVM?

Ideas on Architecting an Application

$
0
0

I'm looking at a Xamarin Forms app which will have a start form, and end form and the middle is a series of detail forms based upon a list which can be 1 to x records long. So the start form would kick off displaying the detail form and when you can move back and forward through the details until you come to the last detail which would then move to the end form.

I'm thinking of using the NavigationPage and in the details Pushing and Poping the details and passing the current detail to the detail form to allow it to be displayed.

However I'm not sure if this is the best approach to be using. Anyone have any better ideas on how I should architect this simple pattern.

How to Implement Social Logins

$
0
0

l am trying to implement social login with xamarin.auth on my mobile app.l have a web api backend supporting both a mobile and web app. my challenge right now is getting the keystore signature for xamarin.andriod. the process is stated in this document

https://docs.microsoft.com/en-us/xamarin/android/deploy-test/signing/keystore-signature?tabs=macos

but when l run

$ keytool -list -v -keystore ~/.local/share/Xamarin/Mono\ for\ Android/debug.keystore -alias androiddebugkey -storepass android -keypass android

it gives me command not found response.

l cant seem to be able to add keytool to the path variable. Can anyone direct me on how to add keytool to PATH variable.
l am using catalina os.

modal return

$
0
0

Hi,
I need to receive a value from modal Page. I win open modal Page but dont win retur one value wuen I pop this. How to do this? Thanks

Trying to make my own graphical DisplayAlert

$
0
0

Hello everyone, I am trying to make a customizable popup replacement for DisplayAlert. I asked this over in the syncfusion community forum, but thought someone here may have done something like this as well...
Here is my post form their forum.

I have a condition in my app where I want the user to make a selection of two options, and then continue the code path based on their selection

pseud code like this

public async void GetImage()
{
InitializePermissions();

 if ( await SfPopupTool.Show("<title>", "<Message>", "<LocalFileOption>", "<CameraOption>").ConfigureAwait(true)  == false)
 {
      //Code path to use camera to take picure.  
 }
 else
 {
      //Get Image from local fs
 }
 //work with the image and prepare it for use.

}

I want the code to await the user's response, then to continue with their selected path in the code.
I wanted to use the SfPopup since I could use some icons and make the accept and decline options more graphical (I am assuming that I can overload the ImageButton click events to the accept and decline members.
Finally I would also like to know if I can display the popup with no buttons available (Using my own graphical controls for the form?)

In summary,
Can I make the popup.show() awaitable? Or in other words, can I use the return of the popup.Show() for flow control of the app?
Can I hide the Accept button?

Does anyone here have experience with this kind of thing?

My alternative is to build my own view control that I wire all this stuff up in, but I was hoping that there was an easier method to my madness.

Cheers!

How to make a Label 'text flow from up to down?

$
0
0

for example,this is a Label:

H
i
,
I 
a
m
c
o
l
e
x

is it the FlowDirection?I tried but not work.


ImageButton

$
0
0

Why does my imagebutton look like this?
I want the only picture to be shown.

Is it possible to add photos to Android AVD/iPhone emulators?

$
0
0

I don't have Android studio installed, is there a way via Visual Studio or otherwise a way to upload a couple of pictures to Android/iPhone emulators to test the photo features of my XF app? If so, how?

Text on Button

$
0
0

Hi All,

The text given to Button control in xamarin forms appears in Capital letter all times. Can you please suggest solution on it.

Thanks..

Interop with Native Libraries in Xamarin Forms for encryption

$
0
0

I have been following this example on how to encrypt a Sqlite database in a Xamarin project.
https://github.com/Azure-Samples/app-service-mobile-dotnet-offline-encryption
I have created a libsqliteX.so file using a SEE license and added to the Android project along with an app.config file that looks like this
<?xml version="1.0" encoding="utf-8"?>



And added the following to the Android csproj file
True

The application run and builds but when I look at the database it is not encrypted.
I believe the issue is with the Android project not mapping the dll for sqlite3 to libsqliteX.so.
I can find examples of dll mapping Xamarin.Android but not Xamarin.Form
Is anyone able to advise on how this could be achieved or advise on how to encrypt an sqlite db in a Xamarin Android project?

How to change case for buttons?

$
0
0

I wish to change the text case of button in ios and uwp using effects but im not getting which control method I should use for the same.
Any inputs appreciated

Beacons are not detected sometimes

$
0
0

Hi there I am using modified AltBeacon library sample: https://github.com/acaliaro/AltBeaconLibrarySample
I am starting the service in MainPage instead of App Main (Because I need to login first where I get Beacons from the server, save them to local storage (for quick retrival later))

My App.cs only has resume methos

    public partial class App : Application
    {
        bool _closeTimer = false;

        public static ICrossTimer timer; //to gain acsess to timer class
        public static CAPI api; //To get acsess to our API
        public App()
        {
            InitializeComponent();

            DependencyService.Register<MockDataStore>();

            App.api = new CAPI(); //To get acsess to our API

            //if API KEY is invalid or doesn't exists yet, prompt user to login
            string API_LOGIN = Preferences.Get("API_KEY_LOGIN", null);
            string API_SECRET = Preferences.Get("API_KEY_SECRET", null);
            DateTime APIKeyDate = Preferences.Get("API_KEY_STATUS", DateTime.Parse("1/1/1970"));
            string API_URL = Preferences.Get("API_URL", null);


            if (DateTime.Now > APIKeyDate) //Key is expired if its date is smaller than todays date
                MainPage = new Views.LoginPage();
            else
            {
                App.api.LoginWithAPIKey(Constants.TENANTID, API_LOGIN, API_SECRET, APIKeyDate, API_URL);
                App.IsUserLoggedIn = true;
                MainPage = new MainPage();
           }
        }

        // Use a service for providing this information
        public static bool IsUserLoggedIn { get; set; }

        protected override void OnStart() // Handle when your app starts
        {
            DependencyService.Get<IAltBeaconService>().SetBackgroundMode(false);
            startTimer();           
        }

        protected override void OnSleep() // Handle when your app sleeps
        {
            DependencyService.Get<IAltBeaconService>().SetBackgroundMode(true); //Why is this usefull with this I need to wait even longer before OnEntered Region is called and the service gets killed anyway :(
            closeTimer();
        }

        protected override void OnResume() // Handle when your app resumes
        {
            DependencyService.Get<IAltBeaconService>().SetBackgroundMode(false);
            startTimer();
        }

        void startTimer()
        {

            _closeTimer = false;

            Device.StartTimer(TimeSpan.FromSeconds(10), () =>
            {

                if (_closeTimer)
                {

                    System.Diagnostics.Debug.WriteLine("StartTimer: stop repeating");
                    return false;
                }

                Xamarin.Forms.MessagingCenter.Send<App>((App)Xamarin.Forms.Application.Current, "CleanBeacons");

                System.Diagnostics.Debug.WriteLine("StartTimer: end with " + (!_closeTimer ? "repeating" : "stop repeating"));

                return !_closeTimer;
            });
        }
        private void closeTimer()
        {
            _closeTimer = true;
        }
    }
[assembly: Xamarin.Forms.Dependency(typeof(AltBeaconService))]
namespace Calimero.Droid.Services
{
    public class AltBeaconService : Java.Lang.Object, IAltBeaconService
    {
        bool BeaconEventCalled = false;

        private readonly Calimero.Droid.Notifiers.MonitorNotifier _monitorNotifier;
        private readonly RangeNotifier _rangeNotifier;
        private BeaconManager _beaconManager;

        Org.Altbeacon.Beacon.Region _tagRegion;

        Org.Altbeacon.Beacon.Region _emptyRegion;

        public AltBeaconService()
        {
            _monitorNotifier = new Calimero.Droid.Notifiers.MonitorNotifier();
            _rangeNotifier = new RangeNotifier();
        }

        public BeaconManager BeaconManagerImpl
        {
            get
            {
                if (_beaconManager == null)
                    _beaconManager = InitializeBeaconManager();
                return _beaconManager;
            }
        }

        public void InitializeService()
        {
            if (_beaconManager == null)
                _beaconManager = InitializeBeaconManager();
        }

        private BeaconManager InitializeBeaconManager()
        {
            // Enable the BeaconManager 
            BeaconManager bm = BeaconManager.GetInstanceForApplication(Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity);

            var iBeaconParser = new BeaconParser();
            //  Estimote > 2013
            iBeaconParser.SetBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
            bm.BeaconParsers.Add(iBeaconParser);

            _monitorNotifier.EnterRegionComplete += EnteredRegion;
            _monitorNotifier.ExitRegionComplete += ExitedRegion;
            _monitorNotifier.DetermineStateForRegionComplete += DeterminedStateForRegionComplete;
            _rangeNotifier.DidRangeBeaconsInRegionComplete += RangingBeaconsInRegion;

            //Get Region from storage
           string BEACON_REGION = Preferences.Get("BEACON_REGION", null);
           if(BEACON_REGION != null)
               _tagRegion = new Org.Altbeacon.Beacon.Region("MyRegion", Identifier.Parse(BEACON_REGION), null, null);
           else
                _tagRegion = new Org.Altbeacon.Beacon.Region("MyRegion", Identifier.Parse("F7826DB4-2FG1-4E98-8024-BC0871E6693E"), null, null);
            _emptyRegion = new Org.Altbeacon.Beacon.Region("myEmptyBeaconId", null, null, null);

            bm.BackgroundMode = false;
            bm.Bind((IBeaconConsumer)Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity);

            return bm;
        }

        public void StartMonitoring()
        {
            BeaconManagerImpl.ForegroundBetweenScanPeriod = 5000;
            BeaconManagerImpl.BackgroundBetweenScanPeriod = 5000;

            BeaconManagerImpl.AddMonitorNotifier(_monitorNotifier);
            BeaconManagerImpl.StartMonitoringBeaconsInRegion(_tagRegion);
            BeaconManagerImpl.StartMonitoringBeaconsInRegion(_emptyRegion);
        }

        public void StartRanging()
        {
            BeaconManagerImpl.ForegroundBetweenScanPeriod = 100;
            BeaconManagerImpl.BackgroundScanPeriod = 500;
            BeaconManagerImpl.BackgroundBetweenScanPeriod = 30000;
            BeaconManagerImpl.ForegroundScanPeriod = 200;

            BeaconManagerImpl.AddRangeNotifier(_rangeNotifier);
            try
            {
                BeaconManagerImpl.StartRangingBeaconsInRegion(_tagRegion);
                BeaconManagerImpl.StartRangingBeaconsInRegion(_emptyRegion);

            }
            catch (Exception ex)
            {

                System.Diagnostics.Debug.WriteLine("StartRangingException: " + ex.Message);
            }

        }

        public void StopRanging()
        {
            if (_beaconManager != null)
            {
                try
                {
                    BeaconManagerImpl.StopRangingBeaconsInRegion(_tagRegion);
                    BeaconManagerImpl.StopRangingBeaconsInRegion(_emptyRegion);
                    BeaconManagerImpl.RemoveRangeNotifier(_rangeNotifier);
                }
                catch (Exception ex)
                {

                    System.Diagnostics.Debug.WriteLine("StopRangingException: " + ex.Message);
                }
            }
        }

        private void DeterminedStateForRegionComplete(object sender, MonitorEventArgs e)
        {
            Console.WriteLine("DeterminedStateForRegionComplete");
        }

        private void ExitedRegion(object sender, MonitorEventArgs e)
        {
            string region = "???";
            if (e.Region != null)
            {
                if (e.Region.Id1 == null)
                    region = "null region";
                else
                    region = e.Region.Id1.ToString().ToUpper();
            }

            CrossLocalNotifications.Current.Show("Beacon", "You Exited region");
            Calimero.Util.Malca.startBreak();
            BeaconEventCalled = false;
        }

        private void EnteredRegion(object sender, MonitorEventArgs e)
        {
            string region = "???";
            if (e.Region != null)
            {
                if (e.Region.Id1 == null)
                    region = "null region";
                else
                    region = e.Region.Id1.ToString().ToUpper();
            }
            CrossLocalNotifications.Current.Show("Beacon", "You Just Entered Region");
            Calimero.Util.Malca.stopBreak();
            BeaconEventCalled = true;
        }

        List<SharedBeacon> _sharedBeacons = new List<SharedBeacon>();

        object _lock = new object();

        void RangingBeaconsInRegion(object sender, RangeEventArgs e)
        {

            _sharedBeacons = new List<SharedBeacon>();

            lock (_lock)
            {

                // Get all beacons and create the SharedBeacon
                foreach (Beacon beacon in e.Beacons)
                {
                    System.Diagnostics.Debug.WriteLine(string.Format("NAME {0} - IP {1} - {2}dB", beacon.BluetoothName, beacon.BluetoothAddress, beacon.Rssi));
                    _sharedBeacons.Add(new SharedBeacon(beacon.BluetoothName, beacon.BluetoothAddress, beacon.Id1.ToString(), beacon.Id2.ToString(), beacon.Id3.ToString(), beacon.Distance, beacon.Rssi));
                };

                if (!BeaconEventCalled) //if EnteredRegion is not invoked, invoke backup method
                    BackupBeaconAlert(_sharedBeacons);
            }

        }

        //Backup way incase OnEntered was not called
        /*
         *  if Beacon in local list is already in globalList and time between last addition is > 3 seconds
         *  Beacon is not in range anymore so remove it from GlobalList and Call OnExited
         *  if time between last addition is < 3 seconds, then its new beacon so call OnEntered
         */
        //Dictionary<DateTime, SharedBeacon> GlobalList = new Dictionary<DateTime, SharedBeacon>();
        List<SharedBeacon> GlobalList = new List<SharedBeacon>();
        void BackupBeaconAlert(List<SharedBeacon> localList)
        {
            // Go through localList first and compare
            foreach (SharedBeacon b in localList)
            {
                if (GlobalList.Count == 0) //GlobalList is empty so there are not Beacons in the area
                {
                    GlobalList.Add(b);

                }
                else
                {
                    for (int i = 0; i < GlobalList.Count; i++)
                    {
                            DateTime storedTime = GlobalList[i].LastReceivedDateTime;
                            DateTime CurrentTime = DateTime.Now;
                            if ((CurrentTime - storedTime).TotalSeconds >= 3)
                            {
                                GlobalList.Remove(b);
                                BExitedRegion();
                            }
                            else
                                BEnteredRegion();
                    }
                }
            }
        }

        private void BExitedRegion() //Backup method when phone left beacon region
        {
            CrossLocalNotifications.Current.Show("Beacon", "You Exited region");

            Calimero.Util.Malca.startBreak();
            BeaconEventCalled = false;

        }

        private void BEnteredRegion() //Backup method when phone is in Beacon Region
        {
            CrossLocalNotifications.Current.Show("Beacon", "You Just Entered Region");

            BeaconEventCalled = true;
        }


        public void SetBackgroundMode(bool isBackground)
        {
            if (_beaconManager != null)
                BeaconManagerImpl.BackgroundMode = isBackground;

        }

        public void OnDestroy()
        {

            if (_beaconManager != null && BeaconManagerImpl.IsBound((IBeaconConsumer)Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity))
                BeaconManagerImpl.Unbind((IBeaconConsumer)Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity);

        }
    }
}

now this service has 2 problems, which I have no idea how to fix, region detection doesn't work reliably, sometimes OnEntered region method is never called or it takes like 5 seconds for it to get called but I know that I am in region, because beacon is near me

so to mitigate this I implemented BackupBeaconAlert which speeds things up a bit but its still not realiable

or sometimes OnExited region method is called for no reason even if I am in the region, one time OnEntered method was called even when I had bluetooth turned off

and the second problem is that if you kill the app or close it (after a while when you close it) the service gets killed and beacons are not detecting anymore, as I am on Android 10 I would probably need to reimplement this beacon searching thing in Foreground service but I don't know how to convert this into Foreground service so it never gets killed?

Thanks for Anwsering and Best Regards

Is VisualTreeHelper going to be ever implemented and what is the best workaround for now?

$
0
0

I saw many questions similar to this one and there are some ideas for a workaround but what I saw is far from being perfect. The most accepted workaround using reflection to find "Children" or "Content" or "TemplatedItems" and go recursively. When this method is used rarely I'd say it's OK but if you need to go over the children hierarchy rather often it is definitely not acceptable. I saw there are LogicalChildren and RealParent properties which probably could be used and give much better performance but they are documented as internal and I have doubts about reliability of them. Even though they are probably even more reliable than the method with using reflection.
I would like to hear from the Xamarin developers. If an analogy of the VisualTreeHelper is not implemented yet what is the best approach for iterating over the components hierarchy?


selected tabbar item using shell

$
0
0

Hi All,

I have come across a problem where i am unable to add background colour to selected tabbar item using shell in xamarin forms.

Are there any ways to achieve this.

Thanks!!!

Xamarin.Forms make photo in pdf

$
0
0

I need a good tutorial or guide to make a converter from image to pdf. Any ideas. Maybe make a dll and import in xamarin.forms app? I dont know from where to start. Good plugins are very expensive

Passing data in xaml

$
0
0

hi everyone,

I've got trouble to pass data in xaml. I would like to initialize a component named PDebugListPage passing a list of business items :

ListeLogs is a List declared in the ViewModel. The constructor of PDebugListPage is :

I don't know how to "bind" the ListeLogs between my xaml and my viewmodel.

Thanks for your answer !

Adrien.

Cascade BindableProperties

$
0
0

Hey,
I'have a theoretical question. Is it possible to define some BindableProperties and cascade their values? I think about something like this:
You define three BindableProperties. If the user just set one the two others should have a value of the first as default value. If he sets all values every property should have its own value.

I have not found any solution of how to set the default value to return another property. Is it even possible?

Thanks
flo

How to do SSL certificate pinning in Xamarin forms?

$
0
0

Hi all, I want to implement SSL certificate pinning with server using xamarin forms. Could any one please share me the code

Viewing all 77050 articles
Browse latest View live


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