Rodrigo Salgado Atala
Rodrigo Salgado Atala

Reputation: 344

How can I save user-specific data at the time of installation of the app?

I've been requested the following at my job: I need to develop an Android app that connects to one of our web applications and stores user-specific data in the device, so said users can see their data whenever they need it. The thing is, one of the requirements is that the app installation becomes tied to the user, and it must happen automatically (that is, somehow detect which user is downloading the app and save his/her existent user ID from the web app to the Android app at the time of download/installation, without the user needing to log in. Which brings me to my question: Is there any way to somehow get the user ID/username/whatever I need, from my web app, at the time of download of the APK file, and "attach" it to the installation, so to speak? Note that this Android app is not supposed to be installed from the Play Store, but downloaded directly from our web application. It's also not meant to be used within the company by any co-workers, but by our clients, which might end up beind thousands, or tens of thousands eventually, so making an installation for each potential user that contains their data isn't feasible.

If there isn't a practical way to do the above, what is the closest to it that can be done?

Upvotes: 0

Views: 987

Answers (3)

Willis
Willis

Reputation: 5336

It seems to me that you have a few different options...

  1. It was hard to tell from your post, but if the application is only being distributed within the company by simply sharing the APK with your co-workers (not using the Play store), then it would be quite easy to simply modify the required information (ID/username/etc.) and generate a unique APK for everyone who wants the application. Or you could simply include a unique ID number and keep track of who has what ID whenever you generate each APK. Depending on the size of the company and how many people will use this application this solution could range from trivial to impossible. It is also fairly limiting, as any updates to the application would require you to generate a new APK for each person who has the application.

  2. The second option is to use some sort of identification scheme to generate a unique ID for each application and then associate that ID with the users information. There are multiple options for generating a unique ID for each installation. Here is an brief article that describes a few approaches to solving this issue: http://android-developers.blogspot.com/2011/03/identifying-app-installations.html

  3. The third option, which I believe is probably the best, is to not necessarily track the individual installations but to save the user information locally on the device and then use this information when the application connects with your web application. For example, you could request that the user enter an ID and a password when the android application starts and then use this information to verify the identify of the person when the android application connects to the web app; without the proper ID and password, the android application would not be able to access the web information, regardless of who installed it. There is a wealth of information on storing information locally within an application: http://developer.android.com/guide/topics/data/data-storage.html

EDIT

You can also access the Unique Android device ID (Is there a unique Android device ID?) although there are some issues with this as well.

You made me curious with your question so I wrote and tested a quick method that generates a unique ID. The method below will create a unique ID number by getting the serial number of the device and adding a random number between 0 and a million to the beginning and the end of the serial number. It then writes this unique number to a simple text file that you can access and use as the unique ID for the application. Furthermore, you can call this method at the beginning of your activity and, since the method checks to see if a text file is present, a unique ID will only be created once...

public static void CreateInstallationID()
        {
            File log = new File("sdcard/AppInstallID.txt");
            /** Check to see if ID has already been created */
            if (!log.exists())
            {
                try
                {
                    /** Create file */
                    log.createNewFile();
                    BufferedWriter writer = new BufferedWriter(new FileWriter(log, true));
                    /** Create unique ID */
                    Random rand1 = new Random();
                    Random rand2 = new Random();
                    int iRandomNumber1 = rand1.nextInt((1000000 - 0) + 1) + 0;
                    int iRandomNumber2 = rand2.nextInt((1000000 - 0) + 1) + 0;
                    String sUniqueID = Integer.toString(iRandomNumber1) + Build.SERIAL +
                            Integer.toString(iRandomNumber2);
                    writer.append(sUniqueID);
                    writer.newLine();
                    writer.close();
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }

        }

As an example, when I executed this method I obtained a text file entitled "AppInstallID" that read 826225F12G4005DIE416255. You could add or remove fields to the unique ID to increase or decrease complexity as you see fit.

EDIT 2

If you do something like this make sure you add the permission to write to external storage in your manifest file.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Upvotes: 2

Jamil
Jamil

Reputation: 5535

According to my Suggestion=

When the Application is downloaded, and user have entered the Login and password, the app should check whether the user data is saved in the mobile or not, if not then give a screen which says "Syncing" and download all the data from the web to its local storage.

else continue normal flow of application

Upvotes: 0

kolo
kolo

Reputation: 85

I think it's not possible to asign user ID or some think to the apk durning download. I think only one possible is after install apk user login to service and get some unique ID and send specific data. or You can make every apk with unique ID and send this application to specific user but I think it's not ergonomic solution :-). and btw I'am not sure but if user download application and install hi must start this application and then she can work in background but if hi only install(don't start) she wont work.

Upvotes: 0

Related Questions