我的Android list 文件

<service android:name="com.google.android.gms.analytics.CampaignTrackingService" />
      <receiver android:name="com.google.android.gms.analytics.CampaignTrackingReceiver"
            android:exported="true" >
            <intent-filter>
                <action android:name="com.android.vending.INSTALL_REFERRER" />
            </intent-filter>
      </receiver>

我没有其他接收器。

测试:
 ~/development/sdk/platform-tools $ ./adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n com.myapp.myapplication/com.google.android.gms.analytics.CampaignTrackingService --es  "referrer" "utm_source=testSource&utm_medium=testMedium&utm_term=testTerm&utm_content=testContent&utm_campaign=testCampaign"

响应:
Broadcasting: Intent { act=com.android.vending.INSTALL_REFERRER cmp=com.myapp.myapplication/com.google.android.gms.analytics.CampaignTrackingService (has extras) }
Broadcast completed: result=0

现在,当我运行该应用程序时,我得到了I/GAV3(17797): Thread[GAThread,5,main]: No campaign data found.
然后,我尝试了自定义接收器:
这是我的代码:
<service android:name="com.myapp.myapplication.ReferrerCatcher"/>
<receiver android:name="com.myapp.myapplication.ReferrerCatcher" android:exported="true">
  <intent-filter>
    <action android:name="com.android.vending.INSTALL_REFERRER" />
  </intent-filter>
</receiver>

而我的接收者:
package com.myapp.myapplication;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import com.google.analytics.tracking.android.CampaignTrackingReceiver;


public class ReferrerCatcher extends BroadcastReceiver {

      private static String TAG = "INSTALL_RECEIVER";

        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d(TAG, "Received install event");
            String referrer = "";
            Bundle extras = intent.getExtras();
            if(extras != null) {
                referrer = extras.getString("referrer");
            }
            Log.d(TAG, "Referer is: " + intent + " :: " + extras );
            new CampaignTrackingReceiver().onReceive(context, intent);
        }
}

这是我对自定义接收器的测试:~/development/sdk/platform-tools $ ./adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n com.myapp.myapplication/com.myapp.myapplication.ReferrerCatcher --es "referrer" "utm_source=testSource&utm_medium=testMedium&utm_term=testTerm&utm_content=testContent&utm_campaign=testCampaign"
这是响应:
Broadcasting: Intent { act=com.android.vending.INSTALL_REFERRER cmp=com.myapp.myapplication/.ReferrerCatcher (has extras) }
Broadcast completed: result=0

现在,当我运行该应用程序时,我得到的是:
08-15 14:59:38.391: D/INSTALL_RECEIVER(24996): Referer is: Intent { act=com.android.vending.INSTALL_REFERRER flg=0x10 cmp=com.myapp.myapplication/.ReferrerCatcher (has extras) } :: Bundle[{referrer=utm_source=testSource}]

这比上次测试要好,但是我没有得到完整的引荐来源。我只是得到消息来源。能否请您看一下代码,看看我是否在做任何错误?我已经为这段代码苦苦挣扎了2天了。

先感谢您。

最佳答案

简短的答案。您必须对引荐来源信息进行编码编码,否则只会得到第一个参数。您可以更改参数的顺序,但仍将获得第一个参数值。

utm_source%3DtestSource%26utm_medium%3DtestMedium%26utm_term%3DtestTerm%26utm_content%3DtestContent%26utm_campaign%3DtestCampaign

07-28 03:24
查看更多