androidxamarin.androidandroid-shortcut

Application isn't installed when I launched it from a static shortcut in Xamarin.Android


I recently added some shortcuts to my app. The app is working fine, and the Static Shortcuts are shown as expected:

preview 1

However, when I do click on any of them, I'm getting the following error that prevents the app to be launched:

Application isn't installed

These are my XMLs:

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="tk.supernova.tmtimer.tk.supernova.tmtimer" android:versionName="2.1.0.0" android:installLocation="auto" android:versionCode="320">
    <uses-permission android:name="android.permission.READ_OWNER_DATA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_OWNER_DATA" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="com.android.vending.BILLING" />
    <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

    <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="30" />
    <application android:theme="@style/Launcher" android:icon="@drawable/icon" android:label="@string/app_name" android:requestLegacyExternalStorage="true">
        <activity android:name="tk.supernova.tmtimer.MainActivity" android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts" />
        </activity>
    </application>
</manifest>

shortcuts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<shortcuts
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:targetApi="25">
    <shortcut
        android:shortcutId="time1"
        android:enabled="true"
        android:icon="@drawable/timeline_clock_outline"
        android:shortcutShortLabel="@string/Time1"
        android:shortcutLongLabel="@string/Time1">
        <intent
            android:action="android.intent.action.VIEW"
            android:targetPackage="tk.supernova.tmtimer.tk.supernova.tmtimer"
            android:targetClass="tk.supernova.tmtimer.MainActivity">
            <extra
                android:name="customTime"
                android:value="30;45;60" />
        </intent>
        <categories android:name="android.shortcut.conversation" />
    </shortcut>
    <shortcut
        android:shortcutId="time2"
        android:enabled="true"
        android:icon="@drawable/timeline_clock_outline"
        android:shortcutShortLabel="@string/Time2"
        android:shortcutLongLabel="@string/Time2">
        <intent
            android:action="android.intent.action.VIEW"
            android:targetPackage="tk.supernova.tmtimer.tk.supernova.tmtimer"
            android:targetClass="tk.supernova.tmtimer.MainActivity">
            <extra
                android:name="customTime"
                android:value="300;360;420" />            
        </intent>
        <categories android:name="android.shortcut.conversation" />
    </shortcut>
</shortcuts>

This is an intro to the MainActivity class:

namespace tk.supernova.tmtimer
{
    [Activity(Label = "@string/app_name", MainLauncher = true, WindowSoftInputMode = SoftInput.AdjustPan)]
    public partial class MainActivity : AppCompatActivity
    {    
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            Platform.Init(this, savedInstanceState);

            var context = Platform.AppContext;
            var activity = Platform.CurrentActivity;
    
            SetTheme(Resource.Style.MyBaseTheme_NoActionBar);
            SetContentView(Resource.Layout.Main);

I know that my package name (tk.supernova.tmtimer.tk.supernova.tmtimer) is different from the main namespace (tk.supernova.tmtimer.tk.supernova.tmtimer). I also tried to use {applicationId}, but it didn't work. I have also checked several ideas in Stack, and none of them worked in my case. Furthermore, I cannot easily change the "wrong package name" because the app has been published in the Play Store for around 3 years.

Also, I am sure the package name is correct:

package name

Furthermore, Android.App.Application.Context.PackageName returns tk.supernova.tmtimer.tk.supernova.tmtimer. The expected result.

Any idea what am I doing wrong?

P.S.:


Solution

  • I got a solution from a Microsoft Forum. I just added this property: Name = tk.supernova.tmtimer.MainActivity" to my MainActivity like this:

    [Activity(Label = "@string/app_name", Name = "tk.supernova.tmtimer.MainActivity", MainLauncher = true, WindowSoftInputMode = SoftInput.AdjustPan)]
    public partial class MainActivity : AppCompatActivity
    {
        //...
    }
    

    I personally believe this is a Xamarin.Android bug. I don´t think it will happen the same in regular Android apps but if someone tests it feel free to add it to the comments section, and I´m going to update this answer.