Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A collection of .NET for Android sample projects

License

NotificationsYou must be signed in to change notification settings

dotnet/android-samples

Repository files navigation

This repository contains.NET for Android samples, showing usage of variousAndroid API wrappers from C#. Visit theAndroid Sample Galleryto download individual samples.

See the.NET MAUI Installation docs for setup instructions.

Galleries

We love samples! Application samples show off our platform and provide a great way for people to learn our stuff. And we even promote them as a first-class feature of the docs site. You can find the sample galleries here:

Sample Requirements

We welcome sample submissions, please start by creating an issue with your proposal.

Because the sample galleries are powered by the github sample repos, each sample needs to have the following things:

  • Screenshots - a folder called Screenshots that has at least one screen shot of the sample on each platform (preferably a screen shot for every page or every major piece of functionality). For an example of this, seeandroid-p/AndroidPMiniDemo.

  • Readme - aREADME.md file that explains the sample, and contains metadata to help customers find it. For an example of this, seeandroid-p/AndroidPMiniDemo. The README file should begin with a YAML header (delimited by---) with the following keys/values:

    • name - must begin with.NET for Android -

    • description - brief description of the sample (< 150 chars) that appears in the sample code browser search

    • page_type - must be the stringsample.

    • languages - coding language/s used in the sample, such as:csharp,fsharp,vb,java

    • products: should bedotnet-android for every sample in this repo

    • urlFragment: although this can be auto-generated, please supply an all-lowercase value that represents the sample's path in this repo, except directory separators are replaced with dashes (-) and no other punctuation.

    Here is a working example fromandroid-p/AndroidPMiniDemo README raw view.

    ---name:.NET for Android - Android P Mini Demodescription:"Demonstrates new display cutout and image notification features (Android Pie)"page_type:samplelanguages:-csharpproducts:-dotnet-androidurlFragment:android-p-androidpminidemo---# Heading 1rest of README goes here, including screenshot images and requirements/instructions to get it running

    NOTE: This must be valid YAML, so some characters in the name or description will require the entire string to be surrounded by " or ' quotes.

  • Buildable solution and .csproj file - the projectmust build and have the appropriate project scaffolding (solution + .csproj files).

This approach ensures that all samples integrate with the Microsoftsample code browser.

Tips for .NET Migration

The goal here is to fully "modernize" the template for .NET and C# 11.

Compare adotnet new android template named the same as the existing project.

  1. If the root namespace doesn't match the project name, to get theexisting code to compile, you may need:
<RootNamespace>Xamarin.AidlDemo</RootNamespace>
  1. Update any dependencies, NuGet packages, etc.

  2. Removeandroid:versionCode,android:versionName,package,<uses-sdk/>, and<application label="". These are defined inthe.csproj file.

  3. Remove all unused using statements, since we now haveImplicitUsings=enable.

  4. Fix all namespace declarations to use C# 10 file-scoped namespaces.

  5. Build. Fix any warnings related to nullable reference types (Nullable=enable).

  6. Run the app and ensure the sample still works.

Porting to .NET

When porting a legacy sample to .NET, please make sure to preserve asmuch history of the original sample as possible. Some samples havetheir project, source and resource files in the same directory wherethe readme file, screenshot folder and other files not directlyrelated to the sample code reside. Since .NET defaults to importingall the files in the project directory as if they were part of theproject, the application code must first be moved to a subdirectory(with the exception of the .sln file).

New subdirectory should use the same name as the solution file,without the .sln extension. After creating itfirst move all therelevant files and directories (source code, project file(s), theProperties andResources directories etc), using thegit mvcommand to the newly created directory, modify the .sln file to updateproject file path(s) andcommit these changes. This ensures thatfurther changes will preserve commit history.

Now the sample is ready for porting. After creating new project file(usingdotnet new android -n SampleName) in a separate directory,copy any necessary package and project references from the oldproject, updating them as needed and after that replace the oldproject file with the new one.

A handful of useful tips (copied from thedotnet branch's README inthis repository):

  1. If the root namespace doesn't match the project name, to get the existing code to compile, you may need:
<RootNamespace>Xamarin.AidlDemo</RootNamespace>
  1. Update any dependencies, NuGet packages, etc.
  2. Remove android:versionCode, android:versionName, package,, and <application label="". These are defined in the.csproj file.
  3. Remove all unused using statements, since we now have ImplicitUsings=enable.
  4. Fix all namespace declarations to use C# 10 file-scoped namespaces.
  5. Build. Fix any warnings related to nullable reference types (Nullable=enable).
  6. Run the app and ensure the sample still works.

Another collection of tips can be foundhere

License

.NET (including the android-samples repo) is licensed under theMIT license.

Code of conduct

This project has adopted the code of conduct defined by theContributor Covenant to clarify expected behavior in our community. For more information, see the.NET Foundation Code of Conduct.


[8]ページ先頭

©2009-2025 Movatter.jp