question

fanmixco avatar image
0 Votes"
fanmixco asked RobCaplan edited

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:

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.


dotnet-xamarin
rdjol.png (33.3 KiB)
onndi.png (242.0 KiB)
rdjol.png (33.3 KiB)
onndi.png (242.0 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JarvanZhang-MSFT avatar image
1 Vote"
JarvanZhang-MSFT answered fanmixco commented

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Unexpected approach but it worked. Thanks!

0 Votes 0 ·