-
Notifications
You must be signed in to change notification settings - Fork 237
[essentials] port some more articles #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,95 +1,84 @@ | ||
| --- | ||
| title: "Get Started with Xamarin.Essentials" | ||
| description: "Get started with Xamarin.Essentials, which provides a single cross-platform API that works with any iOS, Android, or UWP application." | ||
| ms.date: 05/11/2020 | ||
| title: "Get Started with Essentials" | ||
| description: "Get started with Essentials in .NET MAUI. Essentials provides a single cross-platform API that your app can use to access device features, operating system functionality, and phone support, among other capabilities." | ||
| ms.date: 08/11/2021 | ||
| no-loc: ["Microsoft.Maui", "Microsoft.Maui.Essentials"] | ||
| --- | ||
|
|
||
| # Get Started with Xamarin.Essentials | ||
| # Get started with .NET MAUI Essentials | ||
|
|
||
| Xamarin.Essentials provides a single cross-platform API that works with any iOS, Android, or UWP application that can be accessed from shared code no matter how the user interface is created. See the [platform & feature support guide](platform-feature-support.md) for more information on supported operating systems. | ||
| .NET Multi-platform App UI (.NET MAUI) Essentials provides a single cross-platform API that works with any iOS, Android, or UWP application. Essentials is accessed from cross-platform friendly code that is ignorant of the platform it's run on. Some APIs do require platform-specific configure or setup, but that's the exception rather than the rule. For more information about platform and operating system support, see [Platform Support](platform-feature-support.md). | ||
adegeo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Installation | ||
| ## Migrating from Xamarin.Forms | ||
|
|
||
| Xamarin.Essentials is available as a NuGet package and is included in every new project in Visual Studio. It can also be added to any existing projects using Visual Studio with the following steps. | ||
| Unlike Xamarin.Forms Essentials, .NET MAUI Essentials is included with .NET MAUI. You're no longer required to install a NuGet package or add reference to the Essentials library. | ||
adegeo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 1. Download and install [Visual Studio](https://visualstudio.microsoft.com/) with the [Visual Studio tools for Xamarin](~/xamarin-forms/get-started/installation/index.md). | ||
| ## Setup | ||
adegeo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 2. Open an existing project, or create a new project using the Blank App template under **Visual Studio C#** (Android, iPhone & iPad, or Cross-Platform). | ||
| .NET MAUI Essentials requires setup on Android. iOS and Windows don't require any setup to enable access to Essentials. | ||
|
|
||
| > [!IMPORTANT] | ||
| > If adding to a UWP project ensure Build 16299 or higher is set in the project properties. | ||
| <!-- markdownlint-disable MD025 --> | ||
| # [Android](#tab/android) | ||
|
|
||
| 3. Add the [**Xamarin.Essentials**](https://www.nuget.org/packages/Xamarin.Essentials/) NuGet package to each project: | ||
| .NET MAUI Essentials supports a minimum Android version of _4.4_, corresponding to _API level 19_, on the client device. But when compiling your project, the target Android version must be _9.0_ or _10.0_, corresponding to _API level 28_ and _API level 29_. | ||
|
|
||
| <!--markdownlint-disable MD023 --> | ||
| # [Visual Studio](#tab/windows) | ||
| - Visual Studio for Windows | ||
|
|
||
| In the Solution Explorer panel, right click on the solution name and select **Manage NuGet Packages**. Search for **Xamarin.Essentials** and install the package into **ALL** projects including Android, iOS, UWP, and .NET Standard libraries. | ||
| These two versions are set in the Android project's properties. Right-click the project node in **Solution Explorer** and choose **Properties**, and navigate to the **Android Manifest** property page. | ||
|
|
||
| # [Visual Studio for Mac](#tab/macos) | ||
| - Visual Studio for Mac | ||
|
|
||
| In the Solution Explorer panel, right click on the project name and select **Add > Add NuGet Packages...**. Search for **Xamarin.Essentials** and install the package into **ALL** projects including Android, iOS, and .NET Standard libraries. | ||
| These two versions are set in the Project Options dialog for the Android project. Double-click the project node in the **Solution** pane, or right-click the project node and then select **Options**, then navigate to the **Android Application** tab. | ||
|
|
||
| ----- | ||
| <!-- TODO: What is still valid in these two paragraphs? --> | ||
adegeo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| When compiling against Android 9.0, Xamarin.Essentials installs version 28.0.0.3 of the Xamarin.Android.Support libraries that it requires. Any other Xamarin.Android.Support libraries that your application requires should also be updated to version 28.0.0.3 using the NuGet package manager. All Xamarin.Android.Support libraries used by your application should be the same, and should be at least version 28.0.0.3. Refer to the [troubleshooting page](troubleshooting.md) if you have issues adding the Xamarin.Essentials NuGet or updating NuGets in your solution. | ||
|
|
||
| 4. Add a reference to Xamarin.Essentials in any C# class to reference the APIs. | ||
| Starting with version 1.5.0 when compiling against Android 10.0, Xamarin.Essentials install AndroidX support libraries that it requires. Read through the [AndroidX documentation](../android/platform/androidx.md) if you have not made the transition yet. | ||
|
|
||
| ```csharp | ||
| using Xamarin.Essentials; | ||
| ``` | ||
| <!-- markdownlint-disable MD001 --> | ||
| ### Configure the MainApplication or Activity | ||
adegeo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <!-- markdownlint-enable MD001 --> | ||
|
|
||
| 5. Xamarin.Essentials requires platform-specific setup: | ||
| In the Android project's `MainApplication` or any `Activity` that is launched, Essentials must be initialized in the `OnCreate` method by calling the `Microsoft.Maui.Essentials.Platform.Init`method: | ||
|
|
||
| # [Android](#tab/android) | ||
|
|
||
| Xamarin.Essentials supports a minimum Android version of 4.4, corresponding to API level 19, but the target Android version for compiling must be 9.0 or 10.0, corresponding to API level 28 and level 29. (In Visual Studio, these two versions are set in the Project Properties dialog for the Android project, in the Android Manifest tab. In Visual Studio for Mac, they're set in the Project Options dialog for the Android project, in the Android Application tab.) | ||
|
|
||
| When compiling against Android 9.0, Xamarin.Essentials installs version 28.0.0.3 of the Xamarin.Android.Support libraries that it requires. Any other Xamarin.Android.Support libraries that your application requires should also be updated to version 28.0.0.3 using the NuGet package manager. All Xamarin.Android.Support libraries used by your application should be the same, and should be at least version 28.0.0.3. Refer to the [troubleshooting page](troubleshooting.md) if you have issues adding the Xamarin.Essentials NuGet or updating NuGets in your solution. | ||
|
|
||
| Starting with version 1.5.0 when compiling against Android 10.0, Xamarin.Essentials install AndroidX support libraries that it requires. Read through the [AndroidX documentation](../android/platform/androidx.md) if you have not made the transition yet. | ||
| ```csharp | ||
| public class MainActivity : MauiAppCompatActivity | ||
| { | ||
| protected override void OnCreate(Bundle savedInstanceState) | ||
| { | ||
| base.OnCreate(savedInstanceState); | ||
| Microsoft.Maui.Essentials.Platform.Init(this, savedInstanceState); | ||
| } | ||
|
|
||
| In the Android project's `MainLauncher` or any `Activity` that is launched, Xamarin.Essentials must be initialized in the `OnCreate` method: | ||
| // ... Other code ... | ||
| } | ||
| ``` | ||
|
|
||
| ```csharp | ||
| protected override void OnCreate(Bundle savedInstanceState) { | ||
| //... | ||
| base.OnCreate(savedInstanceState); | ||
| Xamarin.Essentials.Platform.Init(this, savedInstanceState); // add this line to your code, it may also be called: bundle | ||
| //... | ||
| ``` | ||
| ### Configure the permissions | ||
|
|
||
| To handle runtime permissions on Android, Xamarin.Essentials must receive any `OnRequestPermissionsResult`. Add the following code to all `Activity` classes: | ||
| To handle runtime permissions on Android, permission requests must be passed on to Essentials by calling the `Microsoft.Maui.Essentials.Platform.OnRequestPermissionsResult` method. Add the following code to all `Activity` classes: | ||
|
|
||
| ```csharp | ||
| public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Android.Content.PM.Permission[] grantResults) | ||
| ```csharp | ||
| public class MainActivity : MauiAppCompatActivity | ||
| { | ||
| public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults) | ||
| { | ||
| Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults); | ||
| Microsoft.Maui.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults); | ||
|
|
||
| base.OnRequestPermissionsResult(requestCode, permissions, grantResults); | ||
| } | ||
| ``` | ||
|
|
||
| # [iOS](#tab/ios) | ||
|
|
||
| No additional setup required. | ||
|
|
||
| # [Windows](#tab/windows) | ||
|
|
||
| No additional setup required. | ||
|
|
||
| ----- | ||
|
|
||
| 6. Follow the [Xamarin.Essentials guides](index.md) that enable you to copy and paste code snippets for each feature. | ||
|
|
||
| ## Xamarin.Essentials - Cross-Platform APIs for Mobile Apps (video) | ||
| // ... Other code ... | ||
| } | ||
| ``` | ||
|
|
||
| > [!Video https://channel9.msdn.com/Shows/XamarinShow/Snack-Pack-XamarinEssentials-Cross-Platform-APIs-for-Mobile-Apps/player] | ||
| # [iOS](#tab/ios) | ||
|
|
||
| ## Other Resources | ||
| No extra setup required. | ||
|
|
||
| We recommend developers new to Xamarin visit [getting started with Xamarin development](~/cross-platform/getting-started/index.md). | ||
| # [Windows](#tab/windows) | ||
|
|
||
| Visit the [Xamarin.Essentials GitHub Repository](https://github.com/xamarin/Essentials) to see the current source code, what is coming next, run samples, and clone the repository. Community contributions are welcome! | ||
| No extra setup required. | ||
|
|
||
| Browse through the [API documentation](xref:Xamarin.Essentials) for every feature of Xamarin.Essentials. | ||
| ----- | ||
| <!-- markdownlint-enable MD025 --> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.