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

sharing to an app

$
0
0

hi, new to xamarin and just working through some guides. Was just wondering how you would go about allowing another app to share something with it. For instance, how would you get an app on androids 'share' sub-menu or the ios equivalent?

thanks


Symfony API : Impossible to upload a picture

$
0
0

Hello,

I use an HttpClient with the Media plugin and the last version of Xamarin.Forms.

This is my code :
public async Task UploadFilesToServer(string address, byte[] file)
{
MultipartFormDataContent content = new MultipartFormDataContent();
ByteArrayContent baContent = new ByteArrayContent(file);
baContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
baContent.Headers.ContentDisposition.Parameters.Add(new NameValueHeaderValue("name", "\"media[file]\""));
baContent.Headers.ContentDisposition.Parameters.Add(new NameValueHeaderValue("filename", "\"image.png\""));
StringContent titleContent = new StringContent("MyTitleText");
content.Add(titleContent, "title");
StringContent descContent = new StringContent("MyDescription");
content.Add(descContent, "description");
content.Add(baContent);

        return await _client.PostAsync(address, content);
    }

My backend :
public function postArticlesAction(Request $request)
{
$uploader = $this->container->get('pm_storage.uploader');
$entityManager = $this->getDoctrine()->getManager();
$user = $this->getUser();
$article = new Article();
$form = $this->createForm(ArticleType::class, $article);

    // Fill form with data sends with request
    $form->submit([
        'title'         => $request->get('title'),
        'description'   => $request->get('description'),
        'media'         => $request->files->get('media')
    ]);

    // Check the validity of data in form
    if(!$form->isValid()) throw new ApiException(Response::HTTP_BAD_REQUEST, 'invalid data request', $form);

    // Add media file into filesystem and get filename generated
    $filename = $uploader->upload($article->getMedia()->getFile());

    // Set new filename provided by filesystem into media part
    $article->getMedia()->setFilename($filename);

    // Persist article in data storage
    $article->setUser($user);
    $entityManager->persist($article);
    $entityManager->flush();


    // Create view used when service succeed
    $view = View::create(null, Response::HTTP_CREATED);
    $view->setLocation('http://{hostname}/{entrypoint}/articles/' . $article->getId());

    return $view;
}

On any browser, the XHR look like :
------WebKitFormBoundary1aF5eiFQb8xX____(hidden chars)
Content-Disposition: form-data; name="title"

MyTitleText
------WebKitFormBoundary1aF5eiFQb8xX____(hidden chars)
Content-Disposition: form-data; name="description"

MyDescription
------WebKitFormBoundary1aF5eiFQb8xX____(hidden chars)
Content-Disposition: form-data; name="media[file]"; filename="image.png"
Content-Type: image/png

------WebKitFormBoundary1aF5eiFQb8xX____(hidden chars)--

How can I send the ByteArrayContent correctly ?

Regards

Enable bluetooth automatically when application launches should be pair the near by devices

$
0
0

Hi i am new to the xamarin form.I have one challenge that when we deployed one basic application on android mobile,when we try to open that application the bluetooth in our mobile should be enabled automatically and pair the device which are very near ,the main thing the application should allow share the information from present app to the device which are connected. this is my challenge please help me .......

ContentPage Toolbar; can there be a caption?

$
0
0

I have a ContentPage where I have added a ToolbarItem and that works perfectly; shows an icon at the top right-hand corner.

I need to display some text though at the top of the screen and just to the left of that icon would be a perfect place for that but I can't seem to find how to do that. Adding Text="blah" doesn't do it.

Scroll when entering

$
0
0

Hi. I need do that when enter fields I can scroll my page because i entering filed and can't select next field. How can I do it?

SignalR component

$
0
0

Hi all,

I am on the verge of implementing the SingalR client into my Android app, but I can't find the component in the store.

On github it states:
Added support for MonoTouch and MonoDroid components. For more information on how to use them see Using Xamarin Components.
These components will ship in the Xamarin Store when SignalR 2.0 is RTW.

I also see these branches coming by:
https://github.com/SignalR/SignalR/tree/xamarin-package

But where is the actual package? Do I have to get a copy from Github? Is that the stable 2.0 release?

Issues with switching focus in Entry.Completed event handler

$
0
0

I have a simple login form with the XAML layout: two entries for username and password and a login button. My application runs on an Android device equipped with a hardware keyboard. The main functionality of the form is to allow the user to key in the username, press Enter key on the hardware keyboard, key in the password, press Enter again, and then finish the login process.

To achieve that, the form must be capable of the following:

  • setting focus to the Username entry upon appearing on the screen;
  • responding to the hardware Enter key by switching focus to the next control.

The first part works fine: the form sets the focus to the UserName entry upon appearing on the screen. However, when I press the hardware Enter key, the focus switches to the button, instead of switching to the next entry. This is the sequence of events occurring on the form:

txtUserName: 'focused' // the form sets the initial focus in OnAppearing()
txtUserName: 'unfocused' // these two lines is the response to the hardware Enter key pressed while focus is in txtUserName
txtUserName: 'completed'
txtPassword: 'focused' // the forms switches the focus to txtPassword following the code in txtUserName_Completed()
txtPassword: 'unfocused' // txtPassword immediately loses focus; this is an unexpected behavior
btnLogin: 'focused' // focus is now on the button

What am I doing wrong? What is the correct way of manipulating focus in the scenario I described?

This is my form.

XAML layout:

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

      <StackLayout>
        <Entry x:Name="txtUserName" />

        <Entry x:Name="txtPassword" />

        <Button x:Name="btnLogin" Text="Login" />
      </StackLayout>

    </ContentPage>

... and the code-behind file:

using System;
using Xamarin.Forms;

namespace TestFocus
{
    public partial class LoginPage : ContentPage
    {
        public LoginPage()
        {
            InitializeComponent();

            txtUserName.Completed += txtUserName_Completed;
        }

        protected override void OnAppearing()
        {
            base.OnAppearing();

            txtUserName.Focus();
        }

        private void txtUserName_Completed(object sender, EventArgs e)
        {
            txtPassword.Focus();
        }
    }
}

RunOnUiThread startactivity

$
0
0

hubProxy.On("KullaniciDogrula", (_giren_kullanici) =>
{
RunOnUiThread(() =>
{
StartActivity(typeof(MainActivity));
if (_giren_kullanici == "doğrulandı")
{
StartActivity(typeof(MainActivity));
Toast.MakeText(this, "doğrulandı" + _giren_kullanici, ToastLength.Long).Show();
}
else
{
Toast.MakeText(this, "hatalı:" + _giren_kullanici, ToastLength.Long).Show();
}
Toast.MakeText(this, "durum:" + _giren_kullanici, ToastLength.Long).Show();
});
});

I can not start an activity if the incoming character is "correct"


How to get a persistent reference to a keychain item for VPN usage?

$
0
0

Hello,

I'm currently trying to establish a custom VPN connection via the Network Extension Library (NEVpnManager).
After reading and trying a lot, it works like a charm with one big issue I can't get fixed:
The NEVpnProtocol can receive a reference to a password that is stored in the apps keychain so that the user doesn't have to enter the password every time he logs in. No matter what I do, the user has to enter a password, or I can't save the NEVpnManager Settings.
As you can see here NEVpnProtocol.PasswordReference needs a persistent reference to work, otherwise it won't work.
Sadly I don't completely understand the objectC Code behind this link, that's probably why I can't get this to work with Xamarin.

In every Keychain example for Xamarin I found SecKeyChain.QueryAsRecord is used, however I found out that there's also the SecKeyChain.QueryAsData method, which can receive a parameter "wantPersistentReference". That should probably do the trick, but when I use this method I can't save the NEVpnManager settings:

Error Domain=NEVPNErrorDomain Code=5 "IPC failed" UserInfo={NSLocalizedDescription=IPC failed}

IPC probably means Inter Process Communication, allowing different processes to communicate, so I think my problem is that the NEVpnManager can't read the password because it is "persistent".

Is it possible to store and receive the log-in details in a way so that this works like intended ( = user won't be asked for a password)?
Any help is appreaciated, thank you in advance.

The sources I used to create this code:
Establish VPN Connection:
http://ramezanpour.net/post/2014/08/03/configure-and-manage-vpn-connections-programmatically-in-ios-8/
Apple KeyChain Concept:
https://developer.apple.com/library/mac/documentation/Security/Conceptual/keychainServConcepts/02concepts/concepts.html
Xamarin KeyChain Example:
https://github.com/xamarin/monotouch-samples/tree/master/Keychain
Persistent KeyChain iOS:
http://ramezanpour.net/post/2014/09/26/how-to-get-persistent-references-to-keychain-items-in-ios/

Finally, here my complete code, with the code not working ("IPC failed error") and the code working but with a password prompt (in comments).
Please note that in this stage of the coding process the user can't choose a username / password.
Usage of the code:
1) Create VPNServiceIOS object
2) SaveVPNConfig
3) StartVPNConnection
4) StopVPNConnection()

public class VPNServiceIOS : IVPNService
    {
        private NEVpnManager manager;


    public VPNServiceIOS ()
    {
        manager = NEVpnManager.SharedManager;

        var s = new SecRecord (SecKind.GenericPassword) {
            Label = "VPNTest",
            Description = "Item description",
            Account = "MYACCOUNTNAME",
            Service = "VPNService",
            Comment = "Your comment here",
            ValueData = NSData.FromString ("MYPASSWORD", NSStringEncoding.UTF8),
            Generic = NSData.FromString ("VPNPas", NSStringEncoding.UTF8),
        };

        var err = SecKeyChain.Add (s);
        if (err != SecStatusCode.Success && err != SecStatusCode.DuplicateItem) {
            Console.WriteLine ("Password not in Keychain:");
            Console.WriteLine (err.ToString ());
        }
    }

    public void StartVPNConnection ()
    {
        manager.LoadFromPreferences (error => {
            if (error != null) {
                Console.WriteLine ("Cant load VPN settings: ");
                Console.WriteLine (error.ToString ());
            }
        });
        NSError error2 = new NSError ();
        manager.Connection.StartVpnTunnel (out error2);
        if (error2 != null) {
            Console.WriteLine ("Cant establish connection:");
            Console.WriteLine (error2.ToString ());
        }
    }

    public void StopVPNConnection ()
    {
        manager.Connection.StopVpnTunnel ();
    }

    public void SaveVPNConfig (string type, string description, string server, string remoteIdentifier, string localIdentifier, string username)
    {
        manager.LoadFromPreferences (error => {
            if (error != null) {
                Console.WriteLine ("Cant load VPN Settings: ");
                Console.WriteLine (error);
            } else {
                NEVpnProtocol p = null;
                switch (type) {
                case "IKEv2":
                    NEVpnProtocolIke2 ike2 = new NEVpnProtocolIke2 ();
                    ike2.AuthenticationMethod = NEVpnIkeAuthenticationMethod.None;
                    ike2.LocalIdentifier = localIdentifier;
                    ike2.RemoteIdentifier = remoteIdentifier;
                    ike2.UseExtendedAuthentication = true;
                    ike2.DisconnectOnSleep = false;
                    p = ike2;
                    break;
                default:
                    Console.WriteLine ("unknown Protocol!");
                    break;
                }
                p.Username = username;
                p.ServerAddress = server;

                manager.LocalizedDescription = description;

                var s = new SecRecord (SecKind.GenericPassword) {
                    Account = "MYACCOUNTNAME",
                    Generic = NSData.FromString ("VPNPas", NSStringEncoding.UTF8)
                };

// CODE NOT WORKING:
                    SecStatusCode res;
                    var match = SecKeyChain.QueryAsData(s, true, out res);
                    if (res == SecStatusCode.Success){
                        p.PasswordReference = match;
                    }
                    else {
                        Console.WriteLine (res);
                    }

// CODE WORKING but only with password prompt:
//                    SecStatusCode res;
//                    var match = SecKeyChain.QueryAsRecord(s, out res);
//                    if (res == SecStatusCode.Success){
//                        p.PasswordReference = match.ValueData;
//                    }
//                    else {
//                        Console.WriteLine (res);
//                    }

                manager.ProtocolConfiguration = p;
                manager.OnDemandEnabled = false;

                manager.SaveToPreferences (error2 => {
                    if (error2 != null) {
                        Console.WriteLine ("Cant save manager settings:");
                        Console.WriteLine (error2.Code);
                        Console.WriteLine (error2.DebugDescription);
                        Console.WriteLine (error2.Description);
                        Console.WriteLine (error2.Domain);
                        Console.WriteLine (error2.HelpAnchor);
                        Console.WriteLine (error2.LocalizedDescription);
                        Console.WriteLine (error2.LocalizedFailureReason);
                        Console.WriteLine (error2.LocalizedRecoverySuggestion);
                    }
                });
            }
        });
    }

    public void DeleteVPNConfig ()
    {
        manager.RemoveFromPreferences ((NSError error) => {
            if (error != null) {
                Console.WriteLine ("Cant delete VPN Config:");
                Console.WriteLine (error.ToString ());
            } else {
                isConnected = false;
            }
        });
    }
}

getting width of View when making custom renderer for Android TableLayout

$
0
0

Hi, I'm making a custom renderer for Android TableLayout.
What I want to do is that making TextView's backgound which has width size proportional to TextView's width size.

Here is the sample code.

