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

Wear OS, making webcalls over bluetooth

$
0
0

So I have a wear OS native android application, enabling INTERNET permission, connecting the watch to a WAP, I can make http calls, everything working as expected.
But If the watch having the same WAP connection then turns on Bluetooth, being paired to a phone which in turn connected to the same WAP, my application doesn't work....

I have given the app permission to BLUETOOTH as well, but this solves nothing.

I'm thinking either my only test device, a TICWATCH E, has a bug preventing applications to access the internet when connected with Bluetooth to a phone.
Or I'm doing something, or rather failing to do something in my application.
I'm doing nothing in particular now so might I be failing to do something specific to steer web calls over bluetooth?

Having an application that doesn't work when paired to your phone is worthless...
Please advise.


how to change xamarin.forms Theme programmatically/at runtime

$
0
0

Hey how do i change my Xamarin forms theme at runtime from light to dark etc?
Without overriding my Resources Dictionary?

Missing .sln and .csproj file in when creating a cross platform project

$
0
0

I have VS2017 create a new project for cross platform then follow all steps but .sln and .csproj file are not found .

Hide Home Indicator in Xamarin Forms

$
0
0

I'm not able to set my home indicator to hidden. I have a NavigationPage with ContentPages.
I'm aware that I should override PrefersHomeIndicatorAutoHidden and then call SetNeedsUpdateOfHomeIndicatorAutoHidden(). Doesn't seem to work though.
I also tried ChildViewControllerForHomeIndicatorAutoHidden (see code below) but it doesn't seem to work at all.
What am I doing wrong?

using System.Linq;
using UIKit;
using Xamarin.Forms;
using PageRenderer = MyNamespace.PageRenderer;
using NavigationRenderer = MyNamespace.NavigationRenderer;

[assembly: ExportRenderer(typeof(ContentPage), typeof(PageRenderer))]
[assembly: ExportRenderer(typeof(NavigationPage), typeof(NavigationRenderer))]
namespace MyNamespace
{
    public class PageRenderer : Xamarin.Forms.Platform.iOS.PageRenderer
    {
        public override bool PrefersHomeIndicatorAutoHidden => true;

        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);
            SetNeedsUpdateOfHomeIndicatorAutoHidden();
        }
    }

    public class NavigationRenderer : Xamarin.Forms.Platform.iOS.NavigationRenderer
    {
        public override bool PrefersHomeIndicatorAutoHidden => true;

        public override UIViewController ChildViewControllerForHomeIndicatorAutoHidden
        {
            get
            {
                return ViewControllers.Any() ? ViewControllers.Last() : TopViewController;
            }
        }

        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);
            SetNeedsUpdateOfHomeIndicatorAutoHidden();
        }
    }
}

How TO Design a Chat Application Like WhatsApp?

$
0
0

I am Trying to design a Chat App where i can share Audio,Video,Documents and Using websockets,Firebase.
Any Suggestion please?

Background color of "ActionBar"/"Toolbar v7" with FormsAppCompatActivity

$
0
0

Hi there,

I finally figured out I should migrate from FormsApplicationActivity to FormsAppCompatActivity. After doing that and adapting a few configuration options here and there, my theme is now as follows:

  <style name="CustomTheme" parent="CustomTheme.Base">
  </style>

  <style name="CustomTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="windowNoTitle">true</item>
    <!-- We will be using the toolbar so no need to show ActionBar -->
    <item name="windowActionBar">false</item>

    <!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette-->
    <!-- colorPrimary is used for the default action bar background -->
    <item name="colorPrimary">@color/primary</item>
    <!-- colorPrimaryDark is used for the status bar -->
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <!-- colorAccent is used as the default value for colorControlActivated
         which is used to tint widgets -->
    <item name="colorAccent">@color/accent</item>
    <!-- You can also set colorControlNormal, colorControlActivated
         colorControlHighlight and colorSwitchThumbNormal. -->
    <!--item name="colorControlHighlight">@color/primary_light</item-->
    <!--item name="colorControlActivated">@color/primary_light</item-->
    <!--item name="colorLongPressedHighlight">@color/listitem_longpressed</item-->
  </style>

That's dumb but I don't figure out how to get back a dark actionbar:

It does not look dark at all, since it's white background with black text...

Load SVG from PCL by CODE USING FFImageLoading

$
0
0

Hello,

I'm using this package from nugget to display images in SVG :

