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

Scanning Wifi from PCL project using Dependency Service

$
0
0

Hello!
I need to scan the wifi programatically and return a list of all SSID's I get. I've read about it and concluded I can't make it on iOS in a way I can publish the App on the Apple Store(ref).
So, I decided to at least implement it for Android Users, I'm trying to implement via Dependency Service but I'm doing it wrong, here is what I'm doing:

This is the Wifi.cs class in the Android project:

using AirSenseApp.Services;
using Android.Content;
using Android.Net.Wifi;
using System.Collections.Generic;

[assembly: Xamarin.Forms.Dependency(typeof(AirSenseApp.Droid.Classes.Wifi))]
namespace AirSenseApp.Droid.Classes
{
    public class Wifi:IWifi
    {
        private Context context = null;
        private static WifiManager wifi;
        private WifiReceiver wifiReceiver;
        public static List<string> WiFiNetworks;

        public Wifi(Context ctx)
        {
            this.context = ctx;
        }

        public void GetWifiNetworks()
        {
            WiFiNetworks = new List<string>();

            // Get a handle to the Wifi
            wifi = (WifiManager)context.GetSystemService(Context.WifiService);

            // Start a scan and register the Broadcast receiver to get the list of Wifi Networks
            wifiReceiver = new WifiReceiver();
            context.RegisterReceiver(wifiReceiver, new IntentFilter(WifiManager.ScanResultsAvailableAction));
            wifi.StartScan();
        }

        public class WifiReceiver:BroadcastReceiver
        {
            public override void OnReceive(Context context, Intent intent)
            {
                IList<ScanResult> scanwifinetworks = wifi.ScanResults;
                foreach(ScanResult wifinetwork in scanwifinetworks)
                {
                    WiFiNetworks.Add(wifinetwork.Ssid);
                }
            }
        }
    }
}

This is my Interface that I'm trying to implement on the PCL project:

using System;
using System.Collections.Generic;
using System.Text;

namespace AirSenseApp.Services
{
    public interface IWifi
    {
        void GetWifiNetworks();

    }
}

Is this the correct way to implement it? I tried to put it in my ViewModel this way:

public class CreateDeviceViewModel:INotifyPropertyChanged
{
    private readonly IWifi _wifiService;
    public CreateDeviceViewModel()
    {
        this._wifiService = DependencyService.Get<IWifi>();
    }
    public ScanWifiButtonPressed()
    {
        _wifiService.GetWifiNetworks();
    }
}

But I receive this error:
[0:] System.MissingMethodException: Default constructor not found for type AirSenseApp.Droid.Classes.Wifi

This means I'm not implementing the Wifi.cs in the Android project in the correct way or the problem is in the Interface?


Binding Library Error: How to make a method return an array of IDictionary ?

$
0
0

I am getting an error when I import a .aar file to integrate with a machine service.

My question is as per the title.

This the code I am trying to get:

[Register ("getSlots", "()[Ljava/util/HashMap;", "")]
        public unsafe global::System.Collections.Generic.IDictionary <string, byte[]> [] GetSlots ()
        {
            const string __id = "getSlots.()[Ljava/util/HashMap;";
            try {
                var __rm = _members.InstanceMethods.InvokeNonvirtualObjectMethod (__id, this, null);
                return (global::System.Collections.Generic.IDictionary<string, byte[]>[]) JNIEnv.GetArray (__rm.Handle, JniHandleOwnership.TransferLocalRef, typeof (global::System.Collections.Generic.IDictionary<string, byte[]>));
            } finally {
            }
        }

This is the code I am getting:

[Register ("getSlots", "()[Ljava/util/HashMap;", "")]
        public unsafe global::System.Collections.Generic.IDictionary <string, byte[]>GetSlots ()
        {
            const string __id = "getSlots.()[Ljava/util/HashMap;";
            try {
                var __rm = _members.InstanceMethods.InvokeNonvirtualObjectMethod (__id, this, null);
                return (global::System.Collections.Generic.IDictionary<string, byte[]>[]) JNIEnv.GetArray (__rm.Handle, JniHandleOwnership.TransferLocalRef, typeof (global::System.Collections.Generic.IDictionary<string, byte[]>));
            } finally {
            }
        }

I need a method that returns an array IDictionary <string, byte[]>[], but I am getting IDictionary <string, byte[]>

This is the code that is in metadata.xml

<attr path="/api/package[@name='br.com.uol.pagseguro.plugpagservice.wrapper']/class[@name='PlugPagNFCResult']/method[@name='getSlots' and count(parameter)=0]" name="managedReturn">System.Collections.Generic.IDictionary &lt;string, byte[]&gt;</attr>

But every time I write "[]", after ">", it doesn't appear to form an array!

Could you help me with this?

Animating scrollview items appear & disappear.

$
0
0

I'm trying to create some animations inside a CollectionView. This is when the items are added or when the items are removed.
I have looked for some animations tutorials however I have not seen an example being applied to the items inside the collectionview, how could I animate them?

Thanks!

Customize ListView

$
0
0

