How to wire up an Android Share intent in MAUI?

%3CLINGO-SUB%20id%3D%22lingo-sub-3002886%22%20slang%3D%22en-US%22%3EHow%20to%20wire%20up%20an%20Android%20Share%20intent%20in%20MAUI%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3002886%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20trying%20to%20setup%20a%20Share%20Intent%20in%20MAUI%2C%20by%20adding%20the%20share%20intent%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EAndroidManifest.xml%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efile%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%20class%3D%22%22%3E%3CPRE%3E%26lt%3B%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%26gt%3B%0A%26lt%3Bmanifest%20xmlns%3Aandroid%3D%22http%3A%2F%2Fschemas.android.com%2Fapk%2Fres%2Fandroid%22%26gt%3B%0A%20%26lt%3Buses-sdk%20android%3AminSdkVersion%3D%2221%22%20android%3AtargetSdkVersion%3D%2231%22%20%2F%26gt%3B%0A%20%26lt%3Bapplication%20android%3AallowBackup%3D%22true%22%20android%3Aicon%3D%22%40mipmap%2Fappicon%22%20android%3AroundIcon%3D%22%40mipmap%2Fappicon_round%22%20android%3AsupportsRtl%3D%22true%22%26gt%3B%0A%20%20%26lt%3Bactivity%20android%3Aname%3D%22SomeLongName.MainActivity%22%20%26gt%3B%0A%20%20%20%26lt%3Bintent-filter%26gt%3B%0A%20%20%20%20%26lt%3Baction%20android%3Aname%3D%22android.intent.action.SEND%22%20%2F%26gt%3B%0A%20%20%20%20%26lt%3Bcategory%20android%3Aname%3D%22android.intent.category.DEFAULT%22%20%2F%26gt%3B%0A%20%20%20%20%26lt%3Bdata%20android%3AmimeType%3D%22text%2Fplain%22%20%2F%26gt%3B%0A%20%20%20%26lt%3B%2Fintent-filter%26gt%3B%0A%20%20%26lt%3B%2Factivity%26gt%3B%0A%20%26lt%3B%2Fapplication%26gt%3B%0A%20%26lt%3Buses-permission%20android%3Aname%3D%22android.permission.ACCESS_NETWORK_STATE%22%20%2F%26gt%3B%0A%26lt%3B%2Fmanifest%26gt%3B%3C%2FPRE%3E%3C%2FDIV%3E%3CP%3EAnd%20then%20by%20adding%20a%20Name%20property%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EActivity%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eclass%3A%3C%2FP%3E%3CDIV%20class%3D%22%22%3E%3CPRE%3E%5BActivity(%0A%20%20%20%20%20%20%20%20Name%20%3D%20%22SomeLongName.MainActivity%22%0A%20%20Theme%20%3D%20%22%40style%2FMaui.SplashTheme%22%2C%20MainLauncher%20%3D%20true%2C%20ConfigurationChanges%20%3D%20ConfigChanges.ScreenSize%20%7C%20ConfigChanges.Orientation%20%7C%20ConfigChanges.UiMode%20%7C%20ConfigChanges.ScreenLayout%20%7C%20ConfigChanges.SmallestScreenSize)%5D%0A%20public%20class%20MainActivity%20%3A%20MauiAppCompatActivity%0A%20%7B%0A%20%20%20%20%20%20%20%20protected%20override%20void%20OnCreate(Bundle%20savedInstanceState)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20base.OnCreate(savedInstanceState)%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(Intent.Type%20%3D%3D%20%22text%2Fplain%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%3C%2FPRE%3E%3C%2FDIV%3E%3CP%3EWhen%20I%20debug%20the%20application%20in%20MAUI%2C%20the%20app%20builds%20correctly%20and%20the%20Output%20says%20that%20the%20app%20has%20deployed.%20However%2C%20in%20Visual%20Studio%2C%20the%20debugger%20fails%20to%20run%2C%20and%20there%20is%20no%20evidence%20of%20the%20app%20on%20the%20emulator.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20ideas%3F%20Is%20this%20a%20bug%2C%20or%20am%20I%20doing%20something%20wrong%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20also%20tried%20to%20create%20a%20separate%20Activity%20to%20handle%20only%20the%20Share%20intent.%20The%20app%20then%20debugs%2C%20but%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ebase.OnCreate%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%20fails%20with%20the%20following%20exception%3A%3C%2FP%3E%3CDIV%20class%3D%22%22%3E%3CPRE%3EJava.Lang.IllegalStateException%3A%20'The%20specified%20child%20already%20has%20a%20parent.%20You%20must%20call%20removeView()%20on%20the%20child's%20parent%20first.'%3C%2FPRE%3E%3C%2FDIV%3E%3CP%3EHere%20is%20the%20separate%20Activity%3A%3C%2FP%3E%3CDIV%20class%3D%22%22%3E%3CPRE%3E%20%5BActivity(%0A%20%20%20%20%20%20%20%20Name%20%3D%20%22SomeLongName.ShareActivity%22)%5D%0A%20%20public%20class%20ShareActivity%20%3A%20MauiAppCompatActivity%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20protected%20override%20void%20OnCreate(Bundle%20savedInstanceState)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(Intent.Type%20%3D%3D%20%22text%2Fplain%22%20%26amp%3B%26amp%3B%20Intent.Action%20%3D%3D%20%22android.intent.action.SEND%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2FhandleSendUrl()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20base.OnCreate(savedInstanceState)%3B%0A%0A%20%20%20%20%20%20%20%20%7D%3C%2FPRE%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3002886%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3E.NET%20MAUI%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
New Contributor

I am trying to setup a Share Intent in MAUI, by adding the share intent to the AndroidManifest.xml file:

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
	<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="31" />
	<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true">
		<activity android:name="SomeLongName.MainActivity" >
			<intent-filter>
				<action android:name="android.intent.action.SEND" />
				<category android:name="android.intent.category.DEFAULT" />
				<data android:mimeType="text/plain" />
			</intent-filter>
		</activity>
	</application>
	<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>

And then by adding a Name property to the Activity class:

[Activity(
        Name = "SomeLongName.MainActivity"
		Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)]
	public class MainActivity : MauiAppCompatActivity
	{
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            if (Intent.Type == "text/plain")
            {

            }

        }
    }

When I debug the application in MAUI, the app builds correctly and the Output says that the app has deployed. However, in Visual Studio, the debugger fails to run, and there is no evidence of the app on the emulator.

 

Any ideas? Is this a bug, or am I doing something wrong?

 

I also tried to create a separate Activity to handle only the Share intent. The app then debugs, but the base.OnCreate method fails with the following exception:

Java.Lang.IllegalStateException: 'The specified child already has a parent. You must call removeView() on the child's parent first.'

Here is the separate Activity:

 [Activity(
        Name = "SomeLongName.ShareActivity")]
  public class ShareActivity : MauiAppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            if (Intent.Type == "text/plain" && Intent.Action == "android.intent.action.SEND")
            {
                //handleSendUrl();
            }

            base.OnCreate(savedInstanceState);

        }
0 Replies