https://github.com/luberda-molinet/FFImageLoading/wiki

I'm able to load images using xaml from PCL like this:

//using
xmlns:ffimageloadingsvg="clr-namespace:FFImageLoading.Svg.Forms;assembly=FFImageLoading.Svg.Forms">

//my image from resources in PCL

<ffimageloadingsvg:SvgCachedImage WidthRequest="75" HeightRequest="93" Source="resource://MyProject.Resources.MenuLogo.svg" Margin="0,0,0,50" />

Also I'm able to load images by code from a URL like this:

              map = new SvgCachedImage()
                     {
                         DownsampleToViewSize = true,
                         DownsampleWidth = Width,
                         RetryCount = 0,
                         RetryDelay = 250,
                      Source = SvgImageSource.FromUri(new Uri("https://a/simple/web/formaps/1/12_Mapa_Path.svg"))
                     };

The problem happens when I try to load an image from PCL by code :

        var logo = new SvgCachedImage()
        {
            DownsampleToViewSize = true,
            DownsampleWidth = Width,

        };

I have tried to use different sources but:

Source = SvgImageSource.FromFile("MenuLogo.svg") // No errors but does not display anything 

Source = Xamarin.Forms.ImageSource.FromResource("MenuLogo.svg")// Like if it was a normal loading but nothing is displayed

Source = SvgImageSource.FromResource("MyProject.Resources.MenuLogo.svg") // Cannot implicitly convert type 'FFImageLoading.Work.ImageSource' to 'Xamarin.forms.ImageSource'

I don´t know what I'm doing wrong, and I have not found any documentation to load PCL svg by code.

Anyone with the same problem or somebody could help me ?

Thankyou, sorry about my English :smiley:

how to update location in xamarin forms in pcl project

$
0
0

i used geolocator for current location but location not update please share me the code if have


The "LinkAssemblies" task failed unexpectedly error while building the application

$
0
0

Hi,

I'm getting the below error while building the application using linking SDK assemblies option and with out shared runtime (as shared run time causing error while release the application.)


Severity Code Description Project File Line Suppression State
Error The "LinkAssemblies" task failed unexpectedly.
Mono.Linker.MarkException: Error processing method: 'System.Void System.Net.Http.HttpClientHandler/c__async0::MoveNext()' in assembly: 'System.Net.Http.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.Void System.Net.WebHeaderCollection::AddValue(System.String,System.String)
at Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod(MethodReference reference)
at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference)
at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction)
at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
at Mono.Linker.Steps.MarkStep.ProcessQueue()
--- End of inner exception stack trace ---
at Mono.Linker.Steps.MarkStep.ProcessQueue()
at Mono.Linker.Steps.MarkStep.Process()
at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
at Mono.Linker.Pipeline.Process(LinkContext context)
at MonoDroid.Tuner.Linker.Process(LinkerOptions options, LinkContext& context)
at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
at Xamarin.Android.Tasks.LinkAssemblies.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() D:\Program Files\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets 1577

if shared runtime option is unchecked and link option none httpclient.GetStringAsync() method will raise the following error
Method 'System.Net.WebHeaderCollection.AddValue' not found.

but application is working fine when the shared runtime option is ticked and 'SDK assemblies only' link option selected in the android options tab.
I could find lot of similar threads but couldn't find any solution for this one.

Thanks,
Eins

System.Net.WebException: An SSL error has occurred and a secure connection to the server...

$
0
0

Already found the same thread here, but that not resolved my problem.

I have added NSAppTransportSecurity and NSAllowsArbitraryLoads in info.plist.

Screenshot:

enter image description here

Added the below codes from this article.

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSExceptionDomains</key>
        <dict>
            <key>pm-admin.smartwcm.com</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSExceptionAllowInsecureHTTPSLoads</key>
                <true/>
                <key>NSExceptionRequiresForwardSecrecy</key>
                <true/>
                <key>NSExceptionMinimumTLSVersion</key>
                <string>TLSv1.1</string>
                <key>NSThirdPartyExceptionAllowInsecureHTTPSLoads</key>
                <false/>
                <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
                <true/>
                <key>NSThirdPartyExceptionMinimumTLSVersion</key>
                <string>TLSv1.1</string>
                <key>NSRequiresCertificateTransparency</key>
                <false/>
            </dict>
        </dict>
    </dict>

I am using HTTP REST APIs. When running the project I am getting the following exception:

