6

Working with Lollipop, I have a device-owner app that is installed with NFC at provision time.
What I need now is to handle automatic updates for my App, from Google Play to rely on the standard Android App update system...

So far I can imagine 2 ways to get this done, but don't know how to handle any of them :

  1. in my NFC install constant EXTRA PROVISIONING DEVICE ADMIN PACKAGE DOWNLOAD LOCATION install the App directly from the Play Store instead of the url on my own dev server.
    However this constant need to handle the url of an apk file, and I did not find any official way to get apk install direct from Play Store ? (as it will be a production App in the future I'm not interested in hacks)
  2. keep installing the apk from the dev server, but then allow the App to update itself with its little brother located on the Play Store with the same package name.
    To say it an other way: Would this be possible to install a v1 apk from a custom location, then put a v2 on the PlayStore... and let the magic come true ?

I'd be glad to hear if anyone could share experience about such procedures. Thanks for reading!


EDIT after @Stephan Branczyk suggestion I could make some more testing, here is what I did and the results:

1 - In the NFC provisioning I replaced the apk url with snep://my.app.packagename without luck ; it just gives an error without much explanation.

2 - I replaced this url by such a PlayStore link : https://play.google.com/store/apps/details?id=my.app.packagename but it gives a checksum error whether I use the checksum locally computed, or the checksum given on the GooglePlay apk details. It looks not so far from the goal but I could not make it work.

3 - Finally I came back on my first solution, a self-hosted apk versioned 1... but this time I tried to put on the PlayStore a newer version 2 of the app with the exact same packagename... That led me to strange things:

  • At first my App did not appear anywhere in the local PlayStore App, but when I searched for it in Google Play, it showed up with the green "installed" badge, and it proposed me to make an update... So did I.
  • Then, after this first manual update, the App is in v2, nice, and better: it appears well listed in my PlayStore.
  • Optimistically, I uploaded a v3 of the App... just to see if my PlayStore would automatically update my app (as is does for all the other ones), but sadly no luck : even if my app is still listed in the playstore, and proposing the "update" button... it never updates by itself as it should ; I still need to click on it manually.

Isn't it a strange behavior ? If some have ideas about it, I would really need to be able to rely on the Play Store functionalities but so far no luck, and I cannot believe that Device-Owner app distribution is not compatible with PlayStore ?


Just in case, FYI here is the kind of provisioning code I'm using:

try {
            Properties p = new Properties();

            p.setProperty(
                    DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME,
                    "my.app.packagename");
            p.setProperty(
                    DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION,
                    "http://www.example.com/myDeviceOwnerApp.apk");
            p.setProperty(
                    DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM,
                    "U55o3fO0cXQtUoQCbQEO9c_gKrs");

            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            OutputStream out = new ObjectOutputStream(bos);
            p.store(out, "");
            final byte[] bytes = bos.toByteArray();

            NdefMessage msg = new NdefMessage(NdefRecord.createMime(
                    DevicePolicyManager.MIME_TYPE_PROVISIONING_NFC, bytes));
            return msg;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
JBA
  • 2,889
  • 1
  • 21
  • 38

2 Answers2

0

Write your package name as an AAR record in the tag.

To confirm that this functionality works, use this app to write the tag with.

Stephan Branczyk
  • 9,363
  • 2
  • 33
  • 49
  • Thanx for your input. Currently running tests with the PlayStore, publication delays make it slow. However, even if it led me further, none of your 2 solutions was working ; the first link works but there is checksum errors ; the second, interesting one snep:// does not work at all sadly... I'll come back soon and edit my question with the results of the tests to let you know what I tried. – JBA Feb 28 '15 at 14:18
  • Sorry, it's been a while since I did NFC. I just updated my answer. This method only works with Android 4.x and above. – Stephan Branczyk Feb 28 '15 at 18:05
  • Isn't the AAR record already what I'm writing on the NFC tag ? (_MIME_TYPE_PROVISIONING_NFC_ etc.) - I also updated my question to give the results of the tests I could make... – JBA Feb 28 '15 at 23:40
  • I'm actually not familiar with the term MIME_TYPE_PROVISIONING_NFC. I must have used something else. I can only tell you that if you write a tag with an AAR record with the application I've recommended, it should take you to the app store if you don't already have that app loaded on your device. Please do that part first, and confirm that this part is working (when using someone else's NFC writing app) at the very least. – Stephan Branczyk Mar 01 '15 at 00:39
  • What you are referring to is true and helpfull into the app-real-life on a devide (if I can say so)... Allowing a NFC record to be well filtered, secured, and targeted to a certain app. But my issue is located upstream to this: the installation of this app has to be made _before_ the device is provisionned, and before it can give the user any access to the playstore, see what I mean... Thus the AAR record as described in the docs is not helpful for this sake... – JBA Mar 01 '15 at 07:40
  • Ah ok, you might want to try having your applications have the same sharedUserId. However, you might still need two different update mechanisms even if you do that. So I'm afraid, I don't really have a solution for you. – Stephan Branczyk Mar 01 '15 at 07:57
0

You need to set Base64 encoded SHA1 or SHA256 (from M forward) of the apk in the

EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM

field when provisioning through NFC otherwise the provisioned device will not accept the URL for download.

Also see this answer for properly encoding the checksum.

Community
  • 1
  • 1
Vasile Jureschi
  • 2,169
  • 2
  • 17
  • 17