美文网首页
Android 获取当前推荐来源

Android 获取当前推荐来源

作者: 乘风破浪的程序员 | 来源:发表于2020-02-21 14:37 被阅读0次

    当用户通过点击Facebook 上的Ad 或者Google AD 跳转到GooglePlay 商店,我们的应用如何获知这个引荐来源,可通过使用Play Install Referrer 库还获知。
    Play Install Referrer 库

    错误1:

    使用过程中会发现无论设备是否有安装GoogleService, 都会偶发性产生如下崩溃:

    Fatal Exception: java.lang.RuntimeException: Unable to resume activity
     {**}:java.lang.SecurityException: Not allowed to bind to service Intent 
      { act=com.google.android.finsky.BIND_GET_INSTALL_REFERRER_SERVICE cmp=com.android.vending/com.google.android.finsky.externalreferrer.GetInstallReferrerService }
           at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3216)
           at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3247)
           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1458)
           at android.os.Handler.dispatchMessage(Handler.java:102)
           at android.os.Looper.loop(Looper.java:148)
           at android.app.ActivityThread.main(ActivityThread.java:5619)
           at java.lang.reflect.Method.invoke(Method.java)
           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853)
           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:737)
    

    可通过下面try....catch方案进行处理:

    try {
                mReferrerClient.startConnection(installReferrerStateListener);
            } catch (RuntimeException e) {
                CrashLoggingUtils.logException(e, T.UTILS);
                AppLog.e(T.UTILS, "installation referrer start connection failed!", e);
                AnalyticsTracker.track(Stat.INSTALLATION_REFERRER_FAILED);
    
                // just bail if we were not able to connect to the installation referrer service
                stopService();
            }
    

    相关文章

      网友评论

          本文标题:Android 获取当前推荐来源

          本文链接:https://www.haomeiwen.com/subject/zpycqhtx.html