Xamarin: Mobile Leaders Podcast | Enterprise Mobility Trends with Maribel Lopez: Where Are Things Headed?

Today we’re excited to launch a new podcast focused on helping you achieve success with your mobile initiatives faster. On the Mobile Leaders Podcast, we’ll gather different perspectives and experiences from industry analysts and veterans, plus mobile leaders from organizations both big and small. In today’s episode, Xamarin’s Steve Hall and I discuss the latest […]

The post Mobile Leaders Podcast | Enterprise Mobility Trends with Maribel Lopez: Where Are Things Headed? appeared first on Xamarin Blog.

Details

Xamarin: Easier App Debugging with Xamarin Studio Run Configurations

When building apps, we often want to run our application under varying conditions. Whether this is something simple like altering environmental variables, or something a bit more complex like changing the startup Activity or service for an Android app, changing your project’s settings to switch between configurations can be tedious, especially if you change between […]

The post Easier App Debugging with Xamarin Studio Run Configurations appeared first on Xamarin Blog.

Details

Xamarin: Xamarin and Visual Studio at Future Decoded

Don’t miss the Visual Studio and Xamarin teams at this year’s Future Decoded event at London’s ExCeL center. Day One is the “business day,” where organizations can find out how embracing the power of digital transformation can propel them into a brighter future, while Day Two is for the technical crowd, with a focus is […]

The post Xamarin and Visual Studio at Future Decoded appeared first on Xamarin Blog.

Details

Daniel Cazzulino: Leveraging Azure Functions for MIT AppInventor Web Interactions

I’m contributing a few hours a week on Fridays to tutor kids on programming and a bit of electronics,
in what we call a “Geeks’ School” (or Escuela de Geeks). I’m always
exploring ways to make it more interesting for kids (12-16yo) to learn programming. I found out that
given that the cellphone (mostly Androids here in Argentina) is their primary computing device, they
were instantly hooked to the MIT AppInventor 2 platform.

We’re actually using Thunkable,
a fork of the original MIT AI2 that provides a nicer Material Design UI and sleeker looking client/companion
app for the device. Kids have even interacted via chat directly with the site owners, which was a blast!

One of the kids wanted to build a translating app that would:

  1. Accept spoken spanish input
  2. Recognize the text and send it to a web api for translation
  3. Get the translated text and have the app speak it out loud

The speech recognition and
text-to-speech parts were very
straightforward involving just a couple built-in blocks with simple input-output connectors:

speech recognition block and text-to-speech

Plugging a Web component in-between the recognized (Spanish in this case) text in
when speech.After Getting Text and the call to call tts.Speak proved quite
challenging. To be clear, invoking web services by issuing POSTs and GETs is as easy
as anything else: just drop the non-visual Web component
on the designer and just call it from the blocks view. That’s the easy part. But the
key thing in invoking web services is processing its output, of course 😉

Most web APIs nowadays return plain JSON, and a quick search around
the web for how to parse
and consume JSON from an app
yielded some very scary looking
massive amount of blocks for something that is just a couple lines of code in any modern
programming language.

Azure Functions to the rescue

So I remembered the Build Conference introduction of Azure Functions
and chatting with the team at their booth, as well as
Scott’s great introduction to Serverless Computing and
this seemed like the perfect opportunity to give it a shot.

In short, what I wanted was a way to get a single JSON property value from the response of
Google’s translate API. The request looks like the following:

https://www.googleapis.com/language/translate/v2?q=hola&target=en&format=text&source=es&key={YOUR_API_KEY} 

And the response:

{
    "data": {
        "translations": [
            {
                "translatedText": "Hello"
            }
        ]
    }
}

It takes literally ONE line of code to retrieve the translatedText using Json.NET:

var result = JObject.Parse(json).SelectToken("data.translations[0].translatedText")

So I went to http://functions.azure.com (love the customized subdomain, as opposed to
navigating the seemingly endless features of Azure in the portal) and created a new
“Function app”.

NOTE: the “function app” is the actual Web API ‘site lite’ that will host the
actual function (or functions). So if you name it like your function, i.e.
parsejson then define the parsejson function, the resulting URL will look
slightly awkward: https://parsejson.azurewebsites.net/api/parsejson

In my case I went for stringify for the function app name, and json for the
function name, which results in a nice looking url https://stringify.azurewebsites.net/api/json

I started directly with from the Or create your own custom function link at the bottom
of the wizard, and chose the HttpTrigger - C# template. Then I wrote the code in a
window without any intellisense (I hope that changes soon ;)) but it was dead-simple. The
whole function that takes POSTed JSON bodies and a “q=[JSON PATH]” argument
for stringifying it is:

#r "Newtonsoft.Json"

using System.Net;
using Newtonsoft.Json.Linq;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    var query = req.GetQueryNameValuePairs()
        .FirstOrDefault(q => string.Compare(q.Key, "q", true) == 0)
        .Value;

    var json = await req.Content.ReadAsStringAsync();

    return string.IsNullOrEmpty(json) || string.IsNullOrEmpty(query) ?
        req.CreateResponse(HttpStatusCode.OK, "") :
        req.CreateResponse(HttpStatusCode.OK, JObject.Parse(json).SelectToken(query).ToString());
}

And of course you can try it out simply from curl:

curl -k -X POST -d "{"data":{"translations":[{"translatedText":"Hello"}]}}" https://stringify.azurewebsites.net/api/json?q=data.translations[0].translatedText

A whole speech to text translation app in less than 20 blocks

And with that, suddenly, interacting with the Web from MIT AppInventor2 or Thunkable is super
straight-forward. The whole program is easy to grasp by any 12yo+ kid:

  1. When the button is clicked, start listening for speech:
    Listen for speech
  2. When speech is recognized, ship it off for translation:
    Translate recognized speech
  3. When translation JSON comes back, ship it off for “stringifying”:
    Parse JSON
  4. When the simple string comes back from “stringify”, speak it out loud:
    Parse JSON

It would have taken that many blocks or more just to parse the JSON response
from the translation Web API. A massive improvement by just using a little bit
of serverless computing to aid in teaching 🙂

For other teachers leveraging MIT AppInventor for the Web, here’s the “documentation”:

  1. Set the stringify Web component’s URL to https://stringify.azurewebsites.net/api/json
  2. Append the path of the JSON value to retrieve as the query string parameter, like ?q=data.translations[0].translatedText
  3. Use a POST Text call passing in the JSON to parse.

NOTE: if you are dealing with a single JSON web response format, the URL of the
stringify Web component can be set statically in the Designer pane and never changed
from blocks, as shown in the above translation example.

I look forward to using Azure Functions a whole lot more. For one, I think I’ll expand the
stringify Azure Fuction app to include an xml and possibly html functions
receiving an XPath expression as the ?q= query string parameter.

Details

Xamarin: Xamarin Developer Events in October

There are some incredible Xamarin mobile developer events happening throughout October, including more Xamarin Dev Days, making it easy to find a local C# or .NET community where you can learn all about how to build mobile apps for iOS, Android, and Windows in C# using Xamarin in Visual Studio. If you are interested in […]

The post Xamarin Developer Events in October appeared first on Xamarin Blog.

Details

Gerald Versluis: Continuous Integration & Continuous Delivery for your Xamarin App – Video edition

This is a talk I did on a local Meetup group about continuous integration and continuous delivery for you Xamarin app. Mainly based on VSTS and HockeyApp but also naming some alternatives like Bitrise, TestFairy, Play Store and the App Store.

Because of time pressure it was a bit of a rush so if you have any questions please let me know!

Details