Use the Surface Duo SDK with Xamarin
The Surface Duo SDK for Xamarin apps is available from NuGet. Add the correct NuGet for your project type using the instructions below.
Follow these steps to add the Surface Duo SDK to a Xamarin.Forms project:
Open the NuGet Package Manager dialog for your project.
Under the Browse tab, search for
Xamarin.Forms.DualScreen
.Install the
Xamarin.Forms.DualScreen
package into your project.Add the the following initialization method call to the Android project's
MainActivity
class, in theOnCreate
event:Xamarin.Forms.DualScreen.DualScreenService.Init(this);
This method is required for the app to be able to detect changes in the app's state, such as being spanned across two screens.
Update the
Activity
attribute on the Android project'sMainActivity
class, so that it includes all theseConfigurationChanges
options:ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.UiMode
These values are required so that configuration changes and span state can be more reliably reported.
The APIs from the Surface Duo SDK for Xamarin.Forms will be available in the Xamarin.Forms.DualScreen
namespace. The Xamarin.Forms SDK consists of two parts:
Follow these steps to add the Surface Duo SDK to a Xamarin.Android project:
- Open the NuGet Package Manager dialog for your project.
- Under the Browse tab, search for
Xamarin.DuoSdk
. - Install the
Xamarin.DuoSdk
package into your project.
You can review the Microsoft dual-screen SDK reference. The APIs from the Surface Duo SDK for Xamarin are available in the Microsoft.Device.Display
namespace.
Visit the Xamarin samples to see examples of the SDK for both Xamarin.Forms and Xamarin.Android.