Skip to content

Commit c5d4b97

Browse files
authored
Merge pull request #38 from egvijayanand/working
Added FUNDING.yml file and Embedded Android sample
2 parents c63d71b + a54cd3c commit c5d4b97

29 files changed

+209
-0
lines changed

.github/FUNDING.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# These are supported funding model platforms
2+
3+
github: ["egvijayanand"]
4+
patreon: # Replace with a single Patreon username
5+
open_collective: # Replace with a single Open Collective username
6+
ko_fi: # Replace with a single Ko-fi username
7+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
liberapay: # Replace with a single Liberapay username
10+
issuehunt: # Replace with a single IssueHunt username
11+
otechie: # Replace with a single Otechie username
12+
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
13+
custom: ["https://paypal.me/egvijayanand", "https://www.buymeacoffee.com/egvijayanand"]

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ Available under the `src` directory:
2222
- UI, ViewModel, Model, and Business logic all from shared project
2323
- Head projects serve as an app container
2424
- Both Xamarin.Forms and .NET MAUI from a single project - `DateCalculator.UI`
25+
* `EmbeddedAndroid` - .NET MAUI Page embedded in a Native Android App, targeting .NET 6 (`net6.0-android`)
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true">
4+
</application>
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
</manifest>

src/EmbeddedAndroid/App.cs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace EmbeddedAndroid
2+
{
3+
public class App : Application
4+
{
5+
6+
}
7+
}
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net6.0-android</TargetFramework>
4+
<OutputType>Exe</OutputType>
5+
6+
<!-- Project Options -->
7+
<Nullable>enable</Nullable>
8+
<ImplicitUsings>enable</ImplicitUsings>
9+
<RootNamespace>EmbeddedAndroid</RootNamespace>
10+
11+
<!-- .NET MAUI -->
12+
<UseMaui>true</UseMaui>
13+
14+
<!-- App Identifier -->
15+
<ApplicationId>com.companyname.embeddedandroid</ApplicationId>
16+
17+
<!-- App Version -->
18+
<ApplicationVersion>1</ApplicationVersion>
19+
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
20+
21+
<!-- Target Platform Options -->
22+
<SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
23+
</PropertyGroup>
24+
25+
<ItemGroup>
26+
<PackageReference Include="CommunityToolkit.Maui.Markup" Version="1.0.0" />
27+
</ItemGroup>
28+
</Project>
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.3.32519.111
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EmbeddedAndroid", "EmbeddedAndroid.csproj", "{73A85CF6-9D64-4E4D-AB58-AB68EF69B3FC}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{73A85CF6-9D64-4E4D-AB58-AB68EF69B3FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{73A85CF6-9D64-4E4D-AB58-AB68EF69B3FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{73A85CF6-9D64-4E4D-AB58-AB68EF69B3FC}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
17+
{73A85CF6-9D64-4E4D-AB58-AB68EF69B3FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{73A85CF6-9D64-4E4D-AB58-AB68EF69B3FC}.Release|Any CPU.Build.0 = Release|Any CPU
19+
EndGlobalSection
20+
GlobalSection(SolutionProperties) = preSolution
21+
HideSolutionNode = FALSE
22+
EndGlobalSection
23+
GlobalSection(ExtensibilityGlobals) = postSolution
24+
SolutionGuid = {1BDC1A21-2B2C-4625-B4F1-A5B39689F0E8}
25+
EndGlobalSection
26+
EndGlobal

src/EmbeddedAndroid/MainActivity.cs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Android.App;
2+
using Android.OS;
3+
using CommunityToolkit.Maui.Markup;
4+
using Microsoft.Maui.Embedding;
5+
using Microsoft.Maui.Platform;
6+
7+
namespace EmbeddedAndroid
8+
{
9+
[Activity(Label = "@string/app_name", MainLauncher = true)]
10+
public class MainActivity : Activity
11+
{
12+
protected override void OnCreate(Bundle? savedInstanceState)
13+
{
14+
base.OnCreate(savedInstanceState);
15+
16+
// Set our view from the "main" layout resource
17+
//SetContentView(Resource.Layout.activity_main);
18+
19+
var builder = MauiApp.CreateBuilder();
20+
builder.UseMauiEmbedding<App>()
21+
.UseMauiCommunityToolkitMarkup();
22+
var mauiApp = builder.Build();
23+
var mauiContext = new MauiContext(mauiApp.Services, this);
24+
var mauiPage = new MauiPage();
25+
// Platform-specific extension method
26+
SetContentView(mauiPage.ToContainerView(mauiContext));
27+
// Platform-independent extension method
28+
//SetContentView(mauiPage.ToPlatform(mauiContext));
29+
}
30+
}
31+
}

src/EmbeddedAndroid/MauiPage.cs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using CommunityToolkit.Maui.Markup;
2+
using static Microsoft.Maui.Graphics.Colors;
3+
4+
namespace EmbeddedAndroid
5+
{
6+
public class MauiPage : ContentPage
7+
{
8+
public MauiPage()
9+
{
10+
Content = new StackLayout
11+
{
12+
Children =
13+
{
14+
new Label
15+
{
16+
Text = "Welcome to .NET MAUI!!!"
17+
}.TextColor(Purple)
18+
}
19+
}.Center();
20+
}
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Images, layout descriptions, binary blobs and string dictionaries can be included
2+
in your application as resource files. Various Android APIs are designed to
3+
operate on the resource IDs instead of dealing with images, strings or binary blobs
4+
directly.
5+
6+
For example, a sample Android app that contains a user interface layout (main.xml),
7+
an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png)
8+
would keep its resources in the "Resources" directory of the application:
9+
10+
Resources/
11+
drawable/
12+
icon.png
13+
14+
layout/
15+
main.xml
16+
17+
values/
18+
strings.xml
19+
20+
In order to get the build system to recognize Android resources, set the build action to
21+
"AndroidResource". The native Android APIs do not operate directly with filenames, but
22+
instead operate on resource IDs. When you compile an Android application that uses resources,
23+
the build system will package the resources for distribution and generate a class called "Resource"
24+
(this is an Android convention) that contains the tokens for each one of the resources
25+
included. For example, for the above Resources layout, this is what the Resource class would expose:
26+
27+
public class Resource {
28+
public class Drawable {
29+
public const int icon = 0x123;
30+
}
31+
32+
public class Layout {
33+
public const int main = 0x456;
34+
}
35+
36+
public class Strings {
37+
public const int first_string = 0xabc;
38+
public const int second_string = 0xbcd;
39+
}
40+
}
41+
42+
You would then use Resource.Drawable.icon to reference the drawable/icon.png file, or
43+
Resource.Layout.main to reference the layout/main.xml file, or Resource.Strings.first_string
44+
to reference the first string in the dictionary file values/strings.xml.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent">
7+
<TextView
8+
android:layout_width="wrap_content"
9+
android:layout_height="wrap_content"
10+
android:layout_centerInParent="true"
11+
android:text="@string/app_text"
12+
/>
13+
</RelativeLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
3+
<background android:drawable="@color/ic_launcher_background"/>
4+
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
5+
</adaptive-icon>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
3+
<background android:drawable="@color/ic_launcher_background"/>
4+
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
5+
</adaptive-icon>
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="ic_launcher_background">#2C3E50</color>
4+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<resources>
2+
<string name="app_name">EmbeddedAndroid</string>
3+
<string name="app_text">Hello, Android!</string>
4+
</resources>

0 commit comments

Comments
 (0)