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

Not taking back to app from google auth page


Bluetooth Thermal Printer

$
0
0

I'm trying to connect to a Bluetooth thermal Printer using Xamarin forms, and not platform specific.
I try to use Binding Jar, but failed to connect and send data to printer.. Anyone have idea on how to do it?

plugin.Ble issue

$
0
0

Does anyone solve this problem i encountered error, GattCallback error : 133, using plugin.ble

here is my code below:

  device = DevicesList.SelectedItem as IDevice;

        var result = await DisplayAlert("Confirm", "Do you want to connect?", "Connect", "Cancel");

        if (!result)
            return;

        //Stop Scanner
        await adapter.StopScanningForDevicesAsync();

        try
       {


        await adapter.ConnectToDeviceAsync(device);

        await DisplayAlert("Connection", "Status:" + device.State , "OK");

      }
       catch (DeviceConnectionException ex)
      {
           await DisplayAlert("Error", ex.Message, "OK");
      }

HttpClient - Connection refused

$
0
0

I've got a web service in my control on my server. This server does just fine on my development machine using win forms and postman. However, when Attempt the same request via my emulator, it comes back with a ECONNREFUSED (Connection refused) error.

The code couldn't be any more simple:

    HttpClient client = new HttpClient(new ModernHttpClient.NativeMessageHandler());
            client.BaseAddress = new Uri(@"http://192.168.2.22:1604/WebService/");
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            try
            {
                string uri =  "api/Logins?Code=byteguy&Password=Kinkee";
                string response = await client.GetStringAsync(uri);
                var t = JsonConvert.DeserializeObject<Models.Login>(response);
            }
            catch (Exception ex)
            {
                throw ex;
            }

I'm new to xamarin so I suspect its something I need to do with the emulators. Thanks in advance for any help.

Closing Xamarin.Forms Page Causes App to Crash

$
0
0

Hi

While writing this, I got it working, but posting anyway in case it helps someone else

I am having issues closing a page on Xamarin.Forms running on Android. My app is monolithic - the Android activity launches a Xamarin.forms page based on the content of an Android intent. For this reason I have the decoration:

LaunchMode = LaunchMode.SingleTask, ExcludeFromRecents = true, NoHistory = true

On my Android activity - When back or home is pressed, there is nothing in resents. If the activity is already active and another intent is bound for my app, no new activity is launched (Launchmode.SingleTask), rather I simply switch the active page (while maintaining no history).

This intent comes via a tap, bluetooth characteristic change or via NFC. One of my pages is simply a popup on an NFC intent that initiates a connection to a BLE device.

Onto the Issue

In one of my pages I have a simple 'Close' button, the page is launched via an intent as above, currently (for debug) the close is wired to the codebehind (it will end up being done from the viewmodel off a timer). I have thus far tried three methods to close the page all of which result in a crash:

1) Close();
2) await Navigation.PopModalAsync();
3) Through the DependancyService using an interface that calls: activity.FinishAffinity(); (also tried just Finish() and FinishActivity()

For 1) and 2), I get exceptions thus

1) exception = {System.InvalidCastException: Specified cast is not valid. at ProteusPatientApp.Views.ConnectionStatusPage.Close () [0x00001] in ConnectionStatusPage.xaml.cs:32

2) Message = "Index was out of range. Must be non-negative and less than the size of the collection.\nParameter nam…"

I believe that both of the above failed due to the monolithic, no history, no navigation stack nature of my app.

For three, one needed to get the activity, but the getter mechanism 'Xamarin.Forms.Forms.Context' is obsoleted. I tried 'Android.App.Application.Context' but this resulted in an 'InvalidCastException'.

The solution was to implement the IActivityLifecycleCallbacks interface. There are two ways of doing this - using James Montemagno's Plugin.CurrentActivity which implements the IActivityLifecycleCallbacks in a file MainApplication.cs, or to manually implement the interface. Since implementing the interface is easy, I went for the manual method. The hints for this came from: https://stackoverflow.com/questions/47353986/xamarin-forms-forms-context-is-obsolete and you can simply paste the code from this into a new file MainApplication.cs.

I moved the decoration for [Application] from the Manifest into the MainApplication.cs thus:

 [Application(Label="ProteusPatientApp.Android",Icon="@drawable/spacelabs_logo",  Theme="@android:style/Theme.Translucent.NoTitleBar")]
 public partial class MainApplication : Application, Application.IActivityLifecycleCallbacks
........

I also had to remove the code:

[assembly: Application(Debuggable = true)]

