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

How to display image in byte[] in listview

$
0
0

in page.xaml.cs i have used webservice to fetch data from sqlserver and data is present in List<> expense. List contains Image in byte[] . how will i convert it and assign it to itemsource of ListViiew and display in List view.

public partial class frmProductCatType : ContentPage
{
List fpdetails = new List();
List expense = new List();
public frmProductCatType()
{
InitializeComponent();
FlowListView.Init();

        BindingContext = new ProductCatViewModel(this);
    }
    protected async override void OnAppearing()
    {

        string url = "http://192.168.10.113:6556/api/PROD_CATE_TYPE_MASTR";

        if (response.IsSuccessStatusCode)
        {
            var json1 = await response.Content.ReadAsStringAsync();
            expense = JsonConvert.DeserializeObject<List<PROD_CATE_TYPE_MASTR>>(json1);
        }
        iList.ItemsSource = expense;
    }
}

Model

public class PROD_CATE_TYPE_MASTR
{
public int CAT_ID { get; set; }
public string CAT_TYPE { get; set; }
public string CAT_TYPE_CODE { get; set; }
public string DESCRIPITION { get; set; }
public byte[] PRODIMAGE { get; set; }
}

Page.Xaml

    <ListView.ItemTemplate>

        <DataTemplate>

            <ViewCell>

                <StackLayout Orientation="Horizontal">

                    <Image Source="{Binding PRODIMAGE}"/>

                </StackLayout>

            </ViewCell>

        </DataTemplate>

    </ListView.ItemTemplate>

</ListView>

Xamarin.Forms ZXing scanner double-scanning barcode

$
0
0

Hi,

I'm using ZXing to scan barcodes. In some cases however, it takes some time to process the found value of the barcode. To let the user know that the scanner has picked up the barcode, I added a ACR.UserDialog to show that the app is working on it.

The scanner itself however remains active, causing it to scan over and over again if it sees a barcode. This causes my app to crash.
I tried to solve it with IsAnalyzing = false and IsEnabled = false, but that didn't do the trick:

The barcode is processed in open_page().

Does someone know how to disable/turn off ZXing while processing the barcode?

Regards, Ganesh

HOW TO DESIGN A 3-BUTTON TAB IN XAMARIN FORMS

How to run the InsertAllAsync completely even when it thrown exception

$
0
0

Hi I am using InsertAllAsync method to insert few records in to the database. There is a primary key constraint on the table. But I am getting few duplicate values on the primary key. If I keep a for loop and do InsertAsync I am able to insert all records ignoring duplicate records, but InsertAllAsync throwing exception "Constraint" and not inserting single record in the db. Please let me know any other way to ignore the "Constraint Exception". I have to use only InsertAllAsync.

How to insert all data using InsertAllAsync

$
0
0

Hello.. anyone know how to insert all data using InsertAllAsync.. i want to insert all data before i delete data in sqlite.

How to pass a dll path to msbuild?

$
0
0

I want to pass another path to a dll to msbuild and don't want to use the integrated HintPath in the csproj file for the same library. Therefore I use the following command:

"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\MSBuild" /p:ReferencePath=C:\path\to\libfolder path/to/My.Android.csproj /p:Configuration=Release /t:PackageForAndroid /t:Build

After executing this command I get

error CS0103: The name 'xxx' does not exist in the current context

What am I missing? Attached you find my sample project with the error (you have to rename the library project so that he must take the reference).

Shared Auth across multiple WebViews

$
0
0

Hi Everyone,

I have a MasterDetailPage setup where I can load a detail page which presents a webview - in that webview I sign in to a secure website. That works fine.

I then change the menu bar (Master) in my MasterDetailPage and allow access to lists of pages, including a RSS list which onwardly loads (via Naviation.PushAsync(new page1())) web views that are behind the same authentication that I passed a few seconds ago.

This time however I am pushed back to the sign in page?? Any know how I can force or keep the authentication session live between web views?

I'm sure this has been tackled before, fixed before or solutions created before - it must be a common issue but I just can't seem to find a solution.

Any and all help is greatly appreciated.

Thank you

Is it possible to put a toolbar item in contentview?

