Skip to content

Instantly share code, notes, and snippets.

@tabachain
Last active April 1, 2016 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tabachain/da09460e1aab08b61eb2cb0b3f783886 to your computer and use it in GitHub Desktop.
Save tabachain/da09460e1aab08b61eb2cb0b3f783886 to your computer and use it in GitHub Desktop.
public class RefReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String encodedInstallReferrer = intent.getStringExtra("referrer");
String installReferrer = "";
if (encodedInstallReferrer != null) {
try {
installReferrer = URLDecoder.decode(encodedInstallReferrer, "utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
Log.d("GrowthLink", installReferrer);
String clickId = null;
for (String param : installReferrer.split("&")) {
String pair[] = param.split("=");
String key = pair[0];
String value = "";
if (pair.length > 1) {
value = pair[1];
}
if (key.equals("growthlink.clickId")) {
clickId = value;
}
//androidReferrerパラメータを取得できます(key,value)
}
//オープン数,インストール数の反映をしたい場合
if (clickId != null) {
final String linkClickId = clickId;
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
String result = null;
RequestBody requestBody = new FormEncodingBuilder()
.add("applicationId", "{Application ID}")
.add("clickId", linkClickId)
.add("install", "true")
.add("credentialId", "{Credentia Key}")
.build();
Request request = new Request.Builder()
.url("https://api.link.growthbeat.com/1/click/consume")
.post(requestBody)
.build();
OkHttpClient client = new OkHttpClient();
try {
Response response = client.newCall(request).execute();
result = response.body().string();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
@Override
protected void onPostExecute(String result) {
Log.d("GrowthLink", result);
}
}.execute();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment