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

Xamarin Forms: Grid button UI breaks when click restart button

$
0
0

I am using a button inside the grid for showing letters to implement a Word search game. Initially, the UI is looking good, but when clicks the play again button the UI breaks.

Screenshot:

enter image description here

Code for the setting button inside grid:

void SetGridLayout(char[,] matrixToPrint)
{
    int numRows = matrixToPrint.GetLength(0);
    int numCols = matrixToPrint.GetLength(1);

    gridLayout.HorizontalOptions = LayoutOptions.FillAndExpand;
    gridLayout.SetBinding(Button.HeightRequestProperty, new Binding("Width", source: gridLayout));

    for (int row = 0; row < numRows; row++)
    {
        gridLayout.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
    }
    for (int col = 0; col < numCols; col++)
    {
        gridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
    }

    for (int rowIndex = 0; rowIndex < numRows; rowIndex++)
    {
        for (int columnIndex = 0; columnIndex < numCols; columnIndex++)
        {
            var Rowbutton = new Button
            {
                Text = Char.ToString(matrixToPrint[rowIndex, columnIndex]),
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Padding = 0,
                Margin = 0,
                BackgroundColor = Color.White
            };
            Rowbutton.SetBinding(Button.CommandProperty, "ClickCommand");
            Rowbutton.SetValue(Button.CommandParameterProperty, new PassObject(Rowbutton, rowIndex.ToString() + "," + columnIndex.ToString()));
            Rowbutton.SetBinding(Button.HeightRequestProperty, new Binding("Width", source: Rowbutton));
            gridLayout.Children.Add(Rowbutton, columnIndex, rowIndex);
        }
    }
}

I tried a lot to find the cause behind this issue, but no luck. I have uploaded a sample project here for the reference. Thanks in advance.


Cannot connect to any BLE device on Android

$
0
0

Hi,

I tried to connect with Bluetooth device and I am able to connect the device and detect services by uuid. But problem starts when I try to get any characteristic from the service. Currently I am doing:

                if (peripheral.IsDisconnected())
                {
                    device = await peripheral.ConnectWait(); //1
                }

                var state = peripheral.IsConnected(); // 2
                var serviceId = Guid.Parse("0000180A-0000-1000-8000-00805F9B34FB");
                var manufacturerName = Guid.Parse("00002A29-0000-1000-8000-00805F9B34FB");

                var service = await device.GetKnownService(serviceId);
                var characteristic = await service.GetKnownCharacteristics(new Guid[] { manufacturerName });

                if (characteristic.CanRead())
                {
                    var data = await characteristic.Read(); // 3 
                    var value = Encoding.UTF8.GetString(data.Data);
                }

Brief info:
//1 - state is true on UWP, and on Android it freezes...
//2 - UWP is reporting true here
//3 - data is OK here on UWP

What need to be done to make Android to work? I am also running this code on main thread, and nothing is changing. Trying follow any guidelines but without success. Like I mentioned in point 1, app freezes and no timeout occures, no exception is being thrown, not a single line of info in debug window in VisualStudio.

The code that I posted above works fine on UWP platform but does not work on Android... I am using Shiny.BluetoothLE library to connect. I used also previous library from Allan Ritchie but with same result here. Other libraries works in the same manner.

facebook adnetworks ad not visible

$
0
0

This is my code for show facebook banner ad. My ad is not visible.

FacebookAdsControl.cs

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using Xamarin.Forms;

namespace App
{
    public class FacebookAdsControl : ContentView
    {
        public static BindableProperty PlacementIdProperty = BindableProperty.Create(nameof(PlacementId), typeof(string),
            typeof(FacebookAdsControl), null);
        public string PlacementId
        {
            get { return (string)GetValue(PlacementIdProperty); }
            set { SetValue(PlacementIdProperty, value); }
        }
    public static BindableProperty SizeProperty = BindableProperty.Create(nameof(Size), typeof(FacebookAdSize),
        typeof(FacebookAdsControl), FacebookAdSize.BannerHeight50);