Hey,

I want to create a custom cell which should describe a transaction (like a banking app). The transactions should be group by there date.
The cell should look like the one in the attached photo.

My question is, is this possible with Xamarin.Forms?

I could create a cell with space between them using the DataTemplate for the ListView but there are two other major problems:
- How can I customize the grouping header (Label and Background) from the ListView?
- How can I change the selected background to only apply on my custom frame (not the entire cell, because I use space between them by "actual" cell
is a view inside the cell with margins around them)?

Is it better to use a Scroll view with custom views like cards for this? What is the performance of a ScrollView is like when there are many cells/views in there?

I have searched a lot but don't find anyone who is using such cells...

Thanks for your help!!

Flo

Xaml in Xaml

$
0
0

Hi, I have created a page with a few ListViews and I would like to break out the ListViews into a separate xaml file/class and include it in my main page. Is this possible, and if so, can anyone give an example? Should the ListView be created as another ContentPage and just included somehow?

Thanks

Garbage collector problems

$
0
0

And is preventing me to run the app

And sometimes I run it and the emulator just quit my app

How to open excel sheet in your app

$
0
0

i am using xamarin forms how can i open excel sheet in my app its urgent

GeoJson division method

$
0
0

I can get the following strings, but I want to put each item in an array or List. Please tell me how.

"[{\"geometry\":{\"coordinates\":[140.88195988,38.26132187],\"type\":\"Point\"},\"type\":\"Feature\",\"properties \":{\"addressCode\":\"4101\",\"title\":\" Sendai Central Police Station Sendai Station Police Box \"}},{\"geometry\":{\"coordinates\": [140.88429356,38.26088682],\"type\":\"Point\"},\"type\":\"Feature\",\"properties\":{\"addressCode\":\"4102\", \"title\":\" Sendai East Police Station Sendai Station East Exit Police Box \"}}, {\"geometry\":{\"coordinates\":[140.88182757,38.25961021],\"type\":\"Point \"},\"type\":\"Feature\",\"properties\":{\"addressCode\":\"4101\",\"title\":\" Sendai Station Post Office \" }},{\"geometry\":{\"coordinates\":[140.86964338,38.28124646],\"type\":\"Point\"},\"type\":\"Feature\",\" properties\":{\"addressCode\":\"4101\",\"title\":\" Kita Sendai Ekimae Post Office \"}},{\"geometry\":{\"coordinates\":[140.870058581944 ,38.2817545763889],\"type\":\"Point\"},\"type\":\"Feature\",\"properties\":{\"addressCode\":\"4101\",\" title\":\" Kita Sendai Station \"}},{\"geometry\":{\"coordinates\":[140.882662910278,38.2597717763889],\"type\":\"Point\"},\"type\ ":\"Feature\",\"properties\":{\"addressCode\":\"4101\",\"title\":\ "Sendai Station \"}},{\"geometry\":{\"coordinates\":[140.880538600833,38.2597877827778],\"type\":\"Point\"},\"type\":\"Feature \",\"properties\":{\"addressCode\":\"4101\",\"title\":\" Sendai Station \"}},{\"geometry\":{\"coordinates\" :[140.920350303611,38.2762798888889],\"type\":\"Point\"},\"type\":\"Feature\",\"properties\":{\"addressCode\":\"4102\" ,\"title\":\"Higashi Sendai Station \"}},{\"geometry\":{\"coordinates\":[140.883556986389,38.1975123758333],\"type\":\"Point\"},\ "type\":\"Feature\",\"properties\":{\"addressCode\":\"4104\",\"title\":\"Minami Sendai Station\"}}]"


Why the size of the XamarinForms app still large despite the use of ProGuard

$
0
0

Large size of blank XamrinForms app, Even after I used Linker and ProGuard to reduce the size of the app, the app size is still 17MB, although it is blank, Is this normal size?

sorry about my bad english.

Xamarin Forms Line Chart

$
0
0

Hi All,

I am used xamarin.forms(PCL) and I want to do Line chart in Android and iOS

Can any one please suggest me which library is best for xamarin.forms.

Your help is relay appreciated for me.

How to read an excel sheet data in Xamarin.Forms

$
0
0

I have a requirement where I need to read an excel sheet to be loaded into table. But I don't see any correct working documentation so far.
Googling takes to different pages and most of them seems to be not working.

Please Help!

Xamarin Forms: ios:Page.UseSafeArea is not working for all the children in CarouselPage

$
0
0

I have a CarouselPage having 4 children. For every pages I have added ios:Page.UseSafeArea, but SafeArea property is working only for first 2 pages and for the remaining 2 pages the safe area feature is not working. My XF version is 4.7.0.1080 (latest one).

I found the same issue on Github, is there any solution for this issue?

Facebook Audience Network Ads Implementation In Xamarin.Forms !

$
0
0

