http://dev.classmethod.jp/smartphone/android-referrer/
import
android.content.BroadcastReceiver;
import
android.content.Context;
import
android.content.Intent;
public
class
RefReceiver
extends
BroadcastReceiver {
@Override
public
void
onReceive(Context context, Intent intent) {
String referrer = intent.getStringExtra(
"referrer"
);
Log.d(
"[REFERRER]"
,referrer);
}
}
<
receiver
android:name
=
"a.b.c.receiver.RefReceiver"
android:exported
=
"true"
>
<
intent-filter
>
<
action
android:name
=
"com.android.vending.INSTALL_REFERRER"
>
</
action
>
</
intent-filter
>
</
receiver
>
다른 라이브러리에 referrer 전달할 경우
public
class
RefReceiver
extends
BroadcastReceiver {
@Override
public
void
onReceive(Context context, Intent intent) {
// 다른 라이브러리에서 제공하는 referrer 에 전달
OtherReferrer otherReferrer = new OtherReferrer();
otherReferrer.onReceive(context, intent);
String referrer = intent.getStringExtra(
"referrer"
);
Log.d(
"[REFERRER]"
,referrer);
}
}
ADB 테스트
% adb shell am broadcast -a com.android.vending.INSTALL_REFERRER --es referrer hello
구글 링크 테스트
<
p
>referrer test1</
p
>
<
a
href="http://play.google.com/store/apps/details?id=<your application package>&referrer=hello">link1</
a
>
<
p
>referrer test2</
p
>