System.Net.WebException: An SSL error has occurred and a secure connection to the server cannot be made. ---> Foundation.NSErrorException: Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo={NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?

Am I missing something or do anything wrong?

Archiving, .apk is missing the application icon?

$
0
0

I have a Xamarin project with custom icon for my app. Icon works correctly when deploying to device from Visual Studio, but when I create an .apk file with Archive functionality, I get the default icon instead of my icon.

Icon is defined ( "@drawable/icon" ) in manifest, project settings and MainActivity.

Are there some extra steps/configurations that I need so that correct icon is placed in the .apk?

I'm running Xamarin 4.12.3.78

Getting screen contents height

$
0
0

Hello, I am trying to create my own pan and pinch gestures so I can understand how they work, however I am having some problems finding the boundaries for the dragging. I currently use the ScreenHeight and Contents.Height to find boundaries, however I believe having tabs and a navigation bar are affecting my panning, to where I can't pan all the way to the bottom. Is there a way to get the "usable" content heights that the user sees? I don't care for the tabs and navigation.

Statically registering a Broadcast Receiver - A working example

$
0
0

Hello there

I wan't to statically register a Broadcast Receiver and I have followed the guidelines at
https://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/broadcast-receivers

As I understand we do not register the Broadcast Receiver directly in the Android Manifest file, but instead we decorate our receiver as following

[BroadcastReceiver(Enabled = true)]
[IntentFilter(new[] { "com.xamarin.example.TEST" })]
public class MySampleBroadcastReceiver : BroadcastReceiver
{
    public override void OnReceive(Context context, Intent intent)
    {
        Console.WriteLine("Hurray it works"!);
    }
}

Then the receiver should be able to pick up on the following broadcast

Intent message = new Intent("com.xamarin.example.TEST");
SendBroadcast(message);

However I do not receive this intent. I only receive the intent, when I register the receiver within the context as following

RegisterReceiver(new MySampleBroadcastReceiver(), new IntentFilter("com.xamarin.example.TEST"));

Have I misunderstood something or am I missing some steps? Any help would be appreciated.

Why do I need this?
My goal is to launch notifications at particular timestamps defined by the user. I've context-registered a broadcast receiver, that issues a notification, when an intent is received. The Android Alarm Manager is used to broadcast the intent at a particular time.
As the broadcast receiver is context-registered it will not receive intents, when the app has been killed (when the app is swiped in the recent applications menu). I want the notifications to keep coming when the app has been swiped.

Custom ScrollView renderer does not work scroll

$
0
0

I create custom ScrollView.
This is done so that the swipes and scrolls work.
I need to make a vertical scroll.
Help me please

`
public class GestureScrollView : ScrollView
{
public event EventHandler SwipeDown;
public event EventHandler SwipeTop;
public event EventHandler SwipeLeft;
public event EventHandler SwipeRight;

    public void OnSwipeDown() =>
        SwipeDown?.Invoke(this, null);

    public void OnSwipeTop() =>
        SwipeTop?.Invoke(this, null);

    public void OnSwipeLeft()
    {
        SwipeLeft?.Invoke(this, null);
    }

    public void OnSwipeRight()
    {
        SwipeRight?.Invoke(this, null);
    }
}`

Android

`[assembly: ExportRenderer(typeof(GestureScrollView), typeof(Swipe.Droid.Platform.Renderers.GestureScrollViewRenderer))]
namespace Swipe.Droid.Platform.Renderers
{
public class GestureScrollViewRenderer : ScrollViewRenderer
{
readonly CustomGestureListener _listener;
readonly GestureDetector _detector;

    public GestureScrollViewRenderer(Context context) : base(context)
    {
        _listener = new CustomGestureListener();
        _detector = new GestureDetector(context, _listener);
    }

    public override bool DispatchTouchEvent(MotionEvent e)
    {
        if (_detector != null)
        {
            _detector.OnTouchEvent(e);
            base.DispatchTouchEvent(e);
            return true;
        }
        return base.DispatchTouchEvent(e);
    }

    public override bool OnTouchEvent(MotionEvent ev)
    {
        base.OnTouchEvent(ev);

        if (_detector != null)
            return _detector.OnTouchEvent(ev);

        return false;
    }

    protected override void OnElementChanged(VisualElementChangedEventArgs e)
    {
        base.OnElementChanged(e);

        if (e.NewElement == null)
        {
            this.GenericMotion -= HandleGenericMotion;
            this.Touch -= HandleTouch;
            _listener.OnSwipeLeft -= HandleOnSwipeLeft;
            _listener.OnSwipeRight -= HandleOnSwipeRight;
            _listener.OnSwipeTop -= HandleOnSwipeTop;
            _listener.OnSwipeDown -= HandleOnSwipeDown;
        }

        if (e.OldElement == null)
        {
            this.GenericMotion += HandleGenericMotion;
            this.Touch += HandleTouch;
            _listener.OnSwipeLeft += HandleOnSwipeLeft;
            _listener.OnSwipeRight += HandleOnSwipeRight;
            _listener.OnSwipeTop += HandleOnSwipeTop;
            _listener.OnSwipeDown += HandleOnSwipeDown;
        }
    }

    void HandleTouch(object sender, TouchEventArgs e)
    {
        _detector.OnTouchEvent(e.Event);
    }

    void HandleGenericMotion(object sender, GenericMotionEventArgs e)
    {
        _detector.OnTouchEvent(e.Event);
    }

    void HandleOnSwipeLeft(object sender, EventArgs e)
    {
        var _gi = (GestureScrollView)this.Element;
        _gi.OnSwipeLeft();
    }

    void HandleOnSwipeRight(object sender, EventArgs e)
    {
        var _gi = (GestureScrollView)this.Element;
        _gi.OnSwipeRight();
    }

    void HandleOnSwipeTop(object sender, EventArgs e)
    {
        var _gi = (GestureScrollView)this.Element;
        _gi.OnSwipeTop();
    }

    void HandleOnSwipeDown(object sender, EventArgs e)
    {
        var _gi = (GestureScrollView)Element;
        _gi.OnSwipeDown();
    }
}

public class CustomGestureListener : GestureDetector.SimpleOnGestureListener
{
    private static int SWIPE_THRESHOLD = 100;
    static readonly int SWIPE_VELOCITY_THRESHOLD = 100;

    MotionEvent mLastOnDownEvent;

    public event EventHandler OnSwipeDown;
    public event EventHandler OnSwipeTop;
    public event EventHandler OnSwipeLeft;
    public event EventHandler OnSwipeRight;

    public override bool OnScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
    {
        return base.OnScroll(e1, e2, distanceX, distanceY);
    }

    public override bool OnDown(MotionEvent e)
    {
        mLastOnDownEvent = e;

        return true;
    }

    public override bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
    {
        Console.WriteLine("OnFling");

        if (e1 == null)
            e1 = mLastOnDownEvent;

        float diffY = e2.GetY() - e1.GetY();
        float diffX = e2.GetX() - e1.GetX();

        if (Math.Abs(diffX) > Math.Abs(diffY))
        {
            if (Math.Abs(diffX) > SWIPE_THRESHOLD && Math.Abs(velocityX) > SWIPE_VELOCITY_THRESHOLD)
            {
                if (diffX > 0)
                    OnSwipeRight?.Invoke(this, null);
                else
                    OnSwipeLeft?.Invoke(this, null);
            }
        }
        else if (Math.Abs(diffY) > SWIPE_THRESHOLD && Math.Abs(velocityY) > SWIPE_VELOCITY_THRESHOLD)
        {
            if (diffY > 0)
                OnSwipeDown?.Invoke(this, null);
            else
                OnSwipeTop?.Invoke(this, null);
        }

        return base.OnFling(e1, e2, velocityX, velocityY);
    }
}

}`

Xaml:

<ctrl:GestureScrollView x:Name="gi"> ... </ctrl:GestureScrollView>

C#:

`gi.SwipeDown += (s, e) =>
{
DisplayAlert("Gesture Info", "Swipe Down Detected", "OK");
// scroll down
};

        gi.SwipeTop += (s, e) =>
        {
            DisplayAlert("Gesture Info", "Swipe Top Detected", "OK");
            // scroll top
        };

        gi.SwipeLeft += (s, e) =>
        {
            DisplayAlert("Gesture Info", "Swipe Left Detected", "OK");
            ((NewsFeedDetailPageModel)BindingContext).OpenSourceCommand.Execute(null);
        };

        gi.SwipeRight += (s, e) =>
        {
            DisplayAlert("Gesture Info", "Swipe Right Detected", "OK");
            ((NewsFeedDetailPageModel)BindingContext).BackCommand.Execute(null);
        };`

Xamarin forms android - disables SSL CA validation

$
0
0

Hello we are facing a security problem with apk, there's a application validating our apk (Appthority) and reports this:

Disables SSL CA Validation

[
{
"status": "DISABLED",
"hostname": "xxx.xxxxxx-xx.com",
"connection": "10.27.68.128:40326->192.129.240.16:443",
"validation_hostnames": [
]

wa are using https connection for WS and SSL/TLS implementation, and trusted certificate

this only happens with apk but not with ipa

greetings


"AddEntityFrameworkStores can only be called with a role that derives from IdentityRole

$
0
0

I'm trying to run our backend project locally but I'm getting this error: "AddEntityFrameworkStores can only be called with a role that derives from IdentityRole<Tkey, TUserR

I have no idea why, I tried a lot, can anyone help me out?

Any 3rd party comment components that work well for mobile and Xamarin?

$
0
0

Hey all,

Was wondering if there are any 3rd party comment components available for cross platform development. Something like how Disqus or livefyre for blog commenting. If not, can anyone help point me in the direction of some tutorials to learn how to create such a thing that would work with Xamarin.

Thanks CM

How to make the MasterDetail page in iOS slideover the content Page instead of Pushing

$
0
0

How to make the MasterDetail page in iOS slideover the content Page instead of Pushing...?

MasterBehaviour=PopOver is not working

"System.Web.Http.Common" is not compatible with monoandroid81

$
0
0

Hi,

I have a Xamarin project, but I got the following error message. I don't understand because it is the standard library, right ?

Error NU1202 Package System.Web.Http.Common 4.0.20126.16343 is not compatible with monoandroid81 (MonoAndroid,Version=v8.1). Package System.Web.Http.Common 4.0.20126.16343 supports: net40 (.NETFramework,Version=v4.0)
Error NU1202 Package System.Web.Http.Common 4.0.20126.16343 is not compatible with xamarinios10 (Xamarin.iOS,Version=v1.0) / win. Package System.Web.Http.Common 4.0.20126.16343 supports: net40 (.NETFramework,Version=v4.0)

Any idea or recommandation to solve theses issues ?

and what does it mean ? ... does the .net 4 framework is not compatible with Android 8.1 and IoS 10 ?

Thanks

Couldn't open an APK File with NFC

$
0
0

Hi!
At first I want say, that I made many things with C#, but don't have much experience in Xamarin. So please don't kill me if my question is silly. ;)
I have just tried to add NFC in my a Xamarin App. I did it it like there: forums.xamarin.com/discussion/34007/read-information-from-uncontact-card-using-nfc-techonology-on-xamarin
I have written the code nearly exactly like in this post and also created a file named xml under Resources with techlist.xml in it. It all workde fine and I have installed the App on my phone, but I couldn'T open it. I found the App in the App-List, but there wasn't a way to open it. When I tried to launch it in the Android Emulator the App just didn't open. If you need more information please contact me. Thank you very much!

using Android.App;
using Android.Widget;
using Android.OS;
using Android.Nfc;
using System.Text;

namespace NFC
{
    [Activity(Label = "NFC", MainLauncher = false), IntentFilter(new[] { "android.nfc.action.TECH_DISCOVERED"
     },
        Categories = new[] {
    "android.intent.category.DEFAULT"
     })]

    [MetaData("android.nfc.action.TECH_DISCOVERED", Resource =
    "@xml/techlist")]
    public class TransactionActivity : Activity
    {

        protected string TagUid;
        protected override void OnResume()
        {
            base.OnResume();
            SetContentView(Resource.Layout.Main);
            TextView idtext = FindViewById<TextView>(Resource.Id.textView1);
            if (NfcAdapter.ActionTechDiscovered.Equals(Intent.Action))
            {
                var MyTag = Intent.GetParcelableExtra(NfcAdapter.ExtraTag) as Tag;
                if (MyTag != null)
                {
                    var tagId = MyTag.GetId();
                    TagUid = ByteArrayToString(tagId);
                    idtext.Text = TagUid;
               }
            }
        }

        private static string ByteArrayToString(byte[] ba)
        {
            var hex = new StringBuilder(ba.Length * 2);
            foreach (byte b in ba)
                hex.AppendFormat("{0:x2}", b);
            return hex.ToString();
        }
        //  public class MainActivity : Activity
        //  {
        //     protected override void OnCreate(Bundle savedInstanceState)
        //     {
        //     }
        //  }
    }
}
Viewing all 204402 articles
Browse latest View live


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