In-app updates in Android using .net maui c# - Stack Overflow

I tried implementing in-app updates for android using this library<PackageReference Include="X

I tried implementing in-app updates for android using this library <PackageReference Include="Xamarin.Google.Android.Play.Core" Version="1.10.3.15" />

and here is the code

using Xamarin.Google.Android.Play.Core.AppUpdate;
using Xamarin.Google.Android.Play.Core.Install.Model;
protected override void OnCreate(Bundle savedInstanceState)
{
    appUpdateManager = AppUpdateManagerFactory.Create(this);
    StartInAppUpdate();

    base.OnCreate(savedInstanceState);
}
private void StartInAppUpdate()
{
    var appUpdateInfoTask = appUpdateManager.AppUpdateInfo;
    appUpdateInfoTask.AddOnCompleteListener(new OnCompleteListener(task =>
    {
        if (task.IsSuccessful)
        {
            var appUpdateInfo = task.GetResult(Java.Lang.Class.FromType(typeof(AppUpdateInfo))) as AppUpdateInfo;
            if (appUpdateInfo != null)
            {
                if (appUpdateInfo.UpdateAvailability() == UpdateAvailability.UpdateAvailable && appUpdateInfo.IsUpdateTypeAllowed(AppUpdateType.Immediate))
                {                                        
                    appUpdateManager.StartUpdateFlowForResult(
                                appUpdateInfo,
                                AppUpdateType.Immediate,
                                this,
                                123);
                }
            }
        }
        else
        {
            System.Diagnostics.Debug.WriteLine("Failed to retrieve app update info.");
        }
    }));
}
class OnCompleteListener : Java.Lang.Object, Xamarin.Google.Android.Play.Core.Tasks.IOnCompleteListener
{
    private readonly Action<Xamarin.Google.Android.Play.Core.Tasks.Task> _callback;

    public OnCompleteListener(Action<Xamarin.Google.Android.Play.Core.Tasks.Task> callback)
    {
        _callback = callback;
    }

    public void OnComplete(Xamarin.Google.Android.Play.Core.Tasks.Task task)
    {
        _callback(task);
    }
}
    protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
    
            if (requestCode == 123)
            {
                if (resultCode == Result.Ok)
                {
                    // Update was successful, notify the user or handle the result
                    Toast.MakeText(this, "Update complete!", ToastLength.Short).Show();
                }
                else
                {
                    // Update failed or was canceled, notify the user
                    Toast.MakeText(this, "Update failed or canceled.", ToastLength.Short).Show();
                }
            }
        }

I tried testing using Internal App Sharing, giving 2 builds, first version 1.0 and second as 2.0. Reference -> I installed 1.0 (using Internal App Sharing) and then I clicked on the app sharing url of version 2.0 but didn't install and went back to the 1.0 application (already installed one), killed and opened the app. The update dialog is not coming.

task.IsSuccessful is coming as false task.IsComplete is true

here is the exception Install Error(-3): The API is not available on this device. ( /reference/com/google/android/play/core /install/model/Install ErrorCode#ERROR_API _NOT_AVAILABLE)

I tried implementing in-app updates for android using this library <PackageReference Include="Xamarin.Google.Android.Play.Core" Version="1.10.3.15" />

and here is the code

using Xamarin.Google.Android.Play.Core.AppUpdate;
using Xamarin.Google.Android.Play.Core.Install.Model;
protected override void OnCreate(Bundle savedInstanceState)
{
    appUpdateManager = AppUpdateManagerFactory.Create(this);
    StartInAppUpdate();

    base.OnCreate(savedInstanceState);
}
private void StartInAppUpdate()
{
    var appUpdateInfoTask = appUpdateManager.AppUpdateInfo;
    appUpdateInfoTask.AddOnCompleteListener(new OnCompleteListener(task =>
    {
        if (task.IsSuccessful)
        {
            var appUpdateInfo = task.GetResult(Java.Lang.Class.FromType(typeof(AppUpdateInfo))) as AppUpdateInfo;
            if (appUpdateInfo != null)
            {
                if (appUpdateInfo.UpdateAvailability() == UpdateAvailability.UpdateAvailable && appUpdateInfo.IsUpdateTypeAllowed(AppUpdateType.Immediate))
                {                                        
                    appUpdateManager.StartUpdateFlowForResult(
                                appUpdateInfo,
                                AppUpdateType.Immediate,
                                this,
                                123);
                }
            }
        }
        else
        {
            System.Diagnostics.Debug.WriteLine("Failed to retrieve app update info.");
        }
    }));
}
class OnCompleteListener : Java.Lang.Object, Xamarin.Google.Android.Play.Core.Tasks.IOnCompleteListener
{
    private readonly Action<Xamarin.Google.Android.Play.Core.Tasks.Task> _callback;

    public OnCompleteListener(Action<Xamarin.Google.Android.Play.Core.Tasks.Task> callback)
    {
        _callback = callback;
    }

    public void OnComplete(Xamarin.Google.Android.Play.Core.Tasks.Task task)
    {
        _callback(task);
    }
}
    protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
    
            if (requestCode == 123)
            {
                if (resultCode == Result.Ok)
                {
                    // Update was successful, notify the user or handle the result
                    Toast.MakeText(this, "Update complete!", ToastLength.Short).Show();
                }
                else
                {
                    // Update failed or was canceled, notify the user
                    Toast.MakeText(this, "Update failed or canceled.", ToastLength.Short).Show();
                }
            }
        }

I tried testing using Internal App Sharing, giving 2 builds, first version 1.0 and second as 2.0. Reference -> https://developer.android/guide/playcore/in-app-updates/test I installed 1.0 (using Internal App Sharing) and then I clicked on the app sharing url of version 2.0 but didn't install and went back to the 1.0 application (already installed one), killed and opened the app. The update dialog is not coming.

task.IsSuccessful is coming as false task.IsComplete is true

here is the exception Install Error(-3): The API is not available on this device. (https://developer.android /reference/com/google/android/play/core /install/model/Install ErrorCode#ERROR_API _NOT_AVAILABLE)

Share Improve this question edited Nov 20, 2024 at 15:31 Meghna Singh asked Nov 20, 2024 at 5:15 Meghna SinghMeghna Singh 112 bronze badges 2
  • Is there an error prompt which can help us find the cause of the problem? – Jessie Zhang -MSFT Commented Nov 20, 2024 at 8:17
  • Install Error(-3): The API is not available on this device. (developer.android /reference/com/google/android/play/core /install/model/Install ErrorCode#ERROR_API _NOT_AVAILABLE) – Meghna Singh Commented Nov 20, 2024 at 15:31
Add a comment  | 

1 Answer 1

Reset to default 0

You can troubleshoot the problem from the following aspects:

1.Please check the app you are testing has the same package name which is available on the play store.

2.Please check whether the signature between the two versions you have installed on the device and the one that Play Store would deliver.

Note:

To run it again, please clear the cache and storage of Play Store again.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742379691a4432879.html

相关推荐

  • In-app updates in Android using .net maui c# - Stack Overflow

    I tried implementing in-app updates for android using this library<PackageReference Include="X

    14小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信