Firebase Analytics在实际设备中不起作用

时间:2020-08-21 14:10:29

标签: android firebase firebase-analytics

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

测试Firebase的其他功能(实时数据库,Crashlytics等),都可以在Real和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

MainActivity代码:

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出现在“调试设备”中。

1 个答案:

答案 0 :(得分:1)

您的代码很好。

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