No Remote Registration Event During Initial App Install

I have been troubleshooting an issue where the majority of the time I do not get a remoteRegistration event (thus no token) during a fresh install of my app. However, I can clear the app’s data, fire up the app and get a token every single time.

I have tried both 2016.2992 and 2017.3068 using v1 and v2 of the notifications plugin on both. It doesn’t matter if I use GCM or FCM, the result is the same; no token after a fresh uninstall/reinstall but a token every time if I clear data (although 2992 with GCM received the token more often than not.)

That made no sense to me. It was almost as if I had some sort of residual data in the system.DocumentsDirectory still on my phone even after an uninstall. So I decided to add the following readily-available code to the top of my main.lua and sure enough, after a uninstall/reinstall there are game files located in the documents directory that should only be there once the user signs in and starts playing the game!

local lfs = require( "lfs" ) local doc\_path = system.pathForFile( "", system.DocumentsDirectory ) for file in lfs.dir( doc\_path ) do -- File is the current file or directory name print( "Found file: " .. file ) end

My research led me to these two articles:

https://stackoverflow.com/questions/33169618/an-android-app-remembers-its-data-after-uninstall-and-reinstall

https://forums.coronalabs.com/topic/67401-how-to-prevent-my-app-files-being-picked-up-by-google-backup/

The first article was spot on. I turned off “Automatic Restore” on my phone (3 different phones really) and now I get a token every time after I do an uninstall/install. “Automatic Restore” was restoring old games files into the system.DocumentsDirectory which made my app not “request” a new token (or so it seems that way to me.) Some of these game files were three months old!

So my question, is there a way we can turn off “Automatic Restore” for our app as discussed in the two posts above? Not only was this a problem with getting a remoteRegistration event, I can see it being an issue with game files as well. 

Thanks ahead of time!

Scott

no this is not possible unless you are an enterprise developer as the Android manifest file is not that accessible to standard users.

Can you be more specific about what you mean by a “fresh install”?  Are you deleting it from the device and re-downloading from Google Play? or are you deleting it from the device and installing it back either via the simulator or adb install?

Sorry for the confusion…everything seems to work great for a brand new install from a new user. I get a token and notifications work correctly.

However, once the user starts playing the game, the app saves a few things like preferences and logs in the system.DocumentsDirectory. If those users who have played the game do a complete uninstall then a reinstall then I do not always get a token (usually not.) The “Automatic Restore” feature in Android 6 will restore these old game files back to the system.DocumentsDirectory and I am assuming since these files are there, my app does not request a token therefore notifications do not work.

Those users can then do a “clear data” within application manager and everything works again which makes me believe that having files in the system.DocumentsDirectory has some bearing on whether my app requests a token or not.

I think it would be much easier if I could just turn “Automatic Restore” off for my app instead of my users having to “clear data.”

BTW…the results are the same whether I download from the Play store or side load.

Hope this helps clarify!

Thanks,

Scott

@Scott, what device are you getting this on?  I cannot replicate this on my Android 7 device by either ADB or Play store.  Nor on Galaxy S4 or s5 running cyanogen and Android 6 respectively.

I know someone was experiencing this on an S8. That is why I am asking.

@SGS, I have tested on a LG V20 (7.0) and a Galaxy Tab A (6.0.1) and the behavior was the same for me.  

And you are using this to load your app…

adb uninstall \<your package name\> adb install \<your apk\>

and your documents folder is not empty?

What happens if you do it on aeroplane mode?

No, I have always loaded straight through USB from PC to device and installed from there. But even doing an install from Google Play does the same. As long as “Automatic Restore” was turned on, I had the issue. When I turned it off, my issue went away.

And if you use my ADB code (put it in a dos box) ?

If you copy and locally install then documents folder will remain and this is by design.  

When your users update your app then don’t expect to lose their saved data!

Tested on Android 7 with “Automatic Restore” off. Seems that Samsung devices also has their own restore feature too.

It seems that Corona has updated the old (GCM) notification plugin. Now the ‘event registration’ does not always appear when the app launches. 

So when i update my old app to a new version (using the old GCM notification plugin), there is no ‘event registration’ being fired at all. The old notification token-id still works fine.

I can only get the ‘event registration’ when the app-data is deleted.

Guys @ Corona, is there a way to forcefully get an ‘event registration’ ?

Is the app-data somehow linked to the notification token-id ? (https://developers.google.com/instance-id/guides/android-implementation)

@yosu

When using the legacy notifications plugin have you added the following plugin to your build.settings?

["shared.google.play.services.gcm"] = { publisherId = "com.coronalabs", supportedPlatforms = { android=true } },

@SGS, the result is the same when I do an “adb uninstall/install.” If Automatic Restore is on and it restores old files into the system.DocumentsDirectory during a clean install then I do not get a remoteRegistration event/token.

@ingemar_cl,

I added it and there isn’t any token on every app-kill-restart. I was expecting the token on every app restart, as what my previous APK which I have build in end-2016.

The ‘event registration’ with the token is only given during the first app start after an install. Subsequent app starts/restarts does not give out anymore ‘event registration’ and thus no token.

no this is not possible unless you are an enterprise developer as the Android manifest file is not that accessible to standard users.

Can you be more specific about what you mean by a “fresh install”?  Are you deleting it from the device and re-downloading from Google Play? or are you deleting it from the device and installing it back either via the simulator or adb install?

Sorry for the confusion…everything seems to work great for a brand new install from a new user. I get a token and notifications work correctly.

However, once the user starts playing the game, the app saves a few things like preferences and logs in the system.DocumentsDirectory. If those users who have played the game do a complete uninstall then a reinstall then I do not always get a token (usually not.) The “Automatic Restore” feature in Android 6 will restore these old game files back to the system.DocumentsDirectory and I am assuming since these files are there, my app does not request a token therefore notifications do not work.

Those users can then do a “clear data” within application manager and everything works again which makes me believe that having files in the system.DocumentsDirectory has some bearing on whether my app requests a token or not.

I think it would be much easier if I could just turn “Automatic Restore” off for my app instead of my users having to “clear data.”

BTW…the results are the same whether I download from the Play store or side load.

Hope this helps clarify!

Thanks,

Scott

@Scott, what device are you getting this on?  I cannot replicate this on my Android 7 device by either ADB or Play store.  Nor on Galaxy S4 or s5 running cyanogen and Android 6 respectively.

I know someone was experiencing this on an S8. That is why I am asking.

@SGS, I have tested on a LG V20 (7.0) and a Galaxy Tab A (6.0.1) and the behavior was the same for me.  

And you are using this to load your app…

adb uninstall \<your package name\> adb install \<your apk\>

and your documents folder is not empty?

What happens if you do it on aeroplane mode?

No, I have always loaded straight through USB from PC to device and installed from there. But even doing an install from Google Play does the same. As long as “Automatic Restore” was turned on, I had the issue. When I turned it off, my issue went away.