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

Issue with Plugin.BLE do not scan devices

$
0
0

Hi!

I'm facing a issue trying to connect to a Bluetooth LE device.

I downloaded the Plugin.BLE and I used the sample included without any problem, I connect and read/write data.

Now, I try to deploy on my App, I follow the instructions on the github repository, add permissions to AndroidManifest.xml. , but when I execute adapter.StartScanningForDevicesAsync(), nothing happens, I don't get the list of devices. There are several devices all around and also the one I want to connect to.

This is my code

public partial class PageSettingsDevice : ContentPage
{
IBluetoothLE ble;
IAdapter adapter;
ObservableCollection deviceList;
IDevice device;
private CancellationTokenSource _cancellationTokenSource;

    public PageSettingsDevice()
    {
        InitializeComponent();

        ble = CrossBluetoothLE.Current;
        adapter = CrossBluetoothLE.Current.Adapter;
        deviceList = new ObservableCollection<IDevice>();

        //adapter.DeviceDiscovered += _bleAdapterDeviceDiscovered;
    }

    private bool status()
    {
        var state = ble.State;

        DisplayAlert("Notice", state.ToString(), "OK !");
        if (state == BluetoothState.Off)
        {
            DisplayAlert("Atención", "Your Bluetooth is off ! Turn it on !", "Aceptar");
        }

        if (ble.State == BluetoothState.Off || ble.State == BluetoothState.TurningOff || ble.State == BluetoothState.Unauthorized || ble.State == BluetoothState.Unknown)
            return false;
        else
            return true;
    }

    async void OnDiscoverDeviceBlueToothClicked(object sender, EventArgs e)
    {
        try
        {
            if (status())
            {
                adapter.DeviceDiscovered += (s, a) =>
                {
                    if (device.Name.Contains("Coltech"))
                            adapter.ConnectToDeviceAsync(device);
                };

                //We have to test if the device is scanning 
                if (!ble.Adapter.IsScanning)
                {
                    _cancellationTokenSource = new CancellationTokenSource();

                    adapter.ScanMode = ScanMode.LowLatency;
                    await adapter.StartScanningForDevicesAsync(null,null,false,_cancellationTokenSource.Token);

                    var list = adapter.ConnectedDevices;
                }
            }                
        }
        catch (Exception ex)
        {
            DisplayAlert("Notice", ex.Message.ToString(), "Error !");
        }
    }

    async void _bleAdapterDeviceDiscovered(object sender, DeviceEventArgs e)
    {
        if (device != null)
        {
            if (device.Name.Contains("Coltech"))
                await adapter.ConnectToDeviceAsync(device);
        }
    }
}

Any help is wellcomed, thanks


Get file path from content.

$
0
0

Hi everyone,

I have a Xamarin.Forms (iOS, Android) app and I open it as option to Open PDF documents. For Android app, I set an intent-filter with mimetype: pdf.

  <intent-filter>
          <action android:name="android.intent.action.VIEW" />
          <category android:name="android.intent.category.DEFAULT" />
          <data android:mimeType="application/pdf" />
        </intent-filter>

Is there any way to do the same thing on iOS?

And I have another problem. After I open my app, I want to retrieve the file's path from intent, but I get something like that:
content://com.android.providers.downloads.documents/document/22

Is there any way to get the file path from that content?

Thank you.

Encode array\list of images to video MP4 in xamarin

$
0
0

I'm building an app that encodes a stream of images or an array of images into MP4 video in Xamarin forms. I couldn't find anything that works with xamarin forms and I've already tried these:

1. FFmpeg - (not working in xamarin native, require .netCore (I'm getting errors when installing any related NuGet package)
2. libvlc - I don't think it has any converting or encoding capabilities.
3. searched in google, here and xamarin forum for a solution.
4. skiasharp - apparently use only for drawing 2D and not for video encoding.
5. Nreco - needs licence.
6. AviSharp/Aforge/Mediacodec/etc - Just for iOS\Android
7. Encode MP4 from scrach - noticed that's too much work.

is there any way to do it without encoding the video on each platform-specific?

Thanks in advance!

I want to use "ConsumerIrService" in Xamarin.Forms

$
0
0

mCIR = (ConsumerIrManager)GetSystemService(Context.ConsumerIrService);

I have been using this in Xamarin.Android but recently I needed to use this in Xamarin.Forms but it is throwing this error "Error CS0103 The name 'GetSystemService' does not exist in the current context"

Just found out that if "GetSystemService" is called in MainActivity then it works but if it is called in any other class then it throws error as mentioned above.

Can someone please guide me what am I missing here?

Thanks in advance.

Using Xam.Plugins.Notifier, can we get list of pending notifications?

$
0
0

@JamesMontemagno mentions that when an Android phone is rebooted, the pending notifications will not be sent and they have to be resent. Does it mean the pending notifications will be cleared from App's space?

How to know that the phone was rebooted?

iphone simulator - launch external app to annotate pdf and images

$
0
0

Hi everyone,

I had previously written an application that allows the user to download files which are effectively images and pdf's that require annotation before sending back to the server, this was done for UWP and Android but has now been requested for iOS. In the absence of owning a Mac I have decided to use macincloud and this environments seems really good for the login and navigation for the app but I have some questions regarding working with files in external applications.

I hadn't previously looked at a cross platform way to work with files, for Android I used an intent and activity, for UWP I used Windows.System.Launcher. With iOS for now I was trying to use Launcher from Xamarin.Essentials and the following code:

await Launcher.OpenAsync(new OpenFileRequest
{
File = new ReadOnlyFile(filePath)
});

Now on the simulator at least I am being offered Reminders, Photos and More as options and on Photos it does not open it but instead wants to create an iCloud album, I would expect to be shown a list of programs from which to work with the file . I do not own an iPhone and I am not sure if I should be using a different implementation or if this is a limitation of the simulator and on a real device it would work better, I am guessing I cannot install 3rd party apps on a simulator. it may also be worth mentioning that for UWP and Android I store these files in Environment.SpecialFolder.LocalApplicationData but after reading about sandboxing within iOS I believe it is more correct to store files in Environment.SpecialFolder.MyDocuments and set LSSupportsOpeningDocumentsInPlace within info.plist.

I hope that this is sufficient detail of what has been done so far and would really appreciate some knowledge from any of you that have had to achieve similar things. If it is the case that what i have done is correct and I need to test this on a real device, can I do this by plugging an iPad into my windows machine running VS2019 and having macincloud running for buliding?

Multiple Image Picker in Xamarin.Forms

$
0
0

Hi everyone, I'm new to this forum and I'm kinda new also with xamarin (just 2 months).
I'm developing an app that allows users to choose a product and apply some customizations to it like adding an image, move that image within the frame and so on...
I'm stuck with the part of the multipicker from the gallery.
I've tried many solutions suggested by many developers but all of them didn't seem to work for me: they actually do open the gallery and let user pick an image but I need to select more than one at a time!
I've tried both implementing code in my project and then downloading the sample from github of those projects and install it on my phone (Android 8.0) and even on an emulator (Android 4.0).
None of this worked for me.
I need a solution that works both for android and for iOs and I'm afraid that doesn't actually exists.
If you want to know more about what I've already tried just ask, moreover is really xamarin worth it for app development? Would you reccomend it or is it better going for Java/Kotlin & C++/Swift/XCode?
Sorry if I mispelled something, english isn't my primary language.

Convert GoogleMap Snapshot Java solution to Xamarin C#


Style not honoring value set by StaticResource in Resources?

$
0
0

Hello Everyone,

I have set certain values to a property (IconWidth) in the Resources of a content view. This property is being used in a Style also contained in the same place.
However, when this is used in the style, the Image view seems to ignore this.
For example -
This doesn't work

    <OnPlatform x:TypeArguments="x:Int32" Android="32" iOS="32" Default="32" x:Key="IconWidthVertical"/>

    <Style TargetType="Image" x:Key="statusIconStyles">
    <Setter Property="WidthRequest" Value="{StaticResource Key=IconWidthVertical}" />
    <Setter Property="Aspect" Value="AspectFit"/>
    </Style>

However, this does -

    <Style TargetType="Image" x:Key="statusIconStyles">
        <Setter Property="WidthRequest" Value="32" />
        <Setter Property="Aspect" Value="AspectFit"/>
    </Style>

What am I doing wrong here? Why dosen't the StaticResource binding work?

Remove Hamburger Menu icon (UWP)

$
0
0

Hi,
I'm using a master detail page to display a hamburger menu for my 3 apps (Android, iOS and UWP).
In the Android and iOS apps, every time I navigate into a detail page, I get a back button where the hamburger icon was previously placed, but in UWP this back button is displayed in the top of the hamburger icon (I can see both of them at the same time).

I just want to let the navigation using the hamburger menu from the home page.
So is there any way of disabling the hamburger menu or hiding the icon whenever I'm not in my homepage?

Thanks in advance

AdMob and mediation

$
0
0
AdMob works fine in my Xamarin.Forms App, but I have a ecpm just something around 1€, so I wanted to use mediation throu AdMob to increase the ecpm.
Is it right that I need for each advertiser a seperate sdk? Is there a list with sdks for xamarin, because the most I found dont work with xamarin.
I've tried to work with facebook audience, but I have issues with the aar binding. I get a lot of binding errors when I try to build the aar-binding dll...
So please boys and girls, help me :)

Extended DatePicker? How to disable certains days from DatePicker?

$
0
0

Hello there, I'm trying to disable certain days, like weekends, from a datepicker, but it seems I can only set min and max selectable dates. Is there anyway to achieve that? or is there any compatible XForms Nuget Package that allows me to do it?

Android Emulator not consuming API and giving error System.Net.WebException: 'Failed to connect to

$
0
0

l have an api backend in a .net core web app and have written the code to consume the api in xamarin.forms. when l run the code
l get the following error.

System.Net.WebException: 'Failed to connect to /127.0.0.1:44360'.

Below is my code in xamarin.forms

public MainPage()
{
InitializeComponent();
Comic();
}

    public async void Comic()
    {
        using(var httpClient = new HttpClient()){
            var response = await httpClient.GetStringAsync("https://127.0.0.1:44360/api/comic");
            var comic = JsonConvert.DeserializeObject<List<Comic>>(response);
            comicList.ItemsSource = comic;
        }
    }

A bit of research says something about configuring the web app to use 127.0.0.1 instead of localhost and it been
specific to android.what can l do to fix this error.

How to add rectangle in xamarin forms?

$
0
0

Hi, I need to add a rectangle box and i want to place my text in the center .Please guide

Detecting KeyDown in an entry?

$
0
0

Hi,

I'd like to detect when the backspace keyboard button is pressed in an Entry even when there is no text in the entry. I've tried creating a custom renderer and overriding OnKeyDown but it doesn't seem to do anything. In my custom android renderer that extends Entry:

public override bool OnKeyDown(Keycode keyCode, KeyEvent e)
{
    Console.WriteLine("A key was pressed");
    if (keyCode == Keycode.Del)
    {
        // do stuff here
    }
    return base.OnKeyDown(keyCode, e);
}

Unfortunately this doesn't seem to do anything. How can I achieve this?


ImageSource not works with Android mipmap folders

$
0
0

Recently i migrated an Android project, I'm using version 4.3.0.908675 of Xamarin.Forms.

I added all the images in Android mipmap folders that were previously drawable, but now my image does not load, when debugging everything seems to be right but when displaying the screen no images appear.

My code to add image source

    stlLogo = new StackLayout
    {
        VerticalOptions = LayoutOptions.CenterAndExpand,
        HorizontalOptions = LayoutOptions.FillAndExpand,
        Padding = new Thickness(20, 0, 20, 40)
    };

    imgLogo = new Image
    {
        Source = ImageSource.FromFile("ig_splash_logo")
    };

UltimateXF pieChart legend click

$
0
0

Hi all, I am using UltimateXF in xamarin.forms for creating PieChart but not able to get click event on piechart 's segment. Can anyone help

Xamarin forms Android, background bluetooth connection

$
0
0

Hello guys,

My app requires to connec to known Ble device at the start of the application, and keep the connection for a long periods of time even when the screen is locked.

Therefore I need to keep connection in the background task/service.

For now I ve been using https://github.com/xabre/xamarin-bluetooth-le for all the bluetooth interactions.

Seems like I need to implement Long running task in platform specific code.

Have anybody implemented this plugin to work as background services without bugs or do you have any resources that could help me?

How to implement app linking so the WebView can handle the links?

$
0
0

Hi,
I'm working on this application where I need to implement applinking. For the app linking stuff, it's already done and I'm able to start the application from a simple link on an Android device. Now on the Forms project, which basically only consists of a simple webview, I'd like to pass the Url with the method protected override void OnAppLinkRequestReceived(Uri uri) from the App.xaml.cs file to the MainPage.xaml.cs file. Which I'm unable to do right now, I can't figure out how to do this. One thing I need to do for sure is executing code on the main thread.

Edit : I need to create a method in the Main Page that I can call async in the override method but for some reason I can't seam to do that..

Xamarin Forms Maps - Android

Viewing all 91519 articles
Browse latest View live


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