    public FacebookAdSize Size
    {
        get { return (FacebookAdSize)GetValue(SizeProperty); }
        set { SetValue(SizeProperty, value); }
    }

    public event EventHandler Loaded;
    public event EventHandler Click;
    public event EventHandler<ErrorEventArgs> Error;
    public event EventHandler Impression;

    public virtual void OnLoaded()
    {
        Loaded?.Invoke(this, EventArgs.Empty);
        Debug.WriteLine("FACEBOOK ADS LOADED");
    }

    public virtual void OnClick()
    {
        Click?.Invoke(this, EventArgs.Empty);
        Debug.WriteLine("FACEBOOK ADS CLICKED");
    }

    public virtual void OnImpression()
    {
        Impression?.Invoke(this, EventArgs.Empty);
        Debug.WriteLine("FACEBOOK ADS Impression");
    }

    public void OnError(int errorCode, string errorMessage)
    {
        Error?.Invoke(this, new ErrorEventArgs(errorCode, errorMessage));
        Debug.WriteLine("FACEBOOK ADS ERROR: " + errorMessage);
        //Settings.FbAdsError = errorMessage;
        //Debug.WriteLine("Settings.FbAdsError: " + Settings.FbAdsError);
    }

    public enum FacebookAdSize
    {
        Banner32050,
        BannerHeight50,
        BannerHeight90,
        Interstitial,
        RectangleHeight250
    }

    public class ErrorEventArgs : EventArgs
    {
        public ErrorEventArgs(int errorCode, string errorMessage)
        {
            ErrorCode = errorCode;
            ErrorMessage = errorMessage;
        }

        public int ErrorCode { get; }
        public string ErrorMessage { get; }

    }
}}

Mainpage.cs

   public MainSwitchboard()
        {
            InitializeComponent();
            AddFacebookAdsControl();
        }

       private void AddFacebookAdsControl()
        {
            FacebookAdsControl myads = new FacebookAdsControl();
            myads.HeightRequest = 50;

            myads.PlacementId = "714857585700004_714858832400006"; //We create this on developer facebook website

            myads.Size = FacebookAdsControl.FacebookAdSize.Banner32050;

            myads.VerticalOptions = LayoutOptions.EndAndExpand;
            StackLayoutAds.Children.Add(myads);

        }

Mainpage.xaml


FacebookAdsRenderer.cs

using Xamarin.Facebook.Ads;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using App.Droid;
using View = Xamarin.Forms.View; 

