8

I need to recognize users with specific apk build. This build has some features comparing to normal apk (like some functions are PRO at start).

build for GooglePlay------>
                           ----> next version of apk
build for some Customers-->

I thought about saving some data to database, so even if I update apk I, will have pernament data no matter what version user will have.

The problem happens when the user didn't run the application but immediately updated to next version. User didn't initialize sqlite, so no data was stored.

Is there any way to keep data and reuse it even if user updated base apk to newer version?

codecrazer
  • 515
  • 5
  • 19
deadfish
  • 11,064
  • 11
  • 79
  • 125
  • i didn't understood your question properly. Do you want to migrate your database properly? if no db_version found, can't you just update your db incrementally? – Sarthak Mittal Aug 14 '17 at 10:19
  • What part of question You don't understand? – deadfish Aug 14 '17 at 10:24
  • why is it necessary to initialize the db? what happens if not initialized before updating? – Sarthak Mittal Aug 14 '17 at 10:27
  • It was only first idea. My aim is to recognize separate builds in two devices. One of the build should have premium features. So far so good. However I would like to have opportunity update both versions without losing old preferences on both devices. Updating version might delete features on premium apk build. – deadfish Aug 14 '17 at 10:30
  • ok, why don't you use separate build flavor for premium and non-premium version? – Sarthak Mittal Aug 14 '17 at 10:32
  • in this case I would have to take care of both versions – deadfish Aug 14 '17 at 22:20
  • u will have to maintain only flavor specific code, rest of the code will be common. same as in any other case. – Sarthak Mittal Aug 15 '17 at 08:33
  • yes but both apps should be updated by Google Play service, from one address. How separate flavour would help here? – deadfish Aug 15 '17 at 21:27
  • I think there's provision for that too! – Sarthak Mittal Aug 16 '17 at 04:50
  • I am not following You – deadfish Aug 17 '17 at 12:02
  • According to my understanding your question. Either you want to keep mobile reference or another data. If you want to save mobile reference you can save its MAK address in another place(remote server) and calling it after you update your App by web request. And after compare current MAK address with that you save you will know which device you are in. Or if you want save another data it will be easier. – Hazem Aug 17 '17 at 14:58
  • @deadfish what I meant was that you probably can use one google play service address and maintain multiple app flavors. – Sarthak Mittal Aug 18 '17 at 08:59
  • @deadfish also, I didn't understood 1 thing in your ques: suppose I am a new user who installed your app, but didn't opened it, now suppose I update the app. Now whatever features you provided for free with the new version will also be available to me whenever I open the app. And regarding maintaining the list of premium features, is it something that you are maintaining on your own server or you are using in-app purchases or something similar? – Sarthak Mittal Aug 18 '17 at 09:05

4 Answers4

3

You can't, at least not without root or any other "patch"-solutions.

There are a few solutions which doesnt work well and need some preparation.

Solution 1:

Create a second App which must be preinstalled and have a PACKAGE_ADDED receiver. Onec it receives the installation of your App it will run it at least onec.

Solution 2:

Create a BOOT_COMPLETED receiver but this means that the device need to reboot to get activated. Even with this solution it may or may not work. Since Android 3.1 google have added a security policy to require (the most devices) that the App has been started at least one time to get in activate-state (some manufacturer dont have this security policy).

Solution 3: (Only working solution)

Create a different Package for your "Customers-App". Onec the app is installed from Playstore and started, it will validate if an app with the customers-namespace is installed. If yes, then it will start to do your Customers-Sqlite-Stuff and uninstall the app after.

Example:

com.myapp.customer -> installed com.myapp.playstore -> installed -> started -> validate if com.myapp.customer is installed and activate the "customers routine" -> remove com.myapp.customer

Edit:

Using Androids Gradle Plugin 3+ allows your to create flavors which allows you to create different package names / builds easily. https://developer.android.com/studio/build/build-variants.html

Emanuel S
  • 7,503
  • 2
  • 32
  • 48
1

In my understanding, your app is completely offline.

If it is offline. You can only identify the user is a pro by asking them.

You can make users get pro features by entering Promo code. get the promo code from the user and provide them pro features.

If your app is Online and has web services.

Then you can simply check pro users when they open the app by calling your server and provide them Pro features.

Another idea is checking Build Number and provide the pro features.

Get the version number by calling BuildConfig.VERSION_CODE

Bhuvanesh BS
  • 11,405
  • 10
  • 36
  • 61
  • I dont think this will answer his question since he didnt ask how to define "pro"-services, but asked how to get state of a preinstalled app when installing / updating to another version from the playstore. – Emanuel S Aug 20 '17 at 02:29
1

In the case of your customer did not run the app before updating it through the store, there's any code of your "pro" variant that can be execute, so I'll try to use the only thing that is "done" when app is installed, the permissions.

Maybe try to add one permission only in "pro" variant that is not really necessary in your app, but that you can check later if user had accept it through first install, and so know which apk it was.

You can also give a try through Install Referrer that is normally used to identify source of your install origin (often used by market tools). Have a look at this Get referrer after installing app from Android Market

smora
  • 667
  • 5
  • 17
1

This solution depends on if you have access to your special users through email for example.

Android supports deeplinking, for your PRO users you could point them to a link to enable the PRO features. If a user opens this link, then your app would open. You can store the unlock in SharedPreferences so it survives updating to newer versions later on.

Optionally, you could also send your users to a login page (the link you send them). If they login successfully it redirects to the deeplink.

Another alternative in the same direction is by associating your app to an unusual file extension (i.e: .fff) and mail a .fff file to your PRO users. That will prompt them to open the file with your app which will allow you once again to record their activation of the pro features.

Both solutions allow you to activate different feature set if, for example, you have different feature group (pro, business, superpro, ...)

user3802077
  • 831
  • 9
  • 21