FrameLayout frame = new FrameLayout(Context);
TextView textView = new TextView(Context);
Android.Views.View background = new Android.Views.View(Context);

textView.Text = "HI";
frame.AddView(textView, LayoutParams.MatchParent, LayoutParams.WrapContent);

background.SetBackgroundResource(Resource.Drawable.Border);
frame.AddView(background, LayoutParams.MatchParent, LayoutParams.WrapContent);

Here, I want to change the width size(LayoutParams.MatchParent in frame.AddView(background, LayoutParams.MatchParent, LayoutParams.WrapContent)) to certain value that proportional to width size of textView.

eg. if an width of textView is 10, I want to set the width of background as 4.

But if I try to getting width value of textView by textView.Width, the value is 0.

So, I don't know how to get the value of width of View, in this case TextView.

please give me some idea.

Error inflating class android.support.v7.widget.Toolbar after updaring to v7.AppCompat Version 23.3

$
0
0

I am creating a Xamarin Forms Project and using android.support.v7.widget.Toolbar with FormsAppCompatActivity. The code I'm posting below was working with Xamarin.Android.Support.v7.AppCompat Version: 23.0.1.3

But after I upgraded to 23.3.0 this has started throwing Android.Views.InflateException: Binary XML file line #1: Error inflating class android.support.v7.widget.toolbar exception.

Here is my code for MainActivity

