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

FirebaseApp is not initialized on real devices

$
0
0

Hello! I'm trying to add push notifications in Xamarin.Forms.
On Genymotion it's work fine but on real devices i have an error:
Default FirebaseApp is not initialized.Make shure to call FirebaseApp.initializeApp(Context)

google-services.json is present in Android project with GoogleServicesJson BuildAction

My MainActivity:

     public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
        {
            internal static MainActivity Instance { get; private set; }
            internal static FirebaseInstanceId FirebaseInstance { get; private set; }

            public static int CurrentUserId { get; set; }
            protected override async void OnCreate(Bundle bundle)
            {
                base.OnCreate(bundle);           

                TabLayoutResource = Resource.Layout.Tabbar;
                ToolbarResource = Resource.Layout.Toolbar;

                VideoViewRenderer.Init();
                global::Xamarin.Forms.Forms.Init(this, bundle);
                string dbPath = FileAccessHelper.GetLocalFilePath("LocalDataBase.db");

                LoadApplication(new App());

                Xamarin.Forms.Application.Current.On<Xamarin.Forms.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
                UserDialogs.Init(this);
                CachedImageRenderer.Init();           

            //on real devices it return  null
                var app = Firebase.FirebaseApp.InitializeApp(this.ApplicationContext);

                Instance = this;
            }

Preferences - How can I connect blob storage account name and key to a preference?

$
0
0

Under my Services i have a data store to wich you need to connect via blob storage account name and key. I want to save the account name and key to settings via Preferences from Xamarin.Essentials.

Local Notifications on Android 10 are not triggering

$
0
0

Local notifications are not triggering on Android 10 and it is triggering fine on previous versions.
Is there anything that I need to set for android 10 to trigger local notification?

`Random rm = new Random();
int NotificationId = rm.Next(9999);
var channelId = "MyApp Channel";
var mainIntent = new Intent(context, typeof(MainActivity));
mainIntent.PutExtra("NotificationId", NotificationId);
mainIntent.PutExtra("PageKey", pageKey);
mainIntent.AddFlags(ActivityFlags.ClearTop);
var pendingIntent = PendingIntent.GetActivity(context, NotificationId, mainIntent, 
PendingIntentFlags.UpdateCurrent);

var style = new NotificationCompat.BigTextStyle();
style.BigText(title);

var defaultSoundUri = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
var notificationBuilder = new NotificationCompat.Builder(context, channelId)
    .SetContentTitle("MyApp - " + title)
    .SetContentText(message)
    .SetAutoCancel(true)
    .SetSound(defaultSoundUri)
    .SetContentIntent(pendingIntent)
    .SetSmallIcon(Resource.Drawable.icon);

var notificationManager = NotificationManager.FromContext(context);

if (global::Android.OS.Build.VERSION.SdkInt >= global::Android.OS.BuildVersionCodes.O)
{
    NotificationChannel mChannel = new NotificationChannel(channelId, "My App", NotificationImportance.High);
    notificationManager.CreateNotificationChannel(mChannel);
    notificationBuilder.SetChannelId(channelId);
}

notificationManager.Notify(NotificationId, notificationBuilder.Build());`

Is it correct to use Xamarin.Forms namespace in a ViewModel

$
0
0

I am a newbie in Xamarin.Forms and the architect in our team mentioned, if we wanted a clean architecture, we must avoid using Xamarin.Forms in ViewModel as it references Views directly so it actually doesn't decouple.

But in the most of the tutorials, guides I don't see this being followed.

Can anyone suggest what's the correct guideline, and how does it really support this decoupling? Does everyone follow the same?
Also, when I try to use buttonclick event via a Command class in the ViewModel, I can't use it without using Xamarin.Forms namespace.

How can I achieve pure decoupling without using the Command class?

DisplayAlert button color

$
0
0

Where does DisplayAlert get the color used for the buttons?

Simply using DisplayAlert:
await DisplayAlert("Alert!", "This is DisplayAlert", "OK");

Is it possible to change this color on "OK"? It's also used in Picker and on Switch too.

Thanks,
Mike

How to change the scrollbar color of a listview

$
0
0

Hi, I want to change the vertical scrollbar color of a list view in xamarin forms. How can i do this.

Please help me...

Regarding Significant Location updates even app kills in Xamarin Forms

$
0
0

Hi all,

I am implementing the location services using Xamarin forms, I have an approach to get the location significantly for every 2 hours even the app killed from background. could some one suggest that if can achieve it in using Xamarin Forms or native platform ? thanks in advance

How to access content Row and column in DataGrid in xamarin.forms

$
0
0

Hello everyone, I want to make such a code dgvcurrencies.Rows(i).Cells(j).Value in DataGrid in xamarin.forms
Please help me with that


Bluetooth classic implementation for Android(No BLE)?

$
0
0

Hi all, I would like to know how to implement classic bluetooth with xamarin. Would you have a link for me to look at?

Any xamarin bluetooth example project? without using any plugin?

$
0
0

Any xamarin Bluetooth example project? without using any plugin?

Xamarin Forms bluetooth

$
0
0

Hi everyone, I'm looking for a nuget package that allows Xamarin Forms (both Android and iOS) to scan bluetooth devices (not bluetooth le). Could you please help me with this? Thanks in advance.

Xamarin Forms Image with 100% of parent container width and auto Height to maintain aspect ratio

$
0
0

Hello, I have read similar questions both here and on SO but apparently this cannot be done without implementing custom renderers? I simply want to have an Image to take 100% width of its parent container while actually fitting the whole image within this container without clipping and having height automatically adjusted to preserve aspect ratio. Why is this such an issue for Xamarin Forms? Implementing a custom renderer for such a trivial task is an overkill and a huge embarrassment for Xamarin in my opinion; unless I am understanding something wrong.

Keyboard overlap

$
0
0

Hello,

I am using Shell with bottom tabs

on one of the pages there is scrolling and entry, when the keyboard comes out, the bottom tabs also adjust, how to hide it?

in android I use:

App.Current.On<Xamarin.Forms.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);

How to set Embedded font support for Native platforms?

$
0
0

Hi,
I am working on embedded font in xamarin forms. I have implemented custom controls, one control is in Xamarin forms, where the embedded font support is working fine.
Next custom control rendered in native platforms, Where the embedded font support is not working.

How to implement embedded font support in native platforms?

Thanks in advance

Value cannot be null. Parameter name: type

$
0
0

Not sure what changed, but now when I build I get this error on every XAML file in my project. Has anyone ran into this issue before? Tried all of the usual fixes - del bin/obj, restart, clean rebuild, downgrade Forms...


Media Plugin MVVM not displaying picture

$
0
0

I am using media plugin and i am not able to see the taken picture on my content page. While debugging the app i can see the path but the picture is not there I have tried to follow this solution, however still nothing. https://stackoverflow.com/questions/47441800/xamarin-forms-mvvm-prism-with-media-plugin-how-to-get-a-taken-picture-from-d My Binding works fine for everything. Just I dont know how to get the imagem

public MediaFile SelectedPhoto { get => _selectedPhoto; set { _selectedPhoto = value; OnPropertyChanged(); } }

private async Task TakePicture()
{
await Permission();
var imageSource = await DependencyService.Get().ShowActionSheet(AppResources.AlertPhoto, AppResources.AlertNewPhoto, AppResources.AlertGallery);
if (imageSource == AppResources.AlertNewPhoto)
{
var imageFileName = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions()
{
Name = $"{DateTime.UtcNow}.jpg",
DefaultCamera = Plugin.Media.Abstractions.CameraDevice.Rear,
PhotoSize = PhotoSize.Medium,
SaveToAlbum = true
});
if (imageFileName == null)
{
DependencyService.Get().LongAlert(AppResources.AlertNoAcess);
}
else
{
SelectedPhoto = imageFileName;

                //var memoryStream = new MemoryStream();
                //imageFileName.GetStream().CopyTo(memoryStream);
                //imageFileName.Dispose();

                //var incidentImage = new PostImage
                //{
                //    ImageBytes = memoryStream.ToArray()
                //};

            }


        }

Need help setting up Shiny.SpeechRecognition in my Xamarin.Forms proj

$
0
0

Ive been struggling eith this shiny.SpeechRecognition plugin. I feel like there is no proper documentation or they are not unique or may be i am new to this. Iam unable to setup this plugin.
So first i installed Shiny.SpeechRecog package nuget and gave all the permission in info.plist and manifest and called the api in my device shake event. At first i got an error which says - cotainer not setup yet. are you missing shiny.init in platform proj.
Then i refered to this link => allancritchie . net / posts / introducingshiny
So after setting up now, my application does not start. it closes automatically after start. when i debugged the app. it says another error => System.TypeLoadException: Could not resolve the signature of a virtual method.
I created a startup class in my PCL, created delegate class to implement IJob
In andoid:mainactivity => Shiny.AndroidShinyHost.OnRequestPermissionsResult(requestCode, permissions, grantResults);
created a mainapplication class i put this
[Application]
public class MainApplication : Shiny.ShinyAndroidApplication<IslamicApp.IslamicAppStartup>
{
public MainApplication(IntPtr handle, JniHandleOwnership transfer) : base(handle, transfer)
{
}

