sách gpt4 ai đã đi

Android 应用 A 想要跟踪 Android 应用 B 安装的 Google Play 推荐数据

In lại 作者:塔克拉玛干 更新时间:2023-11-01 21:44:42 31 4
mua khóa gpt4 Nike

假设我有一个安装在用户设备上的 Android 应用程序 A,我的应用程序有一个 AppWidget,我们可以让其他 Android 开发人员在其中以每次安装成本为基础发布他们的应用程序推广广告。因此,我们需要跟踪 App B 是否通过 App A 的推荐安装在用户的设备上。

我们还假设 Android 应用 B 的广告在 Android 应用 A 的小部件上运行,并且我们将应用 A 的用户重定向到应用 B 的用户到 Google Play 的链接包含所有引荐来源数据。 URL 看起来像这样(推荐 đây -

https://play.google.com/store/apps/details?id=com.joelapenna.foursquared&referrer=utm_source%3Dtooyoou%26utm_medium%3Dbanner%26utm_term%3Dfoursquare%26utm_content%3Dfoursquare-tooyoou%26utm_campaign%3Dfoursquare-android )

如果您在浏览器中点击上面的链接,或者用它制作一个二维码并启动它,它将带您到 Google Play 中的应用程序 B,并提供所需的推荐数据。现在,当应用程序 B 安装在用户设备上并首次启动时,应用程序 A 期望收到的广播是 com.android.vending.INSTALL_REFERRER。如果收到广播并且 utm_source 是应用程序 A,则记录并处理事务。这就是我们的目标。

这是 App A 的 AndroidManifest.xml 代码 fragment 。

<ứng>
android:icon="@drawable/ic_launcher"
android:label="@string/tên_ứng_dụng"
android:debuggable="true" >

android:name=".LocateMeActivity"
android:label="@string/tên_ứng_dụng" >











添加的权限 -



这是应该处理广播的广播接收器类 ReferralReceiver.java。

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;

public class ReferralReceiver extends BroadcastReceiver
{
@Ghi đè
public void onReceive(Context context, Intent intent)
{
// Workaround for Android security issue: http://code.google.com/p/android/issues/detail?id=16006
thử
{
final Bundle extras = intent.getExtras();
if (extras != null) {
extras.containsKey(null);
}
}
catch (final Exception e) {
return;
}

Map referralParams = new HashMap();

// Return if this is not the right intent.
if (! intent.getAction().equals("com.android.vending.INSTALL_REFERRER")) { //$NON-NLS-1$
return;
}

String referrer = intent.getStringExtra("referrer"); //$NON-NLS-1$
if( referrer == null || referrer.length() == 0) {
return;
}

thử
{ // Remove any url encoding
referrer = URLDecoder.decode(referrer, "x-www-form-urlencoded"); //$NON-NLS-1$
}
catch (UnsupportedEncodingException e) { return; }

// Parse the query string, extracting the relevant data
String[] params = referrer.split("&"); // $NON-NLS-1$
for (String param : params)
{
String[] pair = param.split("="); // $NON-NLS-1$
referralParams.put(pair[0], pair[1]);
}

ReferralReceiver.storeReferralParams(context, referralParams);
}

private final static String[] EXPECTED_PARAMETERS = {
"utm_source",
"utm_medium",
"utm_term",
"utm_content",
"utm_campaign"
};

private final static String PREFS_FILE_NAME = "ReferralParamsFile";

public static void storeReferralParams(Context context, Map params)
{
SharedPreferences storage = context.getSharedPreferences(ReferralReceiver.PREFS_FILE_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = storage.edit();

for(String key : ReferralReceiver.EXPECTED_PARAMETERS)
{
String value = params.get(key);
if(value != null)
{
editor.putString(key, value);
}
}

editor.commit();
}


public static Map retrieveReferralParams(Context context)
{
HashMap params = new HashMap();
SharedPreferences storage = context.getSharedPreferences(ReferralReceiver.PREFS_FILE_NAME, Context.MODE_PRIVATE);

for(String key : ReferralReceiver.EXPECTED_PARAMETERS)
{
String value = storage.getString(key, null);
if(value != null)
{
params.put(key, value);
}
}
return params;
}
}

调试设备是Android OS 2.3.4

通过应用程序主要 Activity 中的简单 TextView 和 Button,我尝试显示接收者捕获的推荐数据。这是调用和显示-

referraltext.setText(ReferralReceiver.retrieveReferralParams(this.getApplicationContext()).toString());

当我启动上面显示的应用程序 B 的推荐链接时,转到 Google Play,安装它并第一次打开它 logcat 根本不显示广播 com.android.vending.INSTALL_REFERRER,因此显示推荐数据时显示空字符串。

同时,当我在下面使用 adb 命令时,同一个广播接收器就像一个魅力一样工作并显示推荐数据。

am broadcast -a com.android.vending.INSTALL_REFERRER -n com.locateme.android/.ReferralReceiver --es "referrer" "utm_source=tooyoou&utm_medium=banner&utm_term=foursquare&utm_content=foursquare-tooyoou&utm_campaign=foursquare-android"

那么这是否意味着 Google Play 根本不广播推荐人数据和预期的 Intent ?

或者这是否意味着它只为正在安装的 App B 广播 Intent ?

还是我做错了什么?

如果 App B 不必为了与我们一起做广告而将我们的跟踪 SDK 或代码插入到他们的 App 中,这是否可能实现?

非常感谢您的帮助。

附加信息 - 我们没有使用 Google Analytics SDK,因此我们使用的是自定义广播接收器而不是 Google 的 BR

The code above works like a charm. I just followed Lucas' advice below in the answer marked correct and replaced x-www-form-urlencoded to UTF-8. Why I didn't do this at first is because of what a mobile analytics company called Localytics posted here - http://www.localytics.com/docs/android-market-campaign-analytics/ Their code has the same issue. So basically what I have right now is that the above piece of code in an Android App that I published in Google Play and then downloaded the App from Google Play from my Android device running ICS, opened it and clicked on Retrieve Referral and it worked.Try it for free, here is the link - https://play.google.com/store/apps/details?id=com.locateme.android&referrer=utm_source%3Dtooyoou%26utm_medium%3Dbanner%26utm_term%3Dappdownload%26utm_content%3Dimage%26utm_campaign%3Dtooyooupromo

我想重申的另一件非常重要的事情是,如果您使用网络上的 google play 在您的设备上远程安装应用程序,则以这种方式跟踪 google play Activity 推荐将不起作用。我已经对其进行了测试,这是 Google 的一个开放缺陷。

1 Câu trả lời

上面的源代码不正确。

线

referrer = URLDecoder.decode(referrer, "x-www-form-urlencoded");

应该是

referrer = URLDecoder.decode(referrer, "UTF-8");

android文档对此并不清楚,但是如果你使用x-www-form-urlencoded它会抛出一个不受支持的编码异常....

关于Android 应用 A 想要跟踪 Android 应用 B 安装的 Google Play 推荐数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10986320/

31 4 0
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com