Hey you guys, need help!!
I have an app in Google Play that scan some QR Codes, and these Codes had a pattern, and we have to change it, because the read is very very slow. We will update the QRs and the App, but we have to force an update and keep the correct functionality. I was reading about an "in-app update" on https://developer.android.com/guide/app-bundle/in-app-updates and in there, they say that requires a library called Play Core. There is a Play Core Library for Xamarin? Considering that this site uses Android Studio (Java) for implementations references.
Answers
test
test
I'm also interested in any information about how to achieve in app update thanks this new Google Play capability.
I do not found any information about how to use Play Core in Xamarin.
Any ideas?
I guess this is unavailable for now, I am planning to make a Xamarin Binding for Play Core will get back to you guys as soon as it's done
I'll be anxiously waiting
Hey, guys, I was able to complete the binding creation and I will be updating it on Nuget soon, for now, you guys can pick it up from my drive: https://drive.google.com/file/d/1r8QuqW25PKcQty0W_Q0eEgMcA8ynt_3J/view?usp=sharing
Awesome!! I'll test and give you a feedback soon.
Sure let me know, I sort of gave it one round of test and it seems to be working great...
@G.Hakim
The binding is very useful and works for the immediate update perfectly.
I am having some difficulty getting the InstalledStateUpdateListener to work. The compiler has some issues with ThisInstalledStateListener.java
error: ThisInstallStateUpdatedListener is not abstract and does not override abstract method onStateUpdate(InstallState) in StateUpdatedListener public class ThisInstallStateUpdatedListener
error: name clash: onStateUpdate(Object) in ThisInstallStateUpdatedListener and onStateUpdate(StateT) in StateUpdatedListener have the same erasure, yet neither overrides the other public void onStateUpdate (java.lang.Object p0) where StateT is a type-variable: StateT extends Object declared in interface StateUpdatedListener
Could you help and also is there any news on the Nuget?
Thanks!
@funklet1 Hi happy to know it helps you out, secondly I would like to know how exactly are you using the
ThisInstallStateUpdatedListener
and what are you using it for. Also, note that I am a tad bit busy but I will be uploading it to Nuget really soon. Sorry for the delay everyone!@FreakyAli,
I appreciate that you are busy and the NuGet would be the icing on the cake but I like cake even if it doesn't have icing on it..
I want to implement the Listener for the install state so that when the Flexible update is ready I can inform the user so they can update.
From the developer.android.com section guide/app-bundle/in-app-updates#monitor_flexible
All help is greatly appreciated.
Well from the above code I understand that you are trying to get the flexi-update interface set up now I haven't used it yet, But this is how it should look from my understanding
And this is how the class would look
I hope this is what you were looking for, if not please feel free to get back at anytime
Yes, if you look at my code above you can see that my class is functionally identical to the one that you have provided.
Unfortunately in VS2017 there is a compiler error.
I don't know if the compiler error is due to an issue in the dll or Visual Studio so I am unable to troubleshoot further.
Perhaps if you could provide the source to the binder project..
Please see the following, I believe that this is the issue I am facing, hopefully you can make modifications to your binding project to help out..
www.andipalo.com/2017/07/16/java-seesharp-xamarin/
I will look into it ASAP, will let you know if I get somewhere also I plan on adding the binding to Github today will link it here, Also you will be free to contribute to it
guys is any update ? i need play core for xamarin android to use in app update feature, thanks for advance
@FreakyAli Any updates about the nuget package ?
Any progress on this guys?
@funklet1 Same errors like you. Have you made it work?
Hi,
seems like @funklet1 and @FreakyAli got at least immediate update working, but I don´t know how to do that. Any Idea how that works?
Hi, @PatGet I got immediate update working though I had to bind the latest version of the play core library in my project. I guess there is an available xamarin play core library in nuget which is in preview.
Tested the functionality in both debug (using the fake install app update manager to simulate the immediate update) and release configuration (able to check and detect updates from play store when the application is launched and update the app without any issues).
Sample code snippet
public class UpdateChecker
{
private Activity _activity;
private int _Request_Update;
public UpdateChecker(Activity activity, int Request_Update)
{
_activity = activity;
_Request_Update = Request_Update;
}
Hi @PatGet I got immediate update working on both play store and test environment though I had to bind the latest version of play core library in my project.
Sample code snippet below:
`public class UpdateChecker
{
private Activity _activity;
private int _Request_Update;
public UpdateChecker(Activity activity, int Request_Update)
{
_activity = activity;
_Request_Update = Request_Update;
}
Hey @GabrielDwight .
many thanks! That looks good, at least it compiles with a minor change.
Did you do anything special on the Binding? I had to add two " <remove-node" Entries:
How do you call the UpdateChecker? I just call it in my MainActivity OnCreate, set _activity to this and _Request_Update to 1. Seems like that should work but my AppUpdateSuccessListener is never called. I´m using Closed Alpha Track. Should that work in Debug or is that the reason why you had the FakeAppUpdateManager implemented?
Any one can help me how to get this AndroidX.AppCompat
@NaveenKumar.1636 if you are not using Android X you can just replace "AndroidX.AppCompat.App" with "Android.App"
Hey @PatGet
For the bindings I had to solve some issues though I did it in some shady way because the latest version had some java generics assigned to Tasks. This the binding entries I had:
<attr path="/api/package[@name='com.google.android.play.core.assetpacks']/ class[@name='NativeAssetPackStateUpdateListener']/ method[@name='onStateUpdate' and count(parameter)=1 and parameter[1][@type='com.google.android.play.core.assetpacks.AssetPackState']]/ parameter[1]" name="managedType"> Java.Lang.Object </attr> <attr path="/api/package[@name='com.google.android.play.core.assetpacks']/class[@name='AssetPackException']" name="extends">Java.Lang.Object</attr> <remove-node path="/api/package[@name='com.google.android.play.core.tasks']/class[@name='NativeOnCompleteListener']"/> <attr path="/api/package[@name='com.google.android.play.core.tasks']/class[@name='Tasks']" name="managedName">Tasks</attr> <attr path="/api/package[@name='com.google.android.play.core.splitcompat']/class[@name='SplitCompat']" name="managedName">SplitCompat</attr> <attr path="/api/package[@name='com.google.android.play.core.splitinstall']/class[@name='SplitInstallException']" name="extends">Java.Lang.Object</attr> <attr path="/api/package[@name='com.google.android.play.core.install']/class[@name='InstallException']" name="extends">Java.Lang.Object</attr> <attr path="/api/package[@name='com.google.android.play.core.tasks']/class[@name='RuntimeExecutionException']" name="extends">Java.Lang.Object</attr> <attr path="/api/package[@name='com.google.android.play.core.listener']/interface[@name='StateUpdatedListener']/method[@name='onStateUpdate' and count(parameter)=1 and parameter[1][@type='StateT']]/parameter[1]" name="type">Java.Lang.Object</attr>
If you are going to use other features like splitinstaller it may require further testing.
You can call the updatechecker either on the Mainactivity oncreate or onresume method depending on your preference. Let say you call on the oncreate method like this
// Check for updates updateChecker = new UpdateChecker(this, REQUEST_UPDATE); updateChecker.CheckForUpdates();
The reason I was using fakeupdatemanager in debug configuration is to simulate the update process though it won't show the immediate update play store window that's why I decided to show the Alert dialog in debug configuration. If you are using close alpha track in the play developer console. You may require to publish the application in release that will have the higher version code though with the same signing certificate then the application that you will use for testing may need to be in release configuration but with the lower version code number.
The moment you run the application with the lower version code you should see the updatemanager firing up automatically to display the immediate update window. You can let me know if you have succeeded in your testing.
@All
I have able to complete the mentioned without any error it compiled successfully.
But when we click on restart for update nothing is happening while debugging am I missing anything?
Hi @GabrielDwight
many thanks, it works for me! Sorry for the late reply but with your Metadata.xml it worked on first try. I guess I need to find out how this hole Binding process works and relearn some Java basics.
BTW:: It shows the Update Dialog even while I´m in Debug and my App being in the Closed Track (Alpha) with a higher Version Code. I have commented out the FakeUpdate completely.
Hi @GabrielDwight
one more thing it seems. I´m, stuck in an Update loop it seems. The App starts, finds an update, installs it, restarts.
Finds an update again, installs it, restarts and so on and so on.
It seems that the Update gets not installed.
I added OnActivityResult in my MainActivity but that gets not called at all. Any Idea?
Hi @PatGet. If you are using immediate update it will automatically install the update for you and restart the app which means OnActivityResult will never get called with immediate update since it will only work with flexible update which return an install state status to onActivityResult. Let say you want to use some functions onActivityResult with immediate update.
Update checker class
`if((availability.Equals(UpdateAvailability.UpdateAvailable) || availability.Equals(UpdateAvailability.DeveloperTriggeredUpdateInProgress)) && info.IsUpdateTypeAllowed(AppUpdateType.Immediate))
{
_appUpdateManager.StartUpdateFlowForResult(info, AppUpdateType.Immediate, _mainActivity, _update_request);
}
// If update is not available
if (availability.Equals(UpdateAvailability.UpdateNotAvailable) || availability.Equals(UpdateAvailability.Unknown))
{
Log.Debug("UPDATE NOT AVAILABLE", $"{info.AvailableVersionCode()}");
_mainActivity.StartActivityForResult(_intent, 'yourcustomresult');
}`
For the else part to work, the app needs to be in the same version code with the close track alpha version. This how I did on my side with immediate update.
Your activity class
`protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (REQUEST_UPDATE.Equals(requestCode))
{
switch (resultCode) // This part only works when you are using flexible update since it will return the activity callback automatically for the install status listener
{
case Result.Ok:
// In app update success
if (APP_UPDATE_TYPE_SUPPORTED == AppUpdateType.Immediate)
{
Toast.MakeText(this, "App updated", ToastLength.Short).Show();
}
break;
case Result.Canceled:
Toast.MakeText(this, "In app update cancelled", ToastLength.Short).Show();
break;
case (Result)ActivityResult.ResultInAppUpdateFailed:
Toast.MakeText(this, "In app update failed", ToastLength.Short).Show();
break;
}
}
else // This part you can use to start an activity or anything if no update is available since it will work for immediate update
{
// Your code function you want to perform if no update is available
}
For the update loop you are experiencing do you have any other code functions running in the activity OnStart, OnResume and OnCreate method? You can share with me the part of code you are experiencing problems if possible.
@GabrielDwight Ok, that makes sense but i would have not guessed that from the Docs. Especially as the UI gives no Error i might have thought that OnActivityResult would have been called with more information.
I published a sample including the Binding Lib to GitHub: https://github.com/PatGet/XamarinPlayCoreUpdater
I´m not doing anything in my real code, i can just change the certificate and package name locally and get the same loop result.
@NAVEENKUMAR_G In debug configuration it does not do anything. It is only used to test the play core fakeupdatemanager for update simulation process with the fake update manager class.
@PatGet I am looking into XamarinPlayCoreUpdater. Is there a way to test it with playstore app (if we run app in release mode)?
@DhruvGohil I used the Closed track for Updates as this is much faster. An important thing is that you you need to check your Certificate Setting: https://support.google.com/googleplay/android-developer/answer/7384423?hl=en
If you enabled that setting you can only test with Play Store Apps, not self-signed ones.
What I did was to disable automatic app updates and just wait till the app becomes visible as update in the play store that i started the app and were able to see the update process succeed.
If you can test with selfsigned apps it should just work fine in release mode.
any updates here guys? I've been using a wrapper by @FreakyAli (could be considered as sort of successful usage), but despite the fact IOnSuccessListener and IOnFailureListener work fine, there is still a problem with update state listener - the code shows the same errors as @funklet1 posted above.
I could suggest that changing of IAppUpdateManager.RegisterListener signature to eliminate IInstallStateUpdatedListener usage could solve or help to solve it, as the entire problem could be connected with these interfaces inheritances.
If someone tried this/have another fancy solution, any hints/workarounds would be appreciated.
UPD:
Tried to do like
public class InstallStateUpdatedListener : Java.Lang.Object, IStateUpdatedListener {
//interface implementation here
}
and converting its instance to IInstallStateUpdatedListener when subscribing, it doesn't cause any crash but also unsurprisingly doesn't trigger implemented interface method.
@funklet1 Do you solve your problem with flexible update?
I also have this error:
UpdateChecker_InstallStatusListener is not abstract and does not override abstract method onStateUpdate(InstallState) in StateUpdatedListener
Any ideas?
Hello Xevious95,
I changed to using
https://github.com/PatGet/XamarinPlayCoreUpdater
Really? I'm using that.
Could you show me your listener implementation?
`private class InstallStatusListener : Java.Lang.Object, IInstallStateUpdatedListener
{
private readonly IAppUpdateManager _appUpdateManager;
private readonly Activity _mainActivity;
This is my..
Thank's