繁体   English   中英

Firebase 分析在真实设备中不起作用

[英]Firebase Analytics doesn't work in real devices

我按照 Android Studio 助手将我的应用程序连接到 Firebase Analytics,它在 AVD 中工作正常并在 DebugView 中显示事件。 但是当我试图在我的手机中运行这个应用程序时,DebugView 没有收到任何事件。

测试 Firebase 的其他功能(实时数据库、Crashlytics 等),所有功能都适用于真实和 AVD。

我用来激活 DebugView 的代码:

adb shell setprop debug.firebase.analytics.app <my.app.package>

接收日志信息的代码:

adb logcat -v time -s FA FA-SVC

在我的手机中运行的应用程序日志:

08-21 11:00:07.240 V/FA      (15356): onActivityCreated
08-21 11:00:07.353 V/FA      (15356): App measurement collection enabled
08-21 11:00:07.363 V/FA      (15356): App measurement enabled for app package, google app id: com.papel.myapplication, 1:7809993896:android:1808a14c9e0b159897469d
08-21 11:00:07.365 I/FA      (15356): App measurement initialized, version: 31049
08-21 11:00:07.366 I/FA      (15356): To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
08-21 11:00:07.366 I/FA      (15356): To enable faster debug mode event logging run:
08-21 11:00:07.366 I/FA      (15356):   adb shell setprop debug.firebase.analytics.app com.papel.myapplication
08-21 11:00:07.366 D/FA      (15356): Debug-level message logging enabled
08-21 11:00:07.527 V/FA      (15356): Connecting to remote service
08-21 11:00:07.545 V/FA      (15356): Detected application was in foreground
08-21 11:00:07.554 V/FA      (15356): Session started, time: 607704075
08-21 11:00:07.608 V/FA      (15356): Connection attempt already in progress
08-21 11:00:07.619 I/FA      (15356): Tag Manager is not found and thus will not be used
08-21 11:00:07.765 V/FA      (15356): Connection attempt already in progress
08-21 11:00:07.801 V/FA      (15356): Connection attempt already in progress
08-21 11:00:07.827 V/FA      (15356): Connection attempt already in progress
08-21 11:00:07.829 V/FA      (15356): Activity resumed, time: 607703994
08-21 11:00:07.952 V/FA      (15356): Connection attempt already in progress
08-21 11:00:07.956 V/FA      (15356): Connection attempt already in progress
08-21 11:00:08.083 D/FA      (15356): Connected to remote service
08-21 11:00:08.086 V/FA      (15356): Processing queued up service tasks: 7
08-21 11:00:08.203 V/FA-SVC  ( 4741): Setting user property: ga_session_number(_sno), 2
08-21 11:00:08.222 V/FA-SVC  ( 4741): Setting user property: ga_session_id(_sid), 1598018407
08-21 11:00:08.241 V/FA-SVC  ( 4741): Logging event: origin=auto,name=session_start(_s),params=Bundle[{ga_event_origin(_o)=auto, ga_session_id(_sid)=1598018407}]
08-21 11:00:09.004 V/FA-SVC  ( 4741): Next upload time is 0
08-21 11:00:09.004 V/FA-SVC  ( 4741): Unscheduling upload
08-21 11:00:09.010 V/FA-SVC  ( 4741): Background event processing time, ms: 769
08-21 11:00:09.032 V/FA-SVC  ( 4741): Logging event: origin=auto,name=screen_view(_vs),params=Bundle[{ga_event_origin(_o)=auto, ga_screen_class(_sc)=MainActivity, ga_screen_id(_si)=7116014326966617553}]
08-21 11:00:09.808 V/FA-SVC  ( 4741): Next upload time is 0
08-21 11:00:09.808 V/FA-SVC  ( 4741): Unscheduling upload
08-21 11:00:09.810 V/FA-SVC  ( 4741): Background event processing time, ms: 779
08-21 11:00:09.826 V/FA-SVC  ( 4741): Saving default event parameters, appId, data size: com.papel.myapplication, 2
08-21 11:00:13.371 V/FA-SVC  ( 4741): Logging event: origin=app,name=app_open,params=Bundle[{item_name=Splash screen opened, ga_event_origin(_o)=app, ga_screen_class(_sc)=MainActivity, ga_screen_id(_si)=7116014326966617553, item_id=7}]
08-21 11:00:14.163 V/FA-SVC  ( 4741): Next upload time is 0
08-21 11:00:14.163 V/FA-SVC  ( 4741): Unscheduling upload
08-21 11:00:14.165 V/FA-SVC  ( 4741): Background event processing time, ms: 796

主要活动代码:

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        
        val mFirebaseAnalytics = FirebaseAnalytics.getInstance(this)
        
        findViewById<FloatingActionButton>(R.id.fab).setOnClickListener {

            val bundle = Bundle()
            bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, "Splash screen opened")
            mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.APP_OPEN, bundle)
        }
    }
}

在 DebugView 屏幕中,只有 AVD 出现在“调试设备”中。

你的代码很好。

当应用程序有 10 个用户时,Analytics 开始显示事件。 在显示事件之前会有延迟。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM