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

Restart Activity

$
0
0

Good day
I am trying to do a QR scanner in Xamarin,
I use the Zxing library to do the reading and I try to put the result in an Entry, when the camera reads the code, instead of putting the result of the reading in the Entry, it sends me to the MainActivity

The same thing happens if I minimize the application, it does not matter in which Activity I am, when returning it always sends me to the MainActivity

I'm new to Xamarin.Android development, I hope you can support me

Thanks a lot


Xamarin.Forms.Shell: how to manage StatusBar color

$
0
0

I've developed a small Xamarin.Forms.Shell app and I didn't found how to apply a custom color for the StatusBar Foreground and Background.

My app use a very basic color scheme:
- black for the Foreground of the NavigationBar and the TabBar
- white for the Background of the NavigationBar and the TabBar

I would like to keep the same colors for the StatusBar, but it's not the case:
- on iOS, the StatusBar color seems to be managed by the LightMode/DarkMode => in my case, the Background color of the StatusBar doesn't change and is still white in both cases, but it's not the case for the StatusBar informations: so the StatusBar informations are not visible as there are also white when DarkMode is active
- on Android, the StatusBar color seems to be managed by the styles.xaml file and the android:statusBarColor property => but if I specify a white color, the StatusBar informations are not visible as there are also white

So I've tried to apply a solution given there:
- this doens't work on iOS: I still have the same behavior, as the StatusBar informations are not visible as there are also white when DarkMode is active
- this seems to work on Android, but this doesn't cover all Android versions

=> How could I manage the iOS StatusBar Foreground color? Is it enough for Android?

navigated event is not triggering

$
0
0

I am using Xamarin to load webpage through Webview and handling SSL error through hybridwebviewRenderer

this is my code for creating mainpage.xaml.cs


 public partial class MainPage : ContentPage
    {
        
        ActivityIndicator defaultActivityIndicator;
        WebView defaultWebView;
        
        bool isTaskRunning;
        public MainPage()
        {
            InitializeComponent();
            //Browser.Source = "https://66.85.30.135/index.php";

            defaultWebView = new WebView
            {
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Source = "https://66.85.30.135/index.php"
            };

            defaultWebView.Navigating += WebviewNavigating;
            defaultWebView.Navigated += WebviewNavigated;

            defaultActivityIndicator = new ActivityIndicator
            {
                VerticalOptions = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.Fill,
                IsVisible = false
            };

            Content = new StackLayout
            {
                Children =
                {
                    defaultActivityIndicator,
                    defaultWebView
                }
            };

            //UpdateUiState();
        }

        public void WebviewNavigating(object sender, WebNavigatingEventArgs e)
        {
            defaultActivityIndicator.IsVisible = true;
            isTaskRunning = true;
            UpdateUiState();
        }

        public void WebviewNavigated(object sender, WebNavigatedEventArgs e)
        {
            defaultActivityIndicator.IsVisible = false;
            isTaskRunning = false;
            UpdateUiState();
        }

        void UpdateUiState()
        {
            defaultActivityIndicator.IsRunning = isTaskRunning;   
        }
    }

this is my HybridWebViewRenderer:

[assembly: ExportRenderer(typeof(WebView), typeof(HybridWebViewRenderer))]
namespace KScrapIT.Droid
{
    class HybridWebViewRenderer : WebViewRenderer
    {
        public HybridWebViewRenderer(Context context) : base(context)
        {
        }

        protected override void OnElementChanged(ElementChangedEventArgs e)
        {
            base.OnElementChanged(e);
            Control.Settings.JavaScriptEnabled = true;

            Control.SetWebViewClient(new MyWebviewClient());
        }
    }

    internal class MyWebviewClient : Android.Webkit.WebViewClient
    {
        public override void OnReceivedClientCertRequest(Android.Webkit.WebView view, Android.Webkit.ClientCertRequest request)
        {
            request.Ignore();
            base.OnReceivedClientCertRequest(view, request);
        }
        public override void OnReceivedSslError(Android.Webkit.WebView view, Android.Webkit.SslErrorHandler handler, Android.Net.Http.SslError error)
        {
            handler.Proceed();
            base.OnReceivedSslError(view, handler, error);
        }
    }
}

due to some odd reason WebView Navigated event is not triggering.

please help.

How to start activity ?

$
0
0

Hello
I have two activities the mainActivity and Activity1;
I would like to start activity1 in a click button;

public class MainActivity :  Activity
{
    private Activity1 act1;

    private void statisclick()
        {
            act1 = new Activitystat();
            act1.StartActivity ( ?);

        } 
]

What argument to provide to method StarActivity ?
Thanks

Splash screen storyboard with full screen image

$
0
0

I need create splash screen storyboard with full screen image . at first I thought it was easy. but after trying many options I got no result. at first I thought it was easy. but after trying many options I got no result. the designer in the studio does not work. I have problems with displaying in xcode interface builder. any help - i would be very grateful. I'm tired of fighting with tools. any help or example.

Embedded Resource font and Android

$
0
0

I have a custom font I created on icomoon.com with 4 characters in it. I'm using it as an Embedded Resource. Under iOS, I can see all the symbols on the Views they're used in. Under Android, I can only see one of that symbols in the font.

It has nothing to do with the layout they're used in. I have changed all 4 layouts to use the one symbol that works and it shows up.

What is com.google.android.gms.tasks?

$
0
0

I am trying to build for Android on a Mac and get 92 errors, such as:

javac error JAVAC0000: error: package com.google.android.gms.tasks
package com.google.android.gms.maps.GoogleMap does not exist
error: package com.google.android.gms.common.api does not exist

I've found plenty of websites with similar problems and steps to solve them. But none of the solutions work, and no one really talks much about the actual issue.

Does anyone know what these "packages" are? Are these .jar files or something similar that I can check for on the hard drive? Are these required to build any Xamarin Android app, or only for certain google APIs?

Firebase Crashlytics Migration - Issue Names Now Useless

$
0
0

So with the recent migration from Fabric Crashlytics to the lastest Firebase Crashlytics, the "Issue Grouping" (based on the names/types of exceptions) has completely broken.

Previously when crashes showed up in Firebase console, it'd be the proper C# exception name. The old library we were using allowed us to call RecordException and pass in our System.Exception, so it was formatted nicely (Crashes in console were grouped by exception type and message). The new Xamarin.Firebase.Crashlytics expects a Java.Lang.Throwable. I read around that we can just use Java.Lang.Throwable.FromException to convert between the two, so we tried that.

The result is that ALL our crashes we had previously, from many different C# classes, now get clumped into:
Activity1.java
RunnableImplementor.java
android.runtime.JavaProxyThrowable

If you go through each individual crash we can eventually find all the different issues, and it eventually includes the stack trace going into the C# classes, but trying to group/understand what's happening is completely impossible. Basically it looks like with the new Crashlytics implementation, the root level of each crash report is ignoring any C# call stack and reporting only the root java entry point.

Has anybody else been having this issue? We're really needing a solution since we no longer have any visibility to what's happening in our app anymore.


How to reveice a paramater in ViewModel?

$
0
0

I send a parameter from view using button:
public async void btnchat_clicked(object sender, EventArgs e)
{
string sellerid = custid.Text;
await Navigation.PushAsync(new ChatPageViewModel(sellerid.ToString()));
}
i need help for how to receive the value in viewmodel for where clause

how to change the shadow color of a frame?

$
0
0

how to change the shadow color and spread height of a frame?

How to dynamically change background color with button?

$
0
0

Hi All,

How do I code a button to dynamically change the Stack layout background color on my xamarin Android app? I currently only have a single view and an empty event handler for when the button is clicked. I would like the user to click the button and have the background change color. When the button is clicked again, I would like the button to return to its original color.

Thanks.

SQL Lite query failing

$
0
0

This should be straight forward but apparently its not. I am simply trying to get a list from within an id list in a database table. _connection is already instantiated

public Task<List<TextInfo>> GetTextInfosAsync(List<int> idList)
{
return _connection.Table<TextInfo>().Where(x => idList.Equals(x.Id)).ToListAsync();
}

The error message I get is "row value misused". What gives?

Cheers.

Using flashlight while camera is on

$
0
0

I have an app with a barcodescanner and an in-app camera.

I have an option in the barcodescanner (using ZXing) for a flashlight, which can be turned on and off in the page itself. The code I'm using to do this is:

Where 'scanner' is the barcodescanner and ButtonFlashlight the button to turn the flash on and off. You can also see that two images are used: one for the off state and one for the on state.

Now I want to implement this in my in-app camera as well, but I cannot get it to work. The latest 'failure' is an exception:

I understand the exception, I just don't know how to do it then.

For using this function in the in-app camera, I used Xamarin.Essentials with this code:

So what I need are two things: first the option to turn on the flashlight, and secondly the check if the flashlight is on or off (so that the correct flashlight image can be shown).

Does someone know how to do this?

How can i make a game in unity and run the game when i run xamarin.forms project?

$
0
0

Hi, I just came xamarin crash I want to make a game project that should be called from unity, how can I do it, help guide me

Proguard and shrinking the APK

$
0
0

I am following the steps to prepare for publishing my app found here
https://docs.microsoft.com/en-us/xamarin/android/deploy-test/release-prep/proguard

I am at the shrink the APK step and it suggests using proguard. I went to this document for instructions:

https://docs.microsoft.com/en-us/xamarin/android/deploy-test/release-prep/proguard

When I compile with the dex compiler setting, I get the following:
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(556,2): error XA1011: Using ProGuard with the D8 DEX compiler is no longer supported. Please set the code shrinker to r8 in the Visual Studio project property pages or edit the project file in a text editor and set the AndroidLinkTool MSBuild property to r8.
========== Rebuild All: 1 succeeded, 1 failed, 1 skipped ==========

If I set the dex compiler to dx, I get the following:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(560,2): warning XA1023: Using the DX DEX Compiler is deprecated. Please update $(AndroidDexTool) to d8.

My question(s): Is proguard not the way to go these days and the docs are out of date?

re: What is the actual CURRENT guidance for this?


CollectionView Data isn't loaded

$
0
0

Hi everyone,

I hope you can help me with my issue.

I created a ContentPage with the following ListView. So the important part is the TemplateForAndroid.

<ContentPage.Resources>
        <ResourceDictionary>
            <DataTemplate x:Key="TemplateForiOS">
                <views:NotificationViewCelliOS/>
            </DataTemplate>
            <DataTemplate x:Key="TemplateForAndroid">
                <views:NotificationViewCell/>
            </DataTemplate>
        </ResourceDictionary>
    </ContentPage.Resources>
<ListView 
    x:Name="InboxListView"
    x:FieldModifier="public"
    ItemsSource="{Binding Notifications}"
    HasUnevenRows="True" 
    VerticalOptions="StartAndExpand"
    IsPullToRefreshEnabled="True"
    VerticalScrollBarVisibility="Never"
    SelectionMode="None"
    ItemAppearing="InboxListView_OnItemAppearing"
    RefreshCommand="{Binding RefreshCommand}"
    IsRefreshing="{Binding IsRefreshing}"
    Scrolled="InboxListView_OnScrolled">

    <ListView.Behaviors>
        <local:EventToCommandBehaviour EventName="ItemAppearing" Command="{Binding LoadMoreCommand}"/>
    </ListView.Behaviors>

    <ListView.ItemTemplate>
            <OnPlatform x:TypeArguments="DataTemplate">
                <On Platform="iOS" Value="{StaticResource TemplateForiOS}"/>
                <On Platform="Android" Value="{StaticResource TemplateForAndroid}"/>
            </OnPlatform>
    </ListView.ItemTemplate>
</ListView>

The TemplateForAndroid looks as following:

<ViewCell xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             xmlns:converter="clr-namespace:CommunityApp.Converter;assembly=CommunityApp"
             x:Class="CommunityApp.Views.NotificationViewCell">
    <ViewCell.View>
        <CollectionView x:Name="NotiScroll"
                        ItemsLayout="HorizontalList">
            <CollectionView.Resources>
                <ResourceDictionary>
                    <converter:HtmlLabelConverter x:Key="HtmlLabelConverter" />
                </ResourceDictionary>
            </CollectionView.Resources>
            <CollectionView.ItemTemplate>
                <DataTemplate>
                    <StackLayout Orientation="Horizontal">
                        <Label Grid.Row="0" Grid.Column="0"
                               HeightRequest="30"
                               Text="Test"
                               FontAttributes="Italic"
                               VerticalOptions="End" />
                        <Label Grid.Row="0" Grid.Column="0"
                               HeightRequest="30"
                               Text="Test"
                               FontAttributes="Italic"
                               VerticalOptions="End" />
                        <Label Grid.Row="0" Grid.Column="0"
                               HeightRequest="30"
                               Text="Test"
                               FontAttributes="Italic"
                               VerticalOptions="End" />
                    </StackLayout>
                </DataTemplate>
            </CollectionView.ItemTemplate>
        </CollectionView>
    </ViewCell.View>
</ViewCell>

At the moment I try to work with dummy Labels, but even those are not visible in my Android App. So The ListView works good but the Labels from the DataTemplate inside the ViewCell isn't visible or doesn't get loaded.

If you have further questions, please ask me.

Greetings

Editing an SVG image programmatically

$
0
0

So yeah, we added a handful of SVG images to a Forms App we are working on. That is all fine and dandy. The problem is that the images are going to change.

How? Well, let's say that as long as the app is running (which, given its functionality, is almost an entire day) is going to receive a certain amount of data the is going to change the appearance of said SVG images. The data in question is a number and a string containing a colour (in hex).

What do we want to do with this number and hex? Modify the SVG, change the usual black colour into the hex and write the number on top of the image. Sounds simple, yet it's proven to be quite impossible.

Normally, what we do is fill the resources with the same image (png, obviously) in different colours so that, when necessary, changing from one colour to another is as easy as changing the Image's source. BUT, since we do not know the colours beforehand (and also, they are subject to change), we have to manipulate the SVG as the app runs. The integer is no easy feat either.

If someone knows about how to do something like this, we'll be grateful to hear. Please, ask about any info about our project we might have overlooked (packages, frameworks, etc.).

Regards.

P.S.: In ordrer to load the SVG,s, we use SkiaSharp. Any alternative will be welcome. As long as it works in our framework.
Visual Studio for Mac (Community) V. 8.8 (build 2913)
Xamarin.Forms (4.8.0.1687)
.NET Standard 2.0

How do I assign a value from a static class to x:String in a resource dictionary?

$
0
0

I want my values in the array to reference static values. How can I achieve this?

Here's how the dictionary looks

   <ContentView.Resources>
            <ResourceDictionary>
                <x:Array x:Key="Values" Type="{x:Type x:String}">
                    <x:String>First</x:String>
                    <x:String>Second</x:String>
                </x:Array>
            </ResourceDictionary>
        </ContentView.Resources>

I want something like:

   <ContentView.Resources>
            <ResourceDictionary>
                <x:Array x:Key="Values" Type="{x:Type x:String}">
                    <x:String Value="{x:Static values:Values.First}"></x:String>
                    <x:String Value="{x:Static values:Values.Second}"></x:String>
                </x:Array>
            </ResourceDictionary>
        </ContentView.Resources>

Glide 4.11 for self-signed certificates on Android Xamarin

$
0
0

i am using Xamarin.Android.Glide for my android xamarin app.
this code i try to use

class Verified : Java.Lang.Object, IHostnameVerifier
    {
        public bool Verify(string hostname, ISSLSession session)
        {
            return true;
        }
    }
    class Trusted : Java.Lang.Object, IX509TrustManager
    {
        public void CheckClientTrusted(Java.Security.Cert.X509Certificate[] chain, string authType)
        {
        }
        public void CheckServerTrusted(Java.Security.Cert.X509Certificate[] chain, string authType)
        {
        }
        public Java.Security.Cert.X509Certificate[] GetAcceptedIssuers()
        {
            return new Java.Security.Cert.X509Certificate[] { };
        }
    }
    [GlideModule]
    public class MyGlideModule : AppGlideModule
    {
        public override void ApplyOptions(Context context, GlideBuilder builder)
        {
            base.ApplyOptions(context, builder);
        }
        public override void RegisterComponents(Context context, Glide glide, Registry registry)
        {
            ITrustManager[] trustAllCerts = new ITrustManager[1] { new Trusted() };
            var sslContext = Javax.Net.Ssl.SSLContext.GetInstance("SSl");
            sslContext.Init(null, trustAllCerts, new Java.Security.SecureRandom());
            var sslSocketFactory = sslContext.SocketFactory;
            OkHttpClient client = new OkHttpClient().NewBuilder().Protocols(new Protocol[] { Protocol.Http11 }).SslSocketFactory(sslSocketFactory).HostnameVerifier(new Verified()).Build();

            OkHttpUrlLoader.Factory factory = new OkHttpUrlLoader.Factory(client);
            registry.Replace(Java.Lang.Class.FromType(typeof(GlideUrl)), Java.Lang.Class.FromType(typeof(InputStream)), factory);
        }
        public override bool IsManifestParsingEnabled => false;
    }

but OkHttpUrlLoader.Factory class not exists in this library. this class existrs in Karamunting.AndroidX.BumpTech.Glide.Integration.OkHttp3 4.9.0. i cant use this lib, because it confilcts with xamarin.firebase.crashlyticks. how i can realace this OkHttpUrlLoader.Factory class ?

Error when trying inflate custom button. Caused by: java.lang.ClassNotFoundException.How to fix?

$
0
0

StackTrace:

[MonoDroid] android.view.InflateException: Binary XML file line #1: Error inflating class TypefacedButton
[MonoDroid]     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
[MonoDroid]     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
[MonoDroid]     at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
[MonoDroid]     at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
[MonoDroid]     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
[MonoDroid]     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
[MonoDroid]     at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method)
[MonoDroid]     at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:29)
[MonoDroid]     at android.view.View.performClick(View.java:4438)
[MonoDroid]     at android.view.View$PerformClick.run(View.java:18422)
[MonoDroid]     at android.os.Handler.handleCallback(Handler.java:733)
[MonoDroid]     at android.os.Handler.dispatchMessage(Handler.java:95)
[MonoDroid]     at android.os.Looper.loop(Looper.java:136)
[MonoDroid]     at android.app.ActivityThread.main(ActivityThread.java:5017)
[MonoDroid]     at java.lang.reflect.Method.invokeNative(Native Method)
[MonoDroid]     at java.lang.reflect.Method.invoke(Method.java:515)
[MonoDroid]     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
[MonoDroid]     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
[MonoDroid]     at dalvik.system.NativeStart.main(Native Method)
[MonoDroid] Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.TypefacedButton" on path: @path]
[MonoDroid]     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
[MonoDroid]     at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
[MonoDroid]     at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
[MonoDroid]     at android.view.LayoutInflater.createView(LayoutInflater.java:559)
[MonoDroid]     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:652)
[MonoDroid]     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
[MonoDroid]     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
[MonoDroid]     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
[MonoDroid]     ... 18 more

Error in line:

var scannerOverlay = LayoutInflater.FromContext(topActivity).Inflate(Resource.Layout.ScannerOverlay, null,false);

XML:

<RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <TypefacedButton
                android:text="ОТКРЫТЬ БОЛЬШЕ"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/openBiggerButton"
                style="@style/ButtonStartBlue"
                android:layout_alignParentRight="true"
                android:layout_marginBottom="13dp"
                android:layout_marginRight="7dp" />
            <TypefacedButton
                android:text="ОТМЕНИТЬ"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/revertButton"
                style="@style/ButtonStartBlue"
                android:layout_alignParentLeft="true"
                android:layout_marginLeft="7dp"
                android:layout_marginBottom="13dp" />
        </RelativeLayout>

When i try inflating my Custom TypefacedButton i got InflateException error, but when i use standard Buttons , all works fine. Help me to fix it.

Viewing all 204402 articles
Browse latest View live


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