From my application as otherwise the thing threw a load of Java errors during compilation - I never for to the bottom of this. Anyway, I can now Close the current Activity (or a Popup window implemented using Rg.Plugins.Popup either with button press or programatically.

Following on from that you just need an interface in your UI code 'ICloseApplication.cs':

    namespace ProteusPatientApp.Interfaces
    {
        public interface ICloseApplication
        {
            void CloseApplication();

        }
    }

And an implementation for it in your Android code 'CloseApplication.cs':

[assembly: Xamarin.Forms.Dependency(typeof(ApplicationCloser))]
namespace ProteusPatientApp.Droid
{
    public class ApplicationCloser : ICloseApplication
    {
        public void CloseApplication()
        {

            var activity = (Activity)MainApplication.ActivityContext;
            activity.FinishAffinity();
        }
    }
}

On Android my service does the work, and calling activity.FinnishAffinity() only closes the activities - the service sits there waiting to do work. Things are different on iOS as it has no concept of services or (for non Voip apps), boot start apps. If you do want to close the app in iOS, you can implement the close interface thus. NB: Apparently this is not recommended - iOS likes to maintain the lifecycle of apps by its-self, and going DIY can cause you issues with store approvals - so says the internet. I have not done the iOS bit for my app as yet.

    [assembly: Xamarin.Forms.Dependency(typeof(ApplicationCloser))]
    namespace ProteusPatientApp.iOS
    {
        public class ApplicationCloser : ICloseApplication
        {
            public void CloseApplication()
            {
            Thread.CurrentThread.Abort();
            }
        }
    }

Nigel

How to resolve ArgumentException: Failed to parse PList data type

$
0
0

After updating Visual Studio to 15.6 today on my Windows PC, and updating Visual Studio and XCode on the Mac, I am getting the following when trying to build my app for iOS. Does anybody know how to resolve this?

AggregateException: One or more errors occurred.
MessagingRemoteException: An error occured on client Build490752 while executing a reply for topic xvs/Build/4.9.0.752/execute-task/MyApp.iOS/e164987002fIBTool
ArgumentException: Failed to parse PList data type:
ArgumentException: Must specify valid information for parsing in the string.

Xamarin App for Windows, iOS, Android and Mac

$
0
0

Hi!
We have started using Xamarin.Forms for a Trial Project. Now a new bigger and more substentiall Project is coming up.

My plan would be to start the new (business critical) app with iOS und Android and later on generate also an UWP and MacOS Version.

To push through, it would be easier to have a reference app, which at least runs under iOS, Android and UWP. Is there a known App, which could be used therefore? The MSN News App is now in beta with Xamarin.Forms, but as I understood, the UWP Version is still "normal" and only Shares Code with iOS and Android Xamarin.forms. Is this correct? Are there other reference Projects?

Thanks in advance
Wolfgang

Two-way binding on Native Control causes severe crash— am I doing it right?

$
0
0

My Mac, Xcode and Visual Studio for Mac are all completely up to date as of writing.

I create a new forms app from the template.

On AboutPage.xaml, I add the iOS namespace by adding xmlns:ios="clr-namespace:UIKit;assembly=Xamarin.iOS;targetPlatform=iOS" to the ContentPage node.

I then add a ios:UITextField Text="{Binding Test, Mode=TwoWay}" node about the AppName label.

In AboutViewModel.cs, I add a test property, like so:

private string test = String.Empty;

public string Test

{

get { return test; }

set { SetProperty(ref test, value); }

}


When I play this application in the Simulator (iPhone X iOS 11.3), when I enter text into the UITextField on the about page, it horribly crashes.

I can’t catch the exception, this seems to be a really low level crash.

Have I done this wrong?



Content Page Secondary Toolbar Items in iOS same as Android

$
0
0

I am using secondary toolbar items in my content page. I want the same menu items in iOS as in android. By default it is showing under navigation bar. How can I achieve this.

Application.Current.Properties Can not persist in Android ,Using XF 1.42

$
0
0

It work fine on iOS but when android os restrart ,the properties is empty ,even I use
await Application.Current.SavePropertiesAsync();
after set the value

getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), KnownFolders etc

$
0
0

getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) and KnownFolders (Android, UWP)

Im using Xamarin.Forms, but I need to use the above platform specific features(and others) to get some info. I cant just chuck them into my .NETstandard PCL, that seems clear. Do they need to go in the platform specific projects? Um, How?

Does anyone have a sample implementation of expandable listview on shared project in xamarin forms

$
0
0

Im new in Xamarin app development and iv tried looking for a way to implement an sample of a button with an onlick event that displays a list view with child underneath it?

How to change navigation bar background color for each content page?

$
0
0

I want to change xamarin forms app content page's navigation bar background color for each page instead of common color, has any plugin or default feature how can I change it?

I need to change for each page separately to match with content page's body.

UIKeyboard height in Xamarin IOS is not right in the first time.

$
0
0

I am listening the event using this

