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

Federico Navarrete 616 Reputation points
2021-05-15T13:45:52.293+00:00

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

96847-rdjol.png

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:

96836-onndi.png

Any idea what am I doing wrong?

P.S.:

I'm testing in an emulator running Android 11.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,363 questions
0 comments No comments
{count} votes

Accepted answer
  1. JarvanZhang 23,961 Reputation points
    2021-05-17T05:41:09.017+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    Hi, fanmixco. I created a basic demo to test your code, it works as excepted on Android 11. I could reproduce the 'Application isn't installed' problem when the targetClass is not correct.

       <intent  
           android:action="android.intent.action.VIEW"  
           android:targetPackage="com.companyname.app19_5"  
           android:targetClass="xxx">  
    

    According to the posted code, it seems you didn't set the Name property in the MainActivity class. Please try to specify the value to the MainActivity class and test again.

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

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.