[Activity(Label = "AppMob.Client", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {

        protected override void OnCreate(Bundle bundle)
        {
            FormsAppCompatActivity.ToolbarResource = Resource.Layout.toolbar;
            FormsAppCompatActivity.TabLayoutResource = Resource.Layout.tabs;

            base.OnCreate(bundle);

            global::Xamarin.Forms.Forms.Init(this, bundle);

            Xamarin.FormsMaps.Init(this,bundle);
            GoogleAnalyticsHelper.GetGASInstance().Initialize_NativeGAS(Application.Context);  //For GA initialization
            LoadApplication(new App());
        }
}

This is my code for Resource.Layout.toolbar

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:layout_scrollFlags="scroll|enterAlways" />

Crash in native code Android 6

$
0
0

Hello,
we are getting crashes with Android 6.0.
Thanks for help
Jan Rosa


Build fingerprint: 'samsung/heroltexx/herolte:6.0.1/MMB29K/G930FXXU1BPLM:user/release-keys'
Revision: '8'
ABI: 'arm64'
pid: 14278, tid: 14351, name: Threadpool work >>> cz.freshflow.app <<<
signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
Abort message: '* Assertion at /Users/builder/data/lanes/3511/77cb8568/source/mono/mono/mini/mini-arm64.c:937, condition `arm_is_bl_disp ((code), (target))' not met
'
x0 0000000000000000 x1 000000000000380f x2 0000000000000006 x3 0000000000000000
x4 0000000000000000 x5 0000000000000001 x6 0000000000000000 x7 0000000000000000
x8 0000000000000083 x9 fefefefefefefeff x10 7f7f7f7f7f7f7f7f x11 0101010101010101
x12 0000000000000028 x13 0000007f870daf9c x14 0000000000000001 x15 0000000000000001
x16 0000007fa605d568 x17 0000007fa5ff03b8 x18 0000007fa63fd720 x19 0000007f870de500
x20 0000007f870de440 x21 0000000000000002 x22 0000000000000006 x23 0000007f7f7f4490
x24 0000007f86af2abc x25 0000007f85ce2d40 x26 0000007f8b197000 x27 0000000000000000
x28 0000000000000007 x29 0000007f870daf40 x30 0000007fa5fedb54
sp 0000007f870daf40 pc 0000007fa5ff03c0 pstate 0000000020000000

backtrace:
#00 pc 00000000000693c0 /system/lib64/libc.so (tgkill+8)
#01 pc 0000000000066b50 /system/lib64/libc.so (pthread_kill+68)
#02 pc 0000000000023990 /system/lib64/libc.so (raise+28)
#03 pc 000000000001e2c0 /system/lib64/libc.so (abort+60)
#04 pc 000000000021e1b0 /data/app/cz.freshflow.app-1/lib/arm64/libmonosgen-2.0.so

portable-net45+sl5+win8+wpa81+wp8 and xamarinmac20

$
0
0

Hi, I am trying to install SignalR via nuget to a xamarinmac20 app/library and it is failing. It is failing because Xamarin Studio does not recognize 'portable-net45+sl5+win8+wpa81+wp8' as valid for adding into Xamarin Mac Mobile Framework. However, this should be supportable since it is Profile 344, and you can create a Profile 344 PCL and add it as a reference to a xamarinmac20. A workaround is to change the nuspec to target netstandard11, but 'portable-net45+sl5+win8+wpa81+wp8' is a subset of netstandard11 and should work out of the box.

Please help!

Can you use SkiaSharp to DrawPath to an image\bitmap that can then be emailed?

$
0
0

PCL. Currently doing Canvas.DrawPath and DrawText to SKCanvasView, works fine. Now, I am trying to find out if I can capture the this image (which is basically the entire screen) for attaching to an email.

Home buton and fragment

$
0
0

I would like to know why for exemple if i have 2 fragment. When the application start im on fragment 1 but i click on menu to fragment 2 then i press home button i go back to my app and the app display the fragment 1 ? Why it do not stay in fragment 2 ? i mean this is probably due to the fact that when i press home button the activity go on onpause -> onstop then i go back on the activity and oncreate is call again but how can i make that the applicvaiton ill remember the last fragment that i was on


Add-in Manager Repositories Broken in 6.1.5

$
0
0

Went to update some add-ins using the latest stable version of Xamarin Studio (6.1.5) and found the repositories not working.

Reproduce steps: Xamarin Studio -> Add-ins... -> Update or Gallery tabs -> Refresh

Error:

Repositories:

Max length on Entry

$
0
0

Is there a way to limit the length of text in an Entry control? If not, is it planned to add this feature?

Does Xamarin support iPod Touch and Indoor Positioning System

$
0
0

Hi,
I have requirement to support iPod Touch as a part of cross platform native Xamarin application. Application should use Indoor Positioning System using wifi triangulation or any other approach to locate and map objects.

  • Does Xamarin platform support iPod Touch, if So what are the Pros and Cons, Challenges while implementing solution and also how to test using Xamarin studio?
  • Does iPod touch can be used for Indoor Positioning System and How to achieve it using Xamarin platform like using wifi triangulation or any other third party sdks(please suggest)?
  • Can ipod Touch camera can be used to capture and process images like to read QR code etc. Please suggest any third party api's

Thanks,
Phani

No Android emulators found to run/debug against

$
0
0

I ran out of drive space on my Win8.1 machine and was due for new hardware, so I started from scratch this week. Installed Win10, VS 2015 Pro update 3, Xamarin, and Android SDKs all appear intact. I created a WebView App and went to debug against it when I noticed, there are no emulators appearing in my drop down on my new PC. I checked the Tools -> Options -> Xamarin and assured all paths were correct/connected for JDK, Android SDK and Android NDK.
When I click on Start (my only option since no emulators appear), I get "There were deployment errors. Continue?" but nothing happens. No errors, one warning, "Xamarin Android Player is not installed. Click here to install.". I do not recall having to install this on my Win8.1 machine yet I was able to see emulators for whatever versions of Android I had installed. Is this Android Player mandatory? I read that it is obsolete. Does anyone know how I get my emulators back?

[I:sdk]: Key HKCU\SOFTWARE\Novell\Mono for Android\AndroidSdkDirectory found:
Path contains adb in \platform-tools (C:\Program Files (x86)\Android\android-sdk).
[I:sdk]: Key HKCU\SOFTWARE\Novell\Mono for Android\AndroidNdkDirectory found:
Path contains ndk-stack in . (C:\ProgramData\Microsoft\AndroidNDK\android-ndk-r11c).
[I:sdk]: Key HKCU\SOFTWARE\Novell\Mono for Android\JavaSdkDirectory found:
Path contains jarsigner.exe in \bin (C:\Program Files\Java\jdk1.8.0_121).
[I:Unknown]: Found Xamarin.Android 7.0.2
[I:Unknown]: Found Android SDK. API levels: 19, 21, 22, 23, 24
[I:]: Tracking android devices started
[D:]: Tracking avd started
[D:]: avd watcher *.ini path: 'C:\Users\xxxxxxx.android\avd'
[D:]: TrackDeviceTask got:
[D:]: avd watcher android path: 'C:\PROGRA~2\Android\ANDROI~1\tools\android.BAT'
[I:]: Got new device list from adb with 0 devices
[D:]: avd watcher: got device list from avd with 1 devices

Xamarin: extract android sqlite to a local folder on the device

$
0
0

Dear all,
I need to export my android sqlite database to a folder on my memory so I can get access to it outside my mobile.
example of use : " I need to take a backup of my database and see what does it contain."
I searched the web and did not found any Xamarin method that works .
anyone have an idea about how to do this?

Viewing all 204402 articles
Browse latest View live


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