Last active
April 1, 2016 07:38
-
-
Save tabachain/073836b766ed5632942452eed1817195 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends ActionBarActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
if (getIntent().getData() != null) { | |
Log.d("GrowthLink", getIntent().getData().getQueryParameter("referrer")); | |
String query = getIntent().getData().getQueryParameter("referrer"); | |
String clickId = null; | |
for (String param : query.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", "false") | |
.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