notification = UIKeyboard.Notifications.ObserveWillShow(KeyboardWillShow);

 void KeyboardWillShow(object sender, UIKit.UIKeyboardEventArgs args)
        {
          var gg=  args.FrameEnd.Size.Height;
            KeyboardShowing?.Invoke(this, new KeyboardHeightEventArgs(args.FrameEnd.Height));
        }




 var keyboard = DependencyService.Get<IKeyboardNotifications>();
                keyboard.StartListening();
                keyboard.KeyboardShowing += (s, e) =>
                {
                    var arg = e as KeyboardHeightEventArgs;
                    Device.BeginInvokeOnMainThread(() => {                 
                    //    SendMessageGrid.TranslationY = arg.Height == 0 ? 0 : -arg.Height - SendMessageGrid.Height;
                    });
                };

When the event occurs the first time then the event gives height slightly higher and then after the first occurrence, it gives the right height.
For example, here it gives me 258 at first and in second it gives 216.

Failure [INSTALL_FAILED_VERSION_DOWNGRADE], can not deploy Android app

$
0
0

Hello, in my solution, I can not run the project on my Android phone. Can not deploy the solution because of the error : Failure [INSTALL_FAILED_VERSION_DOWNGRADE]. How can I solve it?


await UserDialogs.Instance.PromptAsync doesn't await/prompt after resuming from locked screen

$
0
0

Hello,

I'm using Acr.UserDialogs 6.3.8 and am trying to figure out why after minimizing the xamarin forms app on droid and locking the screen that when I come back in the dialog doesn't await. When I first start up the app the dialog awaits accordingly. I put a break on var prompt and when I hit F10 it never goes to the next line or prompts.

I have to use Acr.UserDialogs 6.3.8 because I have a dependency on xamarin.android.support 25.3.1

public async Task PerformEpicLogin(bool tryAltMethod = false)
{
.....
var pc = new PromptConfig
{
MaxLength = 4,
InputType = InputType.NumericPassword,
Title = "Enter your Passcode",
OkText = "Login",
};

                var prompt = await UserDialogs.Instance.PromptAsync(pc);
                if (prompt.Ok)
                {
                    ShieldText = "logging in...";
                    epicService.DoLoginWithPasscode(prompt.Text);
                }
                else
                {
                    ShieldText = "";
                }

         .....
         return true;
    }

Thanks for any insights you may have.

How bad is this code?

$
0
0

Hello again:

This is not realted with previous questions at all, and want to know how bad is what I'm going to propose.
I wanted to pass a value to the previous page, but I though that to pass the entire ViewModel from one page to another just for this was too much.
The idea is to pass to the parent page filter the ID of a item created on the child page. That way, the parent list will shows only the recently created item, so, from the child ViewModel I added this to the CreateItem command:

                    if ((Navigation != null) && (Navigation.NavigationStack.Count >= 2))
                    {
                        Page tempPage = Navigation.NavigationStack[Navigation.NavigationStack.Count - 2];
                        ((ParentViewModel)tempPage.BindingContext).SearchBarTextToFind = newItem.ToString();
                    }
                    await Navigation.PopAsync();

I think this is bad coding, but I'm just getting a page, and only modifying his ViewModel (a binded variable to the form), and it works, but should I change it?

Thanks.

"D/AbsListView( 3323): viewType is heaer or footer" message constantly scolloing in debug

$
0
0

Anyone know why the message below is constantly filling up the debug window? it seems the message has "header" spelled incorrectly as well. What does it mean?

02-08 23:28:45.031 D/AbsListView( 3323): viewType is heaer or footer
02-08 23:28:45.041 D/AbsListView( 3323): viewType is heaer or footer
02-08 23:28:45.051 D/AbsListView( 3323): viewType is heaer or footer
02-08 23:28:45.231 D/AbsListView( 3323): viewType is heaer or footer
02-08 23:28:45.241 D/AbsListView( 3323): viewType is heaer or footer
02-08 23:28:45.241 D/AbsListView( 3323): viewType is heaer or footer

Nathan

Hide tab bar on push

$
0
0

I would like to hide the tab bar of a TabbedPage when a specific page is pushed with Navigation.PushAsync(). In iOS UIViewController.hidesBottomBarWhenPushed does the job, is there any way to do the same with Xamarin.Forms? Or is there a method/property to hide the tab bar? I can't seem to find anything.

How to Go About Requesting Data from a User?

$
0
0

Hello, everyone.

I have a Xamarin Forms app and a Windows Forms app. I'm looking for a way to request a specific user to send their GPS data to a database. Right now I've got database connectivity through a WCF service. What I want to do is have someone click a button on the Windows Forms app to send a request to the Xamarin Forms app where it will get the user's lat/long and return it to the database. I'm using the Geolocator plugin to get GPS data.

I'm relatively new to Xamarin Forms so if someone could just point me in the right direction, I'd appreciate it.

Viewing all 75885 articles
Browse latest View live


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