Android Cookies (invitation fee)

I am trying to integrate the invitation reward logic. What I'm trying to do for this, I generate a unique URl for each user. When a friend clicks on a URL, he is directed to the page and then to the game store. A cookie with a unique identifier is stored on the device.

Note - (User can open the link in any browser)

When the application on the device starts, I retrieve the cookies that were saved using the above, and, if available, send them to the server, where the user is easily identified and receives a reward.

It looked pretty straight forward, however, I was stuck at the point where I need to read the cookie and extract the identifier.

I read this one which says this is not possible. :( I also tried below

List<Cookie> cookies = new DefaultHttpClient().getCookieStore() .getCookies(); if (cookies.isEmpty()) { System.out.println("None Cookies"); } else { for (int i = 0; i < cookies.size(); i++) { System.out.println("Cookie - " + cookies.get(i).toString()); } } 

but no luck. I keep getting "No cookies."

My questions:

  • Can I read the created cookie? If so, how?
  • If not, is there any alternative to how I can achieve the above functions?

Thanks for stopping by.

+6
source share
2 answers

I found an alternative to my above requirement using Campaign Dimension .

This can be done in three simple steps in addition to google-play-services_lib integration.

  • Create your invitation url.

    What will be the URL of the game store + your unique code. For example, my code is ABCDEX52362XYZ, then the url will look like https://play.google.com/store/apps/details?id=com.app.yourappspackagename&referrer=utm_source%3DABCDEX52362XYZ

& referrer = utm_source% 3DABCDEX52362XYZ is an important key here. More information on creating this URL here .

Google says -

When your application is downloaded from the Google Play Store, the Play Store application translates INTENT_REFERRER into your application during installation. This intent contains the value of the referrer parameter of the link used to access your page in the Google Play Store, if any.

  1. Add Google Analytics receiver to AndroidManifest.xml

     <receiver android:name="com.app.receiver.ReferrerCatcher" android:exported="true"> <intent-filter> <action android:name="com.android.vending.INSTALL_REFERRER" /> </intent-filter> </receiver> 
  2. Create a ReferrerCatcher referral receiver to capture the invitation code.

      public class ReferrerCatcher extends BroadcastReceiver { private static String referrer = ""; @Override public void onReceive(Context context, Intent intent) { referrer = ""; Bundle extras = intent.getExtras(); if (extras != null) { referrer = extras.getString("referrer"); if (referrer != null) { String invitationCode = referrer.replace("utm_source=",""); //referrer is your code plus the google keys, so you need to handle it } } } } 

Hope this helps. Happy coding. :)

+1
source

Interesting concept.

As for No. 1, you violate the default security protocol for Android, where applications can not read the personal data of other applications. This includes all Android browsers with their cookies isolated from each other, including your application.

For # 2, why not put a short phrase instead (which is easy to remember. Take a cue from the gfycat url generation, although perhaps try to limit the area and word size) to this single “success” or “reward earned” before being redirected to Play Market? (Not sure if you can embed a play store page in an iframe tag).

Even better, if the URL is directed to the location of your application, but switches a specific element on the page to reveal a passphrase, and perhaps makes the download button more attractive (although it just links to the play store page).

The user can then use a short unique passphrase to unlock rewards in the app.

I see a great novelty in your idea, but this is just a suggestion, since you can’t do much to get around the security policy.

+2
source

Source: https://habr.com/ru/post/989284/


All Articles