[assembly: ExportRenderer(typeof(FacebookAdsControl), typeof(FacebookAdsRenderer))]
namespace App.Droid
{
    public class FacebookAdsRenderer : ViewRenderer
    {
        protected FacebookAdsControl AdViewControl => (FacebookAdsControl)Element;
        protected override void OnElementChanged(ElementChangedEventArgs<View> e)
        {
            base.OnElementChanged(e);
            if (e.OldElement != null || Element == null)
                return;

```

        SetNativeControl();
    }

    private void SetNativeControl()
    {
        AdView adView = new AdView(Context, AdViewControl.PlacementId, GetAdSize(AdViewControl.Size))
        {
            LayoutParameters = new LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent)
        };



        adView.LoadAd();
        adView.Click += (sender, args) => AdViewControl.OnClick();
        adView.AdLoaded += (sender, args) => AdViewControl.OnLoaded();
        adView.LoggingImpression += (sender, args) => AdViewControl.OnImpression();
        adView.Error += (sender, args) => AdViewControl.OnError(args.P1.ErrorCode, args.P1.ErrorMessage);

        SetNativeControl(adView);
    }

    private AdSize GetAdSize(FacebookAdsControl.FacebookAdSize size)
    {
        switch (size)
        {
            case FacebookAdsControl.FacebookAdSize.Banner32050:
                return AdSize.Banner32050;
            case FacebookAdsControl.FacebookAdSize.BannerHeight50:
                return AdSize.BannerHeight50;
            case FacebookAdsControl.FacebookAdSize.BannerHeight90:
                return AdSize.BannerHeight90;
            case FacebookAdsControl.FacebookAdSize.Interstitial:
                return AdSize.Interstitial;
        }
        return AdSize.RectangleHeight250;
    }
}

}

Other barcode scanner packages out there besides ZXing?

$
0
0

Are there any good bar code scanning libraries out there for Xamarin.Forms?
I know there is the ZXing library at: https://github.com/Redth/ZXing.Net.Mobile
But this library doesn't seem to be maintained any longer and its really out of date. I hade to duct tape it together to work.

Are there any barcode scanning libraries out there that people would recommend? I would even consider good commercial libraries.
I also heard a rumor that Xamarin.Forms might have barcode scanning built into it one day?

AutoSize Label with a Formatted Text not working on Android

$
0
0

I am trying to implement autofit functionality to the label, i.e. reduce the font size of the label to fit in the same line. Tried using effects and custom renderers as well. Works fine on iOS but not on Android because i am using Formatted text property in the Label.

I have posted detailed information on this issue here - https://stackoverflow.com/questions/64120955/autosize-label-with-a-formatted-text-not-working-on-android

Also, is it possible to change the font family of a specific word in a Label without using formatted text? because eliminating the use of formatted text could resolve the issue with autofit renderer/effect.

Any suggestions would be of great help. Thank you in advance.

Image in stacklayout behaves different on Android than iOS

$
0
0

Hi,

I have a view hierarchy that looks like this: ContentView -> Frame -> StackLayout ->{ Image, Entry }
The Entry has the following properties set:

Entry = new Entry
{
    HorizontalTextAlignment = TextAlignment.Center,
    VerticalTextAlignment = TextAlignment.Center,
    VerticalOptions = LayoutOptions.End,
}

The Image looks like this:

Image = new Image
{
    HorizontalOptions = LayoutOptions.FillAndExpand,
    VerticalOptions = LayoutOptions.FillAndExpand
};

The Stacklayout has no properties set to anything other than default.
The Frame looks like this:

Frame = new Frame
{
    CornerRadius = 5,
    HasShadow = false,
    Padding = 0,
    Margin = 0,
    BackgroundColor = Color.White,
};

The ContentView has the following layoutProperties set:

    HeightRequest = 140;
    WidthRequest = 120;
    HorizontalOptions = LayoutOptions.Fill;
    VerticalOptions = LayoutOptions.Fill;

What I want to achieve is to have an image that fills the available space above the entry.
On iOS this works as expected. On Android however, if the image is too big, it pushes the entry outside of the stacklayout and frame so that it is not visible.
How can I get the same layout behavior on both platforms? What am I missing?

Thanks!

Cannot create a user control with two way binding to view model property names

$
0
0

My objective is to create a user control containing a basic Entry control that will update a specified property in my view model.
I have been unable to bind the user control to the property name in my view model unless the view model property name is exactly the same as the property in the user control. This defeats the purpose of a reusable two way reusable control.
I suspect I'm just missing a key concept.

My expectation is that I should be able to add one or more of my UserEditors to a page and bind it to various string properties in the view model, and the property the UserEditor gets/sets should be the property I specify in the {Binding } for the UserEditor.

I have created a simple PCL project to test with. I would be very grateful if someone can get me on the correct track with this. I have exhausted all other resources to come to grips with this. I can provide a zip file of the VS2015 solution, however its pretty big (65MB) with all the XAM stuff.

Here are all the pieces:
UserEditor.xaml:

    <?xml version="1.0" encoding="UTF-8"?>
    <ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
                 x:Class="UserControl.UserEditor">
      <ContentView.Content>
            <StackLayout Orientation="Vertical" Margin="0,0,0,10" >
                <Entry x:Name="TextEntry" 
                       Text="{Binding Text}"
                       HorizontalOptions="Fill"/>
            </StackLayout>
        </ContentView.Content>
    </ContentView>

UserEditor.xaml.cs

    using System;
    using System.Linq;

    using Xamarin.Forms;

    namespace UserControl
    {
        public partial class UserEditor : ContentView
        {
            //Bindable property for Text
            public static readonly BindableProperty TextProperty =
                BindableProperty.Create("Text",
                    typeof(string),
                    typeof(UserEditor),
                    string.Empty,
                    BindingMode.TwoWay,
                    null,
                    OnTextPropertyChanged,
                    null,
                    null,
                    null);

            public static void OnTextPropertyChanged(BindableObject bindable, object oldValue, object newValue)
            {
                var control = bindable as UserEditor;
                if (control == null) return;
                control.TextEntry.Text = newValue.ToString();
            }

            public UserEditor()
            {
                InitializeComponent();
            }

            public string Text
            {
                get
                {
                    return (string)GetValue(TextProperty);
                }
                set
                {
                    SetValue(TextProperty, value);
                }
            }
        }
    }

MainPageViewModel.cs

using System;
using System.ComponentModel;
using System.Linq;

namespace UserControl
{
    class MainPageViewModel : INotifyPropertyChanged

    {
        public event PropertyChangedEventHandler PropertyChanged;

        public MainPageViewModel()
        {

        }

        protected void OnPropertyChanged(string name)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
        }

        string textProperyInVM = "Initial value";
        public string TextPropertyInVm
        {
            get
            {
                return textProperyInVM;
            }
            set
            {
                textProperyInVM = value;
                OnPropertyChanged("TextPropertyInVm");

            }
        }
    }
}

MainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:UserControl"
             x:Class="UserControl.MainPage">

    <!--//Page binding context is set to the view model in the page contructor.-->
    <StackLayout Orientation="Vertical">
    <Label Text="Binding viewmodel properties to user control"  />
        <!--//Label is bound to ViewModel field named TextPropertyInVm-->
        <Label Text="{Binding TextPropertyInVm}" ></Label>

        <!--//UserEditor custom control is bound to ViewModel field named TextPropertyInVm
        //User editor will not see the view model property.
        //User editor ALWAYS wants to work with a property named "Text"
        //User editor neither reads nor updates the view model property specified in the Binding -->
        <!--
        Text changes in the user control cause this error:
        [0:] Binding: 'Text' property not found on 'UserControl.MainPageViewModel', target property: 'Xamarin.Forms.Entry.Text'
        -->
        <local:UserEditor Text="{Binding TextPropertyInVM, Mode=TwoWay}"></local:UserEditor>
    </StackLayout>
</ContentPage>

MainPage.xaml.cs

using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace UserControl
{
    public partial class MainPage : ContentPage
    {
        private MainPageViewModel vm;
        public MainPage()
        {
            InitializeComponent();
            //instantiate and bind this page to a new view model.
            vm = new MainPageViewModel();
            this.BindingContext = vm;
        }
    }
}

Xamarin.Form.Maps is not compatible when Android is targeting version 10

$
0
0

When you try to target Android 10 and also try to use Nuget to get the Xamarin.Forms.Maps package you will get these errors:

Severity Code Description Project File Line Suppression State
Error Package restore failed. Rolling back package changes for 'Test.Android'.
Error NU1107 Version conflict detected for Xamarin.Android.Support.Collections. Install/reference Xamarin.Android.Support.Collections 28.0.0.3 directly to project Test.Android to resolve this issue.
Test.Android -> Xamarin.Forms.Maps 4.8.0.1451 -> Xamarin.Android.Support.v4 28.0.0.3 -> Xamarin.Android.Support.Media.Compat 28.0.0.3 -> Xamarin.Android.Support.VersionedParcelable 28.0.0.3 -> Xamarin.Android.Support.Collections (= 28.0.0.3)
Test.Android -> Xamarin.Auth 1.7.0 -> Xamarin.Android.Support.CustomTabs 28.0.0.1 -> Xamarin.Android.Support.Collections (= 28.0.0.1). Test.Android D:\temp6\test\Test.Android\Test.Android.csproj 1

Anyone know how to get around this? Or if it is being fixed?
Perhaps I should use the Google maps nuget package?


static proterty / OnPropertyChanged / binding context

$
0
0

Hello,
this is just an example to simplify what my app should do

I have a Data class which contains different instances which must be accessible via binding on the different views

    public class Data
    {
        private Order _order_obj;
        public Order Order_obj
        {
            set
            {
                _order_obj= value;
                OnPropertyChanged();
            }
            get => _order_obj;
        }

        private User _user_obj;
        public User User_obj
        {
            set
            {
                _user_obj = value;
                OnPropertyChanged();
            }
            get => _user_obj;
        }

        private string _connection_st;
        public string Connection_st
        {
            set
            {
                _connection_st = value;
                OnPropertyChanged();
            }
            get => _connection_st;
        }

        public Data()
        {
            User_obj = new User();
            Order_obj = new Order();
            Connection_st = "";
        }
        bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
        {
            if (Object.Equals(storage, value))
                return false;

            storage = value;
            OnPropertyChanged(propertyName);
            return true;
        }

        protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
        public event PropertyChangedEventHandler PropertyChanged;

    }

MainPage.xaml.cs

public partial class MainPage : ContentPage
{
        private Data _data_obj;
        public Data Data_obj // not accessible if it's not static
        {
            set
            {
                _data_obj = value;
                OnPropertyChanged(); // don't works if Data_obj is static
            }
            get => _data_obj;
        }

    public MainPage()
    {
        Data_obj = new Data();
        Data_obj.Connection_st = "Hello";
    }
}

MainPage.xaml and OrderPage.xaml

<Label Text="{Binding Data_obj.Connection_st}" />

ConnectionPage.xaml.cs

        // clic on Button "log in"
    private async void ConnectionUser(object sender, EventArgs e)
    {
        // call API connection
        MainPage.Data_obj.User_obj.UpdateInfo(datas);
        MainPage.Data_obj.Connection_st = "Hello " + MainPage.Data_obj.User_obj.FirstName_st;
        await Navigation.PushAsync(new MainPage(), false);
    }

my problems:

  • the refresh for the binding does not work correctly when I modify the properties of Data_obj (example: MainPage.Data_obj.User_obj.Address = newAdress)
  • if the Data_obj property is not static: MainPage.Data_obj is not accessible on ConnectionPage or on other ContentPages.

I have done a lot of research and attempting, but the handling of OnPropertyChanged or an "OnGlobalPropertyChanged" escapes me. I think I'm complicating things ...

do you have a simple idea for this basic management? Thank you very much for your advice.

Shell: Always show the hamburger icon

$
0
0

I would like to always show the hamburger menu icon regardless how I browsed to a specific page. For instance, if I have an event on a button which sends the users to a new page I don't want the back button - I want the hamburger icon. I understand why the backbutton appears (the navigationstack).

I've tried this in the page constructor:
Shell.Current.Navigation.RemovePage(new IntroPage());

That does not work - I'm completely unable to browse to the page if I do that.

Visiting the pages by using the menu works as expected, the problem is that the customer also wants to navigate the app via buttons/images, and the hierarchy is deep, hence having the hamburger visible at all times would be of great benefit for the user.

Is it at all possible with Shell?

How can I get lat long from place id?

$
0
0

"predictions": [
{
"description": "Shwe Phu Myaw Street, Yangon, Myanmar (Burma)",
"place_id": "Ei1TaHdlIFBodSBNeWF3IFN0cmVldCwgWWFuZ29uLCBNeWFubWFyIChCdXJtYSkiLiosChQKEgm9dYxo3-zBMBG33fzZM-fi4RIUChIJaxk-Ip6UwTARtAsI-HHS-1Y"
}
],

I want latitude and longitude from place_id.

Submission of UWP app to Windows Store - error code 1201

$
0
0

Hey guys, first time posting on the forum!

It's been 3 weeks that I am trying to upload my app to the Windows Store with no luck.

My project runs perfectly on "Release Mode" and even if I sideload it.

I am able to submit the .appxbundle (I'm building for ARM, x86 and x64) but after about 5 minutes it's in the certification, I get this error:

"_This submission failed with error code(s) 1201 . More info about the error(s) can be found here."

Of course, if you go to the link there's nothing related to this issue. So I emailed Microsoft Submission team and after multiples emails, they have said:

After reviewing the information with our specialized team, we found per your app manifest, the Mobile phone package/schema was not removed
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest

You must remove coding related to Windows Mobile in Manifest or create a new package with Mobile phone package and resubmit.

I tried removing from the lines from the manifest but I get lots of other .NET errors, so I'm assuming that's not the way to go. Plus, all Xamarin.Forms examples on Github have this. I thought it was a very weird advice.

I asked how I could go about doing this and that was the answer:

Please create a new package without Mobile phone package and resubmit. as we no longer support mobile apps/devices. Your error means you can not remove the mobile phone package, instead you must create a new package.

I must be missing something really obvious but I'm not targeting Windows Phones, but Windows DESKTOP. So on the package submission to Windows store, everything is unchecked except for "Windows Desktop".

Do you guys think this mobile thing is related? Have you guys experienced something similar? I'm frustrated!

Specifics
Xamarin.Forms 4.8.0.1269
.NET Standard 2.0.3
.NETCore.UniversalWindowsPlatform 6.2.10

EDIT

My app has successfully passed on the Local Windows Ceritfication Tool Kit

need to develop kind of master detail page but it should act as a List - Details page in phone

$
0
0

need to develop a kind of master-detail page but it should act as a List - Details page in the phone and master-details aage in Tablet.

How to get the file path of an image and send it to the server?

$
0
0

Hi everyone. Im currently learning Xamarin.Forms and I'm building my first application. Im using Xam.Media.Plugin to select or take a photo and save it to my server and It's working fine. But somehow, my requirements shifted so I looked around for another plugin and I discovered matheusneder/Xamarin.Forms.ImagePicker. This plugin covers all of my image processing requirements aside from it doesnt seem to save the image to the server. My REST API returns null for the image passed.
This is my code in selecting the image:
if (imageSource != null)
{
image.Source = imageSource;
new Alert("File path", imageSource.ToString(), "");
}
and this results to the file path being : /data/user/0/com.mysample.app/cache/cropped7799234235.jpg
In MediaPlugin, the file path result is : /storage/emulated/0/Android/data/com.mysample.app/files/Pictures/temp/IMG_20200915_104932_12.jpg

Im guessing that this somewhat related to file path? Any ideas on how to achieve the latter result?

Persian calendar


Xamarin.Forms: adjust Image size to the width of the parent's in a BindableLayout

$
0
0

I'm trying to adjust the the Image size to the width of the parent's container in a BindableLayout, but I didn't found a way to achieve this.

I'm based on this other topic to achieve this.

I first tried to embed the Image in a Grid container like this:

<StackLayout x:Name="NewsList"
             BindableLayout.ItemsSource="{Binding News}">
    <BindableLayout.ItemTemplate>
        <DataTemplate>
            <Frame>
                <Grid Padding="0" Margin="0"
                      VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"
                      BackgroundColor="Red">
                    <Image Source="{Binding Image}" Aspect="AspectFit"/>
                </Grid>
                <Label Text="Description" />
            </Frame>
        </DataTemplate>
    </BindableLayout>
</StackLayout

=> but we can see that I get red stripes around the images (at the top/bottom, or at the left/right):
ImageInGrid

Then, I've tried to use a CachedImage from FFImageLoading like this:

<Grid Padding="0" Margin="0"
        HorizontalOptions="FillAndExpand"
        VerticalOptions="FillAndExpand"
        BackgroundColor="Orange">
    <ffimageloading:CachedImage Source="{Binding Image}"
                    HorizontalOptions="Fill"
                    VerticalOptions="Fill"
                    Aspect="AspectFill"
                    DownsampleToViewSize="True"/>
</Grid>

=> but in this case, the images are not fully visible, or are truncated
CachedImage

=> So is there another way allowing me to display an image in the full width of the parent's container, and keeping the original ratio?

FCM - My notifications wont show when app is swiped or mobile restarted

$
0
0

Hello,
I have xamarin.forms application where I use Firebase Cloud Messaging. FCM is working fine when the app is in the foreground or background, but as soon as I swipe the app from the app manager or restart mobile, notification is never delivered.

For android, I use data only message

{
"to" : Token,
"data" : {
    "type" : "x"
}
}

For iOS, I use notification with content-available, like this

{
   "data":
   {
       "type":"x"
   },
   "apns":
   {
       "payload":
       {
           "aps":
           {
               "content-available":1,
               "alert":"Notification",
               "badge":1,
               "sound":"beep.aiff"
           }
       }
   },
   "token": Token
}

For android, I use FirebaseMessagingService and OnMessageReceived like this

public override void OnMessageReceived(RemoteMessage message)
        {
                try
            {
                if (message != null)
                {
                    base.OnMessageReceived(message);

                    // Set up an intent
                    var intent = SetIntent(message);

                    // Create a PendingIntent; we're only using one PendingIntent (ID = 0):
                    const int pendingIntentId = 0;
                    PendingIntent pendingIntent =
                        PendingIntent.GetActivity(this, pendingIntentId, intent, PendingIntentFlags.OneShot);

                    string title = GetNotificationText(message, true);
                    string bodyText = GetNotificationText(message, false);
                    // Create notification
                    var builder = new NotificationCompat.Builder(AndroidUtils.Context, AppInfo.PackageName)
                    .SetContentIntent(pendingIntent)
                    .SetSmallIcon(Resource.Drawable.icoLogo)
                    .SetContentTitle(title)
                    .SetContentText(bodyText)
                    .SetAutoCancel(true);

                    // Build the notification:
                    var notification = builder.Build();
                    notification.Flags = NotificationFlags.AutoCancel;
                    notification.Defaults = NotificationDefaults.Vibrate | NotificationDefaults.Sound;

                    // Get the notification manager:
                    var notificationManager =
                        (NotificationManager)AndroidUtils.Context.GetSystemService(Context.NotificationService);

                    // Publish the notification:
                    int notificationId = new Random().Next(0, 1000);
                    notificationManager.Notify(notificationId, notification);
                }
            }
            catch (Exception exception)
            {
                Crashes.TrackError(exception);
            }
        }

And this works without a problem, no matter if we are in the background or foreground, the app will build local notification from the data message and show it to the user. Unless he swiped the app.

On iOS its the same thing, but OS shows notification without our code - I just use AppDelegate DidReceiveRemoteNotification to run some custom code on our side and WillPresentNotification from UNUserNotificationCenterDelegate

Is there any way I can force both android and iOS to show a notification when the app is killed? I disabled battery optimization on phone and it still does not work, so I don't think that's the problem.

Issue with grouped list view

$
0
0
I am facing a wierd issue. I have a grouped list view it is working fine while loading the page, but when trying to load the same with same data on button click using a command, it's not showing up, anyone has any idea what is going on there

How I can copy my Sqlite database from Device to PC?

$
0
0

How I can copy my Sqlite database from Device to PC?

Wierd behavior with backgroundcolor of my swipeview in SwipeTransitionMode="Drag"

Viewing all 91519 articles
Browse latest View live


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