$
0
0
<ContentPage.ToolbarItems>
    <ToolbarItem Order="Secondary"
                 Text="Share"
                 Command="{Binding ShareCommand}"
                 Priority="0"/>
</ContentPage.ToolbarItems>

Is it possible to do something like the above except with a ContentView? Or could someone please point out how to do something equivalent? So that one can make a list of views that will each have its own contextual menu (with the 3 dots button).

I noticed someone had asked this at the bottom of another thread but thought it may have been overlooked.


Receive data from Serial Usb

$
0
0

Hello!
I am trying to establish data exchange with my custom device connected via Serial Usb. I am using UsbSerialForAndroid https://github.com/anotherlab/UsbSerialForAndroid.
I managed to connect to my device and successfully send data.
My device should answer me right away, but I can’t track the response. The DataReceived event never fires.

public class SerialUsbConnector
    {
    const string ACTION_USB_PERMISSION = "USB_PERMISSION";
        private IUsbSerialPort _port;
        private UsbManager _usbManager;
        private SerialInputOutputManager_serialIoManager;
        public void Init()
        {
            _usbManager = Android.App.Application.Context.GetSystemService(Context.UsbService) as UsbManager;
                var drivers = await FindAllDriversAsync(_usbManager);
                if (drivers.Count == 0) return;
                var driver = drivers.ToArray()[0];
                if (driver == null)
                    throw new Exception("Driver specified in extra tag not found.");
                _port = driver.Ports[0];
                if (_port == null)
                {
                    return;
                }
                GetPremission(driver.Device);
                var portInfo = new UsbSerialPortInfo(_port);
                int vendorId = portInfo.VendorId;
                int deviceId = portInfo.DeviceId;
                int portNumber = portInfo.PortNumber;
                _serialIoManager = new SerialInputOutputManager(_port)
                {
                    BaudRate = 115200,
                    DataBits = 8,
                    StopBits = StopBits.One,
                    Parity = Parity.None,
                };
                _serialIoManager.DataReceived += (sender, e) => {
                   ///…///
                    System.Diagnostics.Debug.WriteLine(e.Data);
                };
                _serialIoManager.ErrorReceived += (sender, e) => {
                    ///…///
                };
                try
                {
                    _serialIoManager.Open(_usbManager);
                }
                catch (Java.IO.IOException e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    return;
                }
                Device.BeginInvokeOnMainThread(() =>
                {
                    _serialIoManager.Write("some message", 50);   // Added
                });
        }
        private Task<IList<IUsbSerialDriver>> FindAllDriversAsync(UsbManager usbManager)
        {
        return UsbSerialProber.DefaultProber.FindAllDriversAsync (usbManager);
        }        
        private async void GetPremission(UsbDevice device)
        {
           ///…///
        }     
}

I added a method to write to a library class SerialInputOutputManager

public int Write(String str, int timeout)
    {
        int bytesWritten = 0;
        try
        {
            List<byte> buff = new List<byte>();
            buff.AddRange(Encoding.ASCII.GetBytes(str));
            bytesWritten = port.Write(buff.ToArray(), timeout);
        }
        catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine(ex.Message + "\n");
        }
            return bytesWritten;
    }

Can anybody help me?

Receiving data from Serial Usb

$
0
0

Hello!
I am trying to establish data exchange with my custom device connected via Serial Usb. I am using UsbSerialForAndroid https://github.com/anotherlab/UsbSerialForAndroid.
I managed to connect to my device and successfully send data.
My device should answer me right away, but I can’t track the response. The DataReceived event never fires.

