Sending Files to a Xamarin.Forms App – Part 2: Android

Sending Files to a Xamarin.Forms App – Part 2: Android

In the first part of this series – I looked at how to register a Xamarin.Forms app on iOS to receive and display a PDF. In this post I’ll do the same thing – but this time on Android. The Scenario Again the overall scenario we’re talking about here is: We wrote a Xamarin.Forms application. This application is capable of special handling of a specific file type (in the demo app I’m using in this blog post, that’s displaying a PDF file). We want the operating system to know that our app is capable of performing operations on that file type. Thus our app should appear as an option in a list of target apps to send the file to, if the user should so decide. So let’s get to it. Android Registration Much like you use Intents to send data between Activities in Android – you can use Intents to do the same between apps. Explicit vs Implicit Intents When you know the exact Activity you want to open within you app – you create what’s called an Explicit Intent. When instantiating an Explicit Intent – you specify the class type of the Activity that should be started, and then the operating system will start that when the StartActivity() is encountered. Easy enough – but what happens when the developer of the “source app” doesn’t know which Activity should be started, because that Activity is going to reside in a separate application? All the app wants to do is “send” out a notification that it has something it wants to deliver to another app, so that app can...
Sending Files to a Xamarin.Forms App – Part 1: iOS

Sending Files to a Xamarin.Forms App – Part 1: iOS

It’s a common occurrence in mobile applications to have a file be open in one app – but need another app to use it. For example, you browsed to a PDF and find you’d like to perform some modifications to it in another app. By tapping on that PDF, a “Open In” bar will appear across the top of the screen, allowing you to import the file in your desired app. Sending files between apps sounds like a pretty operating system specific feature – something that would best be not attempted in Xamarin.Forms, right? Actually, while it is platform-specific, it’s pretty straight-forward, and the rest of this post will demonstrate how to get it up and running on iOS. (A future post will tackle Android … and if there’s any demand, we’ll cover UWP too.) It should be noted that for this post I am NOT going to speak about creating an app extension to the iOS portion of your Forms solution, and then having your app appear when the user taps the share button (the little rectangle with an arrow coming out of it). For now this is purely about bringing a file into our Forms app – not “sharing” content between apps. Our Scenario The example that we’ll build out in this post is having our Xamarin.Forms app register as capable of opening PDF files and then displaying the PDF file in a WebView. That will demonstrate the basics of registering as being able to open for a file with iOS and a means to open them with Xamarin.Forms (that will be applicable to Android as well)....