gpt4 book ai didi

java - 2014 年 BroadcastReceiver 的 Google Play/Google Analytics INSTALL_REFERRER

转载 作者:太空狗 更新时间:2023-10-29 15:00:40 25 4
gpt4 key购买 nike

在 StackOverflow 上,我注意到很多人多年来都无法捕获 INSTALL_REFERRER,Android 论坛上也有一些错误报告(由于 "wrong forum" 而全部关闭——但是,我没有看到任何公共(public)问题追踪器)。我想知道是否有人有办法让 INSTALL_REFERRER 在当前的 2014 版 Google Play 中工作。

编辑:我确实找到了一个问题跟踪器并创建了一个问题: https://code.google.com/p/play-games-platform/issues/detail?id=202

编辑 2:(将 com.myapp 替换为应用名称)

这是我为响应测试所做的。这与 Google 的 Analytics 帮助文档相同。这行得通。
adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n com.myapp/com.flyingsoftgames.googleplayquery.QueryReceiver --es "referrer""utm_source=testSource&utm_medium=testMedium&utm_term=testTerm&utm_content=testContent&utm_campaign=testCampaign"``

这是我为测试来自 Google 的 Play 商店 的响应所做的。这也与来自链接生成实用程序的 Google Analytics 帮助文档相同。 (是的,键是不同的,但这是根据文档,而不是我正在测试的——我只想要任何响应,并且文档表明 referrer 应该工作...)我安装了从这个等级开始运行,使用 logcat (adb logcat -s QueryReceiver) 监听 QueryReceiver。这行不通。


https://play.google.com/store/apps/details?id=com.myapp&referrer=utm_source%3Dgoogle%26utm_medium%3Dcpc%26utm_term%3Dpodcast%252Bapps%26utm_content%3DdisplayAd1%26utm_campaign%3Dpodcast%252Bgeneralkeywords

这是我的(Cordova 插件)代码,它在触发手动广播时完美运行:

AndroidManifest.xml:

<receiver android:exported="true" android:name="com.flyingsoftgames.googleplayquery.QueryReceiver">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>

GooglePlayQuery.java: 包 com.flyingsoftgames.googleplayquery;

import com.flyingsoftgames.googleplayquery.QueryReceiver;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.CordovaPlugin;

import android.content.Intent;
import android.content.IntentFilter;
import android.content.Context;
import android.app.Activity;
import android.content.ComponentName;
import android.content.pm.PackageManager;

import org.json.JSONArray;
import org.json.JSONException;