public class SerialUsbConnector
    {
    const string ACTION_USB_PERMISSION = "USB_PERMISSION";
        private IUsbSerialPort _port;
        private UsbManager _usbManager;
        private SerialInputOutputManager_serialIoManager;
        public async Task Init()
        {
            _usbManager = Android.App.Application.Context.GetSystemService(Context.UsbService) as UsbManager;
                var drivers = await FindAllDriversAsync(_usbManager);
                if (drivers.Count == 0) return;
                var driver = drivers.ToArray()[0];
                if (driver == null)
                    throw new Exception("Driver specified in extra tag not found.");
                _port = driver.Ports[0];
                if (_port == null)
                {
                    return;
                }
                GetPremission(driver.Device);
                var portInfo = new UsbSerialPortInfo(_port);
                int vendorId = portInfo.VendorId;
                int deviceId = portInfo.DeviceId;
                int portNumber = portInfo.PortNumber;
                _serialIoManager = new SerialInputOutputManager(_port)
                {
                    BaudRate = 115200,
                    DataBits = 8,
                    StopBits = StopBits.One,
                    Parity = Parity.None,
                };
                _serialIoManager.DataReceived += (sender, e) => {
                   ///…///
                    System.Diagnostics.Debug.WriteLine(e.Data);
                };
                _serialIoManager.ErrorReceived += (sender, e) => {
                    ///…///
                };
                try
                {
                    _serialIoManager.Open(_usbManager);
                }
                catch (Java.IO.IOException e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    return;
                }
                Device.BeginInvokeOnMainThread(() =>
                {
                    _serialIoManager.Write("some message", 50);   // Added
                });
        }
        private Task<IList<IUsbSerialDriver>> FindAllDriversAsync(UsbManager usbManager)
        {
        return UsbSerialProber.DefaultProber.FindAllDriversAsync (usbManager);
        }        
        private async void GetPremission(UsbDevice device)
        {
           ///…///
        }     
}

I added a method to write to a library class SerialInputOutputManager

public int Write(String str, int timeout)
    {
        int bytesWritten = 0;
        try
        {
            List<byte> buff = new List<byte>();
            buff.AddRange(Encoding.ASCII.GetBytes(str));
            bytesWritten = port.Write(buff.ToArray(), timeout);
        }
        catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine(ex.Message + "\n");
        }
            return bytesWritten;
    }

Can anybody help me?

Play live stream from RTMP URL

$
0
0

Hi,
i have a live stream going through an RTMP URL
i need to somehow display the video that coming from it...
when i use the VideoView it says "Can't play this video"
any idea ?

App center distribute - your experience with in-app updates

$
0
0

I have android app in which I implemented in-app updates through App Center. At the beginning, around a year ago, when I first implemented it, it seemed to work well. Few months ago, however, for no apparent reason it stopped updating the app. The message that there's new release pops up but when I tap update either nothing happens, or downloading progress bar shows up but it's unable to start. It'll loop all the time indicating that it's trying to set a connection or something, but it won't get any further no matter how long you'd leave it.. Tested on few phones on Android 7.0 and few on Android 9.0. App center updated to latest version, application is enabled to install unkown apps. I even turned Play Protect off, still nothing.

What are your experiences with App Center distribute modul? Did anyone manage to get it to work reliably?

How to get InstallationId with Azure Notification Hub ?

Essentials Web Authenticator does not provide PKCE support

$
0
0

Since it is the recommended flow to support mobile clients using OpenID Connect it seems surprising that Web Authenticator does not appear to support PKCE.
I have seen David Britch's post where he combines Web Authenticator with IdentityModel.OidcClient however that has a bit of a problem on iOS when the Authority supports shared cookies and thus pops the iOS Sign In permission. Declining that causes an NSErrorException to be thrown in WebAuthenticator. Also, this OidcClient tends to be quite slow, presumably because it's parsing the discovery document.
Does anyone know if it is planned to support more complex flows using WebAuthenticator?

Custom search-list using Linq freezes.

$
0
0

Hi everybody.

I'm building a search - function in Xamarin (see code below):
I'm filling a Listview with data ( public async void FillSearchList()).
When the user writes in the entry, the datalines,
which content corresponds to the search-text,
are shown in the listview (through private void SearchList_OnTextChanged(object sender, TextChangedEventArgs e)).
The user picks a data-line ((private void SearchList_OnTextChanged(object sender, TextChangedEventArgs e))),
and this is being shown in the entry.
The problem is as follows:
First time the user picks a data-line, there are no problems. However, when picking a dataline for the second time,
the program freezes, Visual Studio 2019 freezes, and after a while the message below (in the picture) appears.

I searched for the error for a long time, but sadly -> no luck. In VS 2019 I tried to "Empty symbol cache" and chose "Microsoft Symbol Servers"
under Debug->Options->Debugging->Symbols (picture 2 below). It did not help.

Does anybody have an idea, how to fix this?
Friendly regards
nbs

Xaml-design:

.cs - code -file:

`using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace test_multi.FrameWork.CustomControls
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ListViewSearching : ContentView
{
ObservableCollection<KeyValuePair<string, string>> SearchDataList;
private DataManipulator dsg;
private AlertManager alert;
private string SqlFunction;
private string callMethod;
private string callObject;
public ListViewSearching()
{
InitializeComponent();
dsg = new DataManipulator();
}

    public ListViewSearching(String sqlFunction = "", string EntrySearchPlaceholder = "", string callingObject="", string callingMethod = "")
    {
        callMethod = callingMethod;
        callObject = callingObject;
        InitializeComponent();
         dsg = new DataManipulator();
        SqlFunction = sqlFunction;
        EntrySearch.Placeholder = EntrySearchPlaceholder;
        SearchDataList = new ObservableCollection<KeyValuePair<string, string>>();
        FillSearchList();
    }

    public async void FillSearchList()
    {
        try
        {
            SearchListValues poa = new SearchListValues();
            IDictionary<string, string> dict = new Dictionary<string, string>
            {
                { "COMPANY", Globals.Company }
            };
            var dataObjects = await dsg.GetDataAsync(SqlFunction, poa, dict, false);
            int count = 0;
            if (!dsg.IsNullOrEmpty(dataObjects))
            {
                // All sql-functions shall return 2 variables: ID and NAME
                foreach (SearchListValues searchVal in dataObjects)
                {
                    count++;
                    SearchDataList.Add(new KeyValuePair<string, string>(searchVal.ID, " " + searchVal.NAME));
                }
            }
        }
        catch (Exception ex)
        {
            alert = new AlertManager(Globals.ErrorOccured + Environment.NewLine + ex.Message.ToString(), Globals.AlertInfo);
        }
    }


    private void SearchList_OnTextChanged(object sender, TextChangedEventArgs e)
    {
        ListViewSearch.IsVisible = true;
        ListViewSearch.BeginRefresh();
        try
        {
            var dataSource = SearchDataList.Where(i => i.Key.ToLower().Contains(e.NewTextValue.ToLower()));
            if (string.IsNullOrWhiteSpace(e.NewTextValue))
                ListViewSearch.IsVisible = false;
            else if (dataSource.Any(s => string.IsNullOrEmpty(s.Key)))
                ListViewSearch.IsVisible = false;
            else
                ListViewSearch.ItemsSource = dataSource;
        }
        catch (Exception ex)
        {
            ListViewSearch.IsVisible = false;
        }
        ListViewSearch.EndRefresh();
        if (EntrySearch.Text.Trim().Equals(""))
            Globals._ValueChosen = "";
    }

    private void ListViewSearch_OnItemTapped(Object sender, ItemTappedEventArgs e)
    {       
        Globals.ChosenValues = (KeyValuePair<string, string>)e.Item;
        String listsd = Globals.ChosenValues.Key + " " + Globals.ChosenValues.Value;
        EntrySearch.Text = listsd;
        ListViewSearch.IsVisible = false;
        ((ListView)sender).SelectedItem = null;
    }

}

}`


How can I use both FFImageLoading and SDWebImage in a Xamarin.iOS project without the linker breakin

$
0
0

I'm trying to bring some Native Forms pages to an existing Xamarin.iOS application so that those pages can be shared between several platforms. I would like to use Xamarin.FFImageLoading for images on those Native Forms pages. That much is easy and I have done before without issue. The difficulty comes because this particular Xamarin.iOS application already uses Xamarin.SDWebImage for similar image functionality. When those two Nuget packages are brought in and referenced, the linker begins to choke with numerous reports of "Duplicate symbol". I believe (but I'm not sure) the cause is related to WebP and what I believe to be its bindings which the two packages use (from different sources) which are colliding. So maybe more generally the question is, what can I do when two distinct native libraries happen to define the same symbols? (if that is the problem here)

