广播INSTALL_REFERRER意图问题

时间:2014-08-15 05:07:48

标签: android android-intent google-analytics broadcastreceiver google-play

我的Android清单文件

<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天。

提前谢谢。

2 个答案:

答案 0 :(得分:3)

简短而简单的回答。您必须编码您的推荐人信息,否则您只能获得第一个参数。你可以改变参数的顺序,你仍然会得到第一个参数值。

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

答案 1 :(得分:0)

您需要更改以下字符: 更改 %26 - &gt; &安培; %3D - &gt; =