Plugin 04: FileIO

In continuation to blog posts in this series on plugins, today we’ll cover a plugin/library to perform FileIO.

There are different APIs on different platforms to perform FileIO. Having said that, Xamarin already makes life easier by implementing System.IO which is available in Android and iOS.

Following code can be used in Android to create a file and then read contents from it.FileIO - Android

Similarly, following code can be used in case of iOS application. FileIO - iOS

In case of Windows, using WinRT APIs, the case is little bit different as shown below:FileIO - Windows

Now to make life easier, there is a NuGet from Daniel Plaisted, which can help you to use same code on different platforms. You can find more information about the library from here: https://www.nuget.org/packages/PCLStorage/FileIO - Forms

This way, you can use one code (in C#) across all the three different platforms.

Hope you’re enjoying this series. Do let me know your feedback if you want to include any specific libraries/features.

Namaste
Mayur Tendulkar

Plugin 03: Phone Calling

In continuation to blog posts in this series on plugins, today we’ll cover a plugin to make phone calls.

As we understood before, all platforms support phone calling (just like emailing, texting, etc…) and Xamarin makes it easier with one common language – C#. However, developers still need to learn

In case of Windows Phone, one can initiate a phone call by using following code. In this case, Windows Phone has special class which allow developers to perform this task.

Screenshot 2015-02-23 10.53.12

In case of Android, developers can use ‘Intent’ and ‘URI activation’ to start a new phone call.

Screenshot 2015-02-23 10.56.09

In case of iOS, same concept of URI activation can be applied. As shown below in the code, developers can create a URI with telephone number and it will launch default application to make a phone call.

Screenshot 2015-02-23 11.13.09

Now, in case of Xamarin.Forms developers can use same Messaging Plugin for Xamarin and Windows plugin to implement phone functionality across the platforms.

Screenshot 2015-02-23 12.31.23

This way, developers can utilize the power of plugins to write one code which can work across different platforms, without bothering about underlying APIs.

Namaste
Mayur Tendulkar

Plugin 02: Email Messaging

In previous blog post we’ve seen how we can use plugins to send text messages and use same API across platforms without bothering about individual platform specific APIs. In this blog post we’ll continue to discuss plugins and see how we can send Email messages.

In case of Windows Phone, we can use EmailManager to send EmailMessage. The code will look like:

image.png

For Android, there is no class as such which can handle email messaging. Rather, we use something called as Intent.

image1.png

In case of iOS, we use built-in controller to pass parameters which can populate the email message and later-on send it.

image.png

Now, lets see how we can implement this feature in Xamarin.Forms using Plugins. The plugin which we used last time, is feature rich and also included capability to send emails. Refer Messaging Plugin for Xamarin and Windows in your applications and modify the code as shown below. Depending on the platform on which the code is executing, it will internally call the platform specific APIs.

image.png

Once again, using this plugin it becomes easy to send Email on Android, iOS and Windows Phone.

Namaste
Mayur Tendulkar