This particular error message is described here: https://docs.microsoft.com/en-us/xamarin/ios/troubleshooting/mtouch-errors#mt5212-native-linking-failed-duplicate-symbol- and I believe I'm encountering "Two distinct native libraries happen to define the same symbols." specifically, but that page doesn't mention at all what to do about that specific cause.

I've tried adding mtouch arguments that I thought would help, such as "--registrar:static" and "-gcc_flags -dead_strip" and I also played around with adding "[assembly: LinkWith (..., SmartLink = true)]" statements in the assemblyinfo.cs. Those haven't helped though and I'm beginning to think both the packages are hard forcing in their bindings/symbols in ways I can't adjust after the fact. I'm not sure if that's true though and I'm not sure how to tell.

I have an extremely simple project which recreates the problem right here but I'm not sure how to share it. However, it can be very easily recreated by just making a brand new Xamarin.iOS project and bringing in the two packages, and then calling out to them both with some garbage method call in AppDelegate.cs (just to make sure neither are completely stripped out during linking), for example:

new FFImageLoading.ImageService();
new SDWebImage.FLAnimatedImageView();

I expect the project to build, but the project does not build, instead spitting out numerous errors of this sort:

Native linking failed, duplicate symbol: '_WebPAllocateDecBuffer'.
Duplicate symbol in: /.../liblibwebp.a(buffer_dec.o) (Location related to previous error)
Duplicate symbol in: /.../WebP.a(libwebpdspdecode_neon_la-alpha_processing_neon.o) (Location related to previous error)

So what is breaking here? Is it "Two distinct native libraries happen to define the same symbols." as I suspect or is it something else? What can I do about it?

The two packages in question:

https://github.com/luberda-molinet/FFImageLoading

https://github.com/xamarin/XamarinComponents/tree/master/iOS/SDWebImage

xamarin build error

$
0
0

I have open 2017 project from 2019. Now i am getting this error. my Xamarin.Android.Support.Core.Utils version is 27.0.2 and Xamarin.Android.Support.v4 is 23.4.0.1

The type 'FileProvider' exists in both 'Xamarin.Android.Support.Core.Utils, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' and 'Xamarin.Android.Support.v4, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'

How to import Adobe XD design on Xamarin Android

$
0
0
Hi, everyone ! I'am sorry, on Android studio we can import designs from adobe xd, is it possible to do it on xamarin android? thanks

How to import Adobe XD design on Xamarin Android

$
0
0
Hi, everyone ! I'am sorry, on Android studio we can import designs from adobe xd, is it possible to do it on xamarin android? thanks

EBADF (Bad file descriptor) with Andoid 10 target with PackageInstaller API

$
0
0

Before I updated to visual studio 19 and Android 10 (Q), I successfully installed third party apps with my app with the following code.

PackageInstaller installer = activity.PackageManager.PackageInstaller;
PackageInstaller.SessionParams sessionParams = new PackageInstaller.SessionParams(PackageInstallMode.FullInstall);
int sessionId = installer.CreateSession(sessionParams);
PackageInstaller.Session session = installer.OpenSession(sessionId);

var input = new FileStream(pfad, FileMode.Open, FileAccess.Read);
var packageInSession = session.OpenWrite("package", 0, -1);
input.CopyTo(packageInSession);
packageInSession.Close();
input.Close();
packageInSession.Dispose();
input.Dispose();

//That this is necessary could be a Xamarin bug.
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();

Intent intent = new Intent(activity, activity.Class);
intent.SetAction("com.example.android.apis.content.SESSION_API_PACKAGE_INSTALLED");
PendingIntent pendingIntent = PendingIntent.GetActivity(activity, 0, intent, 0);
IntentSender statusReceiver = pendingIntent.IntentSender;

// Commit the session (this will start the installation workflow).
session.Commit(statusReceiver);

When i Dispose() the streams, i get an IOException: write failed (EBADF) bad file descriptor which would indicate a bad APK.

But this is unlikely because the code in visual studio 2017 works with the Android 9 target.

Hope somebody can help me and thank you in advance!

Viewing all 204402 articles
Browse latest View live


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