0

我的服务器创建了一个链接,该链接将参数重定向并传递给 google play store;

我的服务器收到的短信; https://goo.gl/ {UNIQUE_ID}

当我点击时,我实际上点击了下面的这个网址; http://www.mycompany.com/env=dev&token=123&id=456

上面的链接将我引导到 google play store 到我的应用程序包含的参数; https://play.google.com/store/apps/details?id=com.mycompany.app&referrer=123,456

这是问题;(第一次安装)当我安装通过上面的链接打开的应用程序时,我想在第一次将那些“token”、“id”参数传递给我的应用程序,然后我将跳过登录。这些参数由服务器创建,因为它们对用户也是唯一的。

我已经设置了“com.android.vending.INSTALL_REFERRER”,我能够按预期接收参数,但在每个设备上并不一致,并且可能会面临很大的延迟。

 <receiver
        android:name=".GooglePlayReceiver"
        android:exported="true"
        android:permission="android.permission.INSTALL_PACKAGES">
        <intent-filter>
            <action android:name="com.android.vending.INSTALL_REFERRER" />
        </intent-filter>
    </receiver>

我的 GooglePlayReceiver Broadcastreceiver 是;

public class GooglePlayReceiver extends BroadcastReceiver {

Context mContext;
String purchaseId = null;

public GooglePlayReceiver() {
}

@Override
public void onReceive(Context context, Intent intent) {
    try {
        mContext = context;
        Bundle extras = intent.getExtras();
        String verificationCode = null;
        String phoneNumber = null;
        if (extras != null) {
            String code = extras.getString("referrer");
            String[] strArr = code != null ? code.split(",") : new String[0];
            token = strArr[0];
            id = strArr[1];
        }
    } catch (Exception ex) {
    }
}}

此流程在某些设备上存在很大延迟。例如,Google Pixel 2 立即获取参数,没有延迟,Samsung Galaxy S7 有 5-10 秒的延迟。

如何解决这个问题?

4

1 回答 1

0

因为它INSTALL_REFERRER是作为广播(文档)发送的,所以它使用发布订阅模型。无法保证时间。

因此,您不应将应用程序启动流程设计为依赖于在一定时间内接收广播。Android是开源的,我不同手机厂商所做的改动会导致播报的及时性不同。

我会为您的应用提供不同的设计:

  • 始终将用户带到正常的设置流程
  • 如果广播稍后到达,允许用户跳过登录
于 2018-02-19T09:51:54.567 回答