Hi Developers ! In Past I Have Successfully Added ADMOB Ads To My Apps. The Instructions Are Straight Forward. But Now I Want To Implement Facebook Audience Network Ads To My App, But No Clear Document Is Available. There is a Official Nuget , But No Clear Docs About Implementation. Also I Have Search On Youtube, Accept Only 2 Videos About FAN, No Third Video Is Found. On Github There Is a Project, I Try To Use But No Success. When I Run a Project, App Crashes Immediately. Its My 3rd Day Of Searching About FAN. So Now I Decided To Discuss This ON Forums.......... AnyOne Has Experience It With Or HE/SHE Implemented FAN Ads?

Official Nuget For Android : https://www.nuget.org/packages/Xamarin.Facebook.AudienceNetwork.Android/
Some Project I Found On Github About FAN : https://github.com/nguyenthanhliemfc/XF_FacebookAds

Need equivalent to an Android Activity for UWP & iOS

$
0
0

I got on GitHub this project to access Google Drive using Xamarin.Forms solution. Good that it works perfectly for Android. I wanted to extend to iOS & UWP. Google Drive API needs an Android Activity 'Custom URL Schem Interceptor'. I need how to implement it for iOS & UWP. The android activity code is given below. Someone might have already done that I hope.

using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.OS;
using System;
using Xamarin.Auth;

namespace XFCloudStorage.Droid
{
    [Activity(Label = "CustomUrlSchemeInterceptor", NoHistory = true, LaunchMode = LaunchMode.SingleTop)]
    [IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable }, DataSchemes = new[] { "com.esmsmartsolutions.xfcloudstorage" }, DataPath = "/oauth2redirect")]
    public class ActivityCustomUrlSchemeInterceptor : Activity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            global::Android.Net.Uri uri_android = Intent.Data;
            CustomTabsConfiguration.CustomTabsClosingMessage = null;
            var uri = new Uri(Intent.Data.ToString());
            AuthenticatorHelper.OAuth2Authenticator.OnPageLoading(uri);
            var intent = new Intent(this, typeof(MainActivity));
            intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
            StartActivity(intent);
            this.Finish();
            return;
        }
    }
}

How do you submit a form to another page

$
0
0

SearchPage.xaml has a CollectionView which initially loads data from ViewModel.
Search form is loaded as modal page with a back navigation bar.

var searchForm = new SearchFormPage(); await Application.Current.MainPage.Navigation.PushAsync(searchForm);

SearchFormPage.xaml has checkboxes, pickers and a Button to use the form data as filter for the data on SearchPage.xaml.

What is the recommended practice in the mobile development arena of submitting a form and presenting data?

There are several example using a search box on the navigation bar but unsure what is best practice using a modal form.


Azure Microsoft Login Error IOS platform

$
0
0

UWP login process success

Android login process success



but , when started ios returning keychain exeption (ios simulator)

How to use ARKit in Xamarin.Forms

$
0
0

Hi all, can any one please help me on how to use ARKit in Xamarin.Forms. Any sample code or proper link on how to implemented will be very helpful!!

Thanks.

How to crop an image based on a square overlay

$
0
0

I have implemented a UI Image picker in my Xamarin project but would like to take it a step further. After the user selects the picture from the camera roll, I'd like for there to be an overlay in the shape of a square over the picture. The user can then drag the little square window around until the subject of the photo is in the square, and then they can crop it to that size. (kind of like the instagram feature when you go to choose a profile picture- except in my case I want it to be square)

How can I go about doing this? I'm not looking for anyone to hold my hand, just tips on how to get started without using some old outdated and unkept library. This is for a company so it's best if I don't use libraries. I looked into all of the libraries and they are either outdated or not what I'm looking for.

Any suggestions?

Centered Icon-only Tabs on Android

$
0
0

Hi,

I'm looking to remove the text from the tabs (and vertically center the icon) in my Xamarin Forms app, like this:


I achieved this on iOS by making the TextColor clear and shifting the image down:

    public override void ViewWillLayoutSubviews()
    {
        base.ViewWillLayoutSubviews();

        if (TabBar != null)
        {
            foreach (var item in TabBar.Items)
            {
                item.ImageInsets = new UIEdgeInsets(5, 0, -5, 0);
            }
        }
    }

Right now my tabs on Android look like this:

If it matters, it's been set it to the bottom of the screen like so:

    public MyTabbedPage()
    {
        On<Android>().SetToolbarPlacement(ToolbarPlacement.Bottom);
    }

How can I remove the text and center the icon on the Android tab bar? I've played around with the styles and axml but I'm not really getting anywhere.

Thanks!

Xamarin Forms - Retrieve All Cookies from a website registered on a WebView

$
0
0

So I followed this article in order to retrieve all cookies for a specific site, but something weird has happened

I sniffed the packets between my device and the server and I'm sure a cookie was set in the following format:
Set-Cookie: AppCookie=COOKIEVALUE; expires=Tue, 13 Jul 2021 21:35:00 GMT; path=/; secure; samesite=lax; httponly
After checking the response of CookieStore.GetCookie(), the cookie was missing from the store

Do you have any possible guess of what could've gone wrong?

Thanks in advance,
Niv

Viewing all 79144 articles
Browse latest View live


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