Search code examples
androidxamarinshare-extension

share extension not working on android in case of version-update of the application


I am working on adding the share-extension to my application so images and other documents can be shared to/on my application.

I have added an Activity for this with Intent-filter for "action.SEND". Application and share-extension seem to be working fine standalone when user installs the current version of the app. But if user already has the previous version of the application (which does not have share-extension feature) installed then in case of share-extension feature is not working on the version update to latest one.

I have tried suggestions like: Setting my app as a sharing target (Xamarin) https://developer.android.com/training/sharing/receive#update-manifest

But they all work fine in case of the fresh installation of the app only but not in case of update.

Does anyone have any pointers on whether it is doable or not? and if it is doable, how can it be achieved?


Solution

  • We could resolve it by adding the following code in the MainActivity file:

    PackageManager p = this.PackageManager;
    
    ComponentName componentName = new ComponentName(AppContext, ShareExtensionClassName); // for example: ShareExtensionClassName .. com.xyz.appname.shareExtension
    
    p.SetComponentEnabledSetting(componentName, ComponentEnabledState.Enabled, ComponentEnableOption.DontKillApp);
    

    Thought of posting the code as it might help others too.