public class GooglePlayQuery extends CordovaPlugin {
public static CallbackContext queryCallback = null;
public static CordovaInterface cordova = null;

@Override public void initialize (CordovaInterface initCordova, CordovaWebView webView) {
// Create a static cordova reference so that QueryReceiver can access it.
cordova = initCordova;

// Enable the broadcast receiver in case it isn't enabled.
Activity activity = cordova.getActivity ();
ComponentName receiver = new ComponentName (activity, QueryReceiver.class);
PackageManager pm = activity.getPackageManager ();
pm.setComponentEnabledSetting (receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
super.initialize (cordova, webView);
}

public boolean execute (String action, JSONArray inputs, CallbackContext callbackContext) throws JSONException {
if ("getURI".equals(action)) {this.queryCallback = callbackContext;}
return true;
}
}


查询接收者.java:

package com.flyingsoftgames.googleplayquery;

import com.flyingsoftgames.googleplayquery.GooglePlayQuery;
import org.apache.cordova.PluginResult;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.app.Activity;
import android.content.ComponentName;
import android.content.pm.PackageManager;

import android.util.Log;

public class QueryReceiver extends BroadcastReceiver {
@Override public void onReceive (Context context, Intent intent) {
if (GooglePlayQuery.queryCallback != null) {
Log.d ("QueryReceiver", intent.toURI());
GooglePlayQuery.queryCallback.sendPluginResult (new PluginResult (PluginResult.Status.OK, intent.toURI()));
}

// Now disable the broadcast receiver since we don't need it anymore.
Activity activity = GooglePlayQuery.cordova.getActivity ();
ComponentName receiver = new ComponentName (activity, QueryReceiver.class);
PackageManager pm = activity.getPackageManager ();
pm.setComponentEnabledSetting (receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
}

最佳答案

我相信我终于找到了它不起作用的原因。 GooglePlayQuery.cordova 为 null 时出现静默错误。 QueryReceiver.onReceiveGooglePlayQuery.initialize 之前运行,但仅在生产模式下运行。疯了。

我仍然需要几个小时来测试它(因为我的游戏已发布)以验证,但这是我的新代码。也可在 https://github.com/agamemnus/cordova-plugin-google-play-query-receiver 获得.

AndroidManifest.xml:

<receiver android:exported="true" android:name="com.flyingsoftgames.googleplayquery.QueryReceiver">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>


GooglePlayQuery.java:

package com.flyingsoftgames.googleplayquery;

import com.flyingsoftgames.googleplayquery.QueryReceiver;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;

import android.content.Intent;
import android.app.Activity;
import android.content.ComponentName;
import android.content.pm.PackageManager;

import org.json.JSONArray;
import org.json.JSONException;

public class GooglePlayQuery extends CordovaPlugin {
public static CallbackContext queryCallback = null;
public static CordovaInterface cordova = null;
public static String referrer_uri = "";

public static Intent QueryReceiverCachedIntent = null;

@Override public void initialize (CordovaInterface initCordova, CordovaWebView webView) {
// Create a static cordova reference so that QueryReceiver can access it.
cordova = initCordova;

// Enable the broadcast receiver in case it isn't enabled.
Activity activity = cordova.getActivity ();
ComponentName receiver = new ComponentName (activity, QueryReceiver.class);
PackageManager pm = activity.getPackageManager ();
pm.setComponentEnabledSetting (receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

// If the QueryReceiver's onReceive already ran, run the cached data.
if (QueryReceiver.cachedIntent != null) {QueryReceiver.runCachedOnReceive (QueryReceiver.cachedIntent);}

super.initialize (cordova, webView);
}

public boolean execute (String action, JSONArray inputs, CallbackContext callbackContext) throws JSONException {
if ("getURI".equals(action)) {
if (referrer_uri != "") {
callbackContext.sendPluginResult (new PluginResult (PluginResult.Status.OK, referrer_uri));
referrer_uri = "";
return true;
}
this.queryCallback = callbackContext;
}
return true;
}
}


查询接收者.java:

package com.flyingsoftgames.googleplayquery;

import com.flyingsoftgames.googleplayquery.GooglePlayQuery;
import org.apache.cordova.PluginResult;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.app.Activity;
import android.content.ComponentName;
import android.content.pm.PackageManager;

import android.util.Log;

public class QueryReceiver extends BroadcastReceiver {

public static Intent cachedIntent = null;

@Override public void onReceive (Context context, Intent intent) {
// If the onReceive occurred before the GooglePlayQuery initialize function ran: cache the intent. Otherwise, run as intended.
if (GooglePlayQuery.cordova == null) {cachedIntent = intent;} else {runCachedOnReceive (intent);}
}

public static void runCachedOnReceive (Intent intent) {
if (cachedIntent != null) cachedIntent = null;
Log.e ("QueryReceiver", intent.toURI());
if (GooglePlayQuery.queryCallback != null) {
GooglePlayQuery.queryCallback.sendPluginResult (new PluginResult (PluginResult.Status.OK, intent.toURI()));
} else {
GooglePlayQuery.referrer_uri = intent.toURI();
}

// Now disable the broadcast receiver since we don't need it anymore.
Activity activity = GooglePlayQuery.cordova.getActivity ();
ComponentName receiver = new ComponentName (activity, QueryReceiver.class);
PackageManager pm = activity.getPackageManager ();
pm.setComponentEnabledSetting (receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
}

关于java - 2014 年 BroadcastReceiver 的 Google Play/Google Analytics INSTALL_REFERRER,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27205375/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com