    //public override void OnCreate()
    //{
    //    base.OnCreate();

    //    Shiny.AndroidShinyHost.Init(
    //        this,
    //        new IslamicAppStartup()
    //    );
    //}
}

In IOS => Shiny.iOSShinyHost.Init(new IslamicAppStartup());

unable to open pdf file on android 10 using xamarin forms

$
0
0

I have a developed code to save and open a pdf file and used to work on all android devices. Recently I figured it is not working on android 10.

Code to Save file:

    public async void SaveFile(byte[] bytes, string folderPath, string fileName)
    {
            if (IsFileExists(folderPath, fileName))
            {
                DeleteFile(folderPath, fileName);
            }
            string path = GetFilePath(folderPath, fileName); //path = "/storage/emulated/0/3080/TCPS/584"
            Directory.CreateDirectory(path);
            path = System.IO.Path.Combine(path, fileName); //filename = "Fugro TCO B-17-009.pdf"
            System.IO.File.WriteAllBytes(path, bytes);
        }
    } 

To Open the file:

public void OpenFile(string folderPath, string fileName)
    {
        MimeTypeMap mimeTypeMap = MimeTypeMap.Singleton;
        Intent newIntent = new Intent(Intent.ActionView);
        string path = GetFilePath(folderPath, fileName);
        string mimeType = null;
        String extension = MimeTypeMap.GetFileExtensionFromUrl(fileName);
        if (extension != null)
        {
            mimeType = MimeTypeMap.Singleton.GetMimeTypeFromExtension(extension.ToLower());
        }
        newIntent.SetDataAndType(Android.Net.Uri.FromFile(GetFile(path, fileName)), mimeType);
        newIntent.SetFlags(ActivityFlags.NewTask);
        Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity.StartActivity(newIntent);
    }

Here, if the file is pdf, I'm getting mime-type as null but it's work fine on android 9 and below. Can anyone explain what needs to be done to get it to work on android 10?

Dark/Light mode switch OnPlatform in XAML

$
0
0

Hi,
I try to change the color in a OnPlatform clause, but I get an System.InvalidCastException: 'Specified cast is not valid.' I have the following XAML-code

        <OnPlatform
            x:Key="ButtonBackgroundColor"
            x:TypeArguments="Color"
            >
            <On
                Value="{StaticResource ColorGreen}"
                Platform="Android, UWP"
                />
            <On
                Value="{AppThemeBinding Dark=#1C1C1E, Light=White}"
                Platform="iOS"
                />
        </OnPlatform>

Can anyone tell me, how can I fix this problem? I tried with static resources definition, but got the same exception. Thank you!

BindableProperty only updating ViewModel property with default values

$
0
0

Hi,

I have a binding issue in my Xamarin.Forms project with the following setup:

  • One GenericPage superclass inheriting from ContentPage and containing a BindableProperty
  • One Page class inheriting from GenericPage with a ViewModel which is bound to the BindableProperty using a OneWayToSource binding mode
  • One GenericControl superclass inheriting from ContentView and containing a BindableProperty
  • One Control class inheriting from GenericControl with a ControlViewModel which is bound to the BindableProperty using a OneWayToSource binding mode
  • An instance of the Control class is embedded in the Page class using XAML and the BindableProperty of GenericControl is bound to the property of the ViewModel using a OneWay binding mode

Visual representation of this setup:

I can verify that the "connection" from Page to the BindableProperty of GenericControl indeed works, as the propertyChanged method is invoked in GenericControl with the correct value from the BindableProperty in GenericPage. I can also verify that the "connection" from GenericControl to ControlViewModel is working (at least in the beginning) as the property setter in ControlViewModel is called once with the default value from the BindableProperty in GenericControl.

However, for some reason, the changes which arrive at the BindableProperty in GenericControl (either the default values from GenericPage or externally set) are not propagated to the ControlViewModel.

I have created a Repro Project for this issue: github.com/mlxyz/Xamarin-Forms-Binding-Repro

In the project, pressing the button will change the value of the bindable property in GenericPage. However, the property of the ControlViewModel is not updated for some reason (the top label).

Why is this the case and how can I fix it?

Thanks!

Note: I have also posted this question to stackoverflow: stackoverflow.com/q/62913492/10289094

Viewing all 79144 articles
Browse latest View live


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