17

Is there a way to pass a custom argument to android market (or any other way) so my app receives the argument after it gets installed (and run for the first time).

Let me explain.

  1. Start an intent with argument1="Hello world1" (custom argument every time)
  2. Install the app from android market.
  3. Open the app for the first time.
  4. App shows the msg "Hello world1"

Any case will do, not just intent to android market.

Most of the time the app will be installed via Barcode scanner with a binded http schema. So a browser workaround is possible too, HTML5 Client Side Storage, (store argument to browser and get it from there the first time my app runs)

Update

A solution would be to create a cookie,or something to the browser and then access it from the application i installed. Is that possible? If so can you provide some information about that? Can browsers share data with applications?

weakwire
  • 9,169
  • 8
  • 51
  • 78
  • So, just to clarify, you want each individual user to receive a different argument and have a different message displayed when they open the app for the first time? – theisenp Sep 27 '11 at 04:04

3 Answers3

21

You can publish a link like that
http://market.android.com/details?id=your.package.name&referrer=your_referrer_parameter
After user clicks this link and installs the application your broadcast receiver will receive a broadcast com.android.vending.INSTALL_REFERRER with "your_referrer_parameter" value.

More info:
http://code.google.com/mobile/analytics/docs/android/#android-market-tracking
Get referrer after installing app from Android Market
Get Android Google Analytics referrer tag

Community
  • 1
  • 1
Fedor
  • 42,643
  • 9
  • 75
  • 86
  • wow! referrer tag might do the work in a very slick way! I'll try it tomorrow and update – weakwire Sep 28 '11 at 02:25
  • I'm going to accept your answer. But since it's a boundy answer can you elaborate the answer a bit more? (For future viewers) – weakwire Oct 01 '11 at 05:43
  • @Fedor: what happens if the user clicks on another install link, with another referrer-parameter, where the app is already installed on his device? 1.Will the app be re-installed or will the previously installed one be launched? 2. If second case occurs, will the referrer be available for the launched app? [edit: I'm just realising how old this answer is, maybe I should consider asking a new question rather than commenting here...] – fpierrat Jun 25 '15 at 09:27
  • actually there is this intent api https://developer.chrome.com/multidevice/android/intents unfortunately if you dont have app installed this thing will redirect you to app store but when you install it won't pass the arguments. :( – Martin Kosicky Jun 09 '19 at 09:09
4

AFAIK what you're asking is not possible. The market only delivers the APK files to devices. However depending on what exactly you want to do there are probably many different work arounds.

Here are a couple thoughts:

If you want the market to deliver a custom argument that is unique for every user, then why not have your app connect to a server on the initial run and download that argument? Even if the market could provide the argument it would have to get it from you and you would presumably have to setup a server to provide the market with the argument.

If you simply want the app to know wether or not it is running for the first time you can do that using a SharedPreference. Query if a preference like hasAppRunBefore exists and if it doesn't then you know the app is running for the first time since install. Then set the hasAppRunBefore variable to some value indicating that it has run before. This implementation will allow users to uninstall the app and reinstall it and after each reinstall the app will run for the first time again.

Another option is a combination of the first two. You can have the app connect to your server and provide the server with the device's UUID then the server can check if its seen that UUID before. If it hasn't it provides the argument otherwise it doesn't.

If you truly need each APK to be different for each device you can setup a server that when a download request is received it compiles a new APK and provides a link to download that APK. That will allow you to generate a new and unique APK for each download. This will however require you to distribute the APK yourself as the Android Market doesn't currently provide this functionality.

slayton
  • 19,732
  • 8
  • 57
  • 86
  • ty for your time.The app will only downloaded from the android market. well yes 1 workaround is to have that unique device - server relation . But then again you need somekind of push notification when the user gets the application. Is it possible to write some data to the default browser and then look from the application to the browser data? Can the browsers share data with the applications? – weakwire Sep 27 '11 at 17:24
  • Why would you need the push notification? why can't the application phone home on the initial load of the application, and request information from the server? – slayton Sep 27 '11 at 17:36
  • + 1, if the idea is to identify the client uniquely then, a ping to a home server is the best way. – RHT Sep 27 '11 at 17:42
  • 1
    i install the app from a link , that redirects to android market.And i say to that link "when you download the app open the 3rd image first. Also i can install that app from the android market without any arguments. How can i tell what i intend to do with that app without having control over the phone at the first place (no app of mine is yet installed to the phone) – weakwire Sep 27 '11 at 17:43
  • or you suggest in every first install tell to the server. "Is there anything special for me?" If the server responds then do the proper action. That's fine but then again i have to bind the user with the IP since i have no UUID or email to assosiate the user at the first place – weakwire Sep 27 '11 at 17:44
  • What i'm suggesting is that the first time the app runs it sends a standard HTTP POST http://en.wikipedia.org/wiki/POST_(HTTP) to a webserver and receives a response. The message to the server would include the device's UUID and the server response would depend on if it had seen that UUID before. – slayton Sep 27 '11 at 18:33
  • 1
    I think the probleme here is that the OP wants to have some information shown specfic to which link was clicked before the app was installed. This way, you'd have to rely on IP Adresses to identify the device – Blitz Sep 27 '11 at 19:07
  • Yes the only way for that slayton suggested to work is using IP adresses. But this cannot be viable since any phones could have the save IP address (public wifi etc), unless i could get a UUID from the browser.Cannot accept this answer because it doesn't supply any real workaround to the issue (IP identifying was not suggested by slayton) and the UUID refference is impossible under the circumstances. What @fedor suggested is a viable solution. refferee tag gets broadcasted to the device at "installing time" . – weakwire Oct 01 '11 at 05:41
1

I would go ahead and have the website that redirects to the market also push a file to the client. the file can be named something like "yourapp.info" and contain the data you need. Once your app starts, it can search the SD card (it should reside in a couple of well known directories, aka /sdcard/Downloads ) and read that file. There are no access restrictions on the sdcard.

Regarding a Cookie in the browser: I'm not sure that you could access the cookie from just any other app - (check this: blog.watchfire.com/files/advisory-android-browser.pdf - it's not possible to access the cookies) so I think that route will be closed.

Blitz
  • 5,263
  • 3
  • 31
  • 51
  • nice approach.If is was a way to save it to a default location that would be the solution, but i think it can't. A similar workaround is to create somekind of "public cookie" that my app can fetch from the browser. – weakwire Sep 27 '11 at 17:27
  • i've updated the answer on why i think a general cookie won't work – Blitz Sep 27 '11 at 18:31