PerlDev
PerlDev

Reputation: 437

Deeplink in MAUI "Java.lang.RuntimeException", unable to instantiate activity ComponentInfo

I'm trying to handle deeplink in MAUI app; modified AndroidManifest.xml as following:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:name="DeeplinkTest" 
                 android:allowBackup="true" 
                 android:icon="@mipmap/appicon" 
                 android:roundIcon="@mipmap/appicon_round" 
                 android:supportsRtl="true">
        <activity
            android:name="DeeplinkTest.MainActivity"
            android:exported="true"
            android:windowSoftInputMode="stateHidden|adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <!-- Deep Link Intent Filter -->
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="https" android:host="foo.com" android:pathPrefix="/bar/" />
            </intent-filter>
        </activity>

    </application>
</manifest>

but it runs into Java.lang.RuntimeException This is .net9.0. After removing the <activity .. /> from the file, app runs well. What's wrong?

Upvotes: 0

Views: 60

Answers (1)

Liyun Zhang - MSFT
Liyun Zhang - MSFT

Reputation: 14409

Please only use the [Activity] and [IntentFilter] in the class. The official document about the Activity name said:

The type name of an activity is based on the 64-bit cyclic redundancy check of the assembly-qualified name of the type being exported. This enables the same fully-qualified name to be provided from two different assemblies without receiving a packaging error.

So you will get the error : Java.lang.Class not found when you register the activity in the AndroidManifest.xml by <activity...>.

  1. First, remove the <activity .. /> from the AndroidManifest.xml file.
  2. And then use the [Activity] and [IntentFilter] for the MainActivity.
[Activity(
    Theme = "@style/Maui.SplashTheme",
    MainLauncher = true,
    WindowSoftInputMode = Android.Views.SoftInput.StateHidden | 
        Android.Views.SoftInput.AdjustResize,
    ConfigurationChanges = ConfigChanges.ScreenSize |
        ConfigChanges.Orientation |
        ConfigChanges.UiMode |
        ConfigChanges.ScreenLayout |
        ConfigChanges.SmallestScreenSize |
        ConfigChanges.KeyboardHidden |
        ConfigChanges.Density)]
[IntentFilter(
    new string[] { Intent.ActionView },
    Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
    DataScheme = "https",
    DataHost = "foo.com",
    DataPath = "/bar/",
    AutoVerify = true,)]    
public class MainActivity : MauiAppCompatActivity
{
}

And then the deep link will work.

Upvotes: 1

Related Questions