当通过营销 URL 下载应用程序时,我试图从 URL 获取推荐人详细信息。我创建了一个带有 INSTALL_REFERRER 意图过滤器的广播接收器。
// 我的接收者清单代码
<receiver android:name="com.cc.rummycentral.service.DownloadReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER"></action>
</intent-filter>
</receiver>
下载接收器类:
public class DownloadReceiver extends BroadcastReceiver
{
private static String TAG = "referrer";
public DownloadReceiver(){
Log.w(TAG, "INSIDE DownloadReceiver()");
}
@Override
public void onReceive(Context context, Intent intent)
{
try
{
Log.w(TAG, "INSIDE onReceive");
if (null != intent && intent.getAction().equals("com.android.vending.INSTALL_REFERRER"))
{
Log.w(TAG, "YES, IT IS AN INSTALL EVENT");
String rawReferrer = intent.getStringExtra("referrer");
if (rawReferrer != null) {
String referrer = URLDecoder.decode(rawReferrer, "UTF-8");
Log.w(TAG,"HEY Received Referrer: " + referrer);
}
}
} catch (Exception var6) {
var6.printStackTrace();
Log.e(TAG, "EXP: "+var6.toString());
}
}
}