首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Facebook应用程序事件不起作用

Facebook应用程序事件不起作用
EN

Stack Overflow用户
提问于 2021-12-08 07:45:31
回答 1查看 1.3K关注 0票数 1

我有一个灵活的应用程序,我的任务是使用facebook应用程序事件记录用户事件。我已将以下包添加到我的pubspec.yaml中:

代码语言:javascript
运行
复制
facebook_app_events: ^0.14.7

在build.gradle中添加了以下内容:

代码语言:javascript
运行
复制
buildscript {
    ext.kotlin_version = '1.5.10'
    repositories {
        google()
        jcenter()
        mavenCentral() //**Added as per fb docs
    }

在app/build.gradle中添加了以下内容:

代码语言:javascript
运行
复制
dependencies {
    implementation 'com.facebook.android:facebook-android-sdk:latest.release'

}

在AndroidManifest中,我添加了以下元数据:

代码语言:javascript
运行
复制
<application
    ..//
        <meta-data android:name="com.facebook.sdk.ApplicationId"
            android:value="app id"/>
     

    </application>

稍后,在我的颤栗视图中,我完成了以下实现:

代码语言:javascript
运行
复制
static final facebookSDK = FacebookAppEvents();

TextButton(
                          onPressed: () {
                            facebookSDK.logEvent(
                              name: 'button_clicked',
                              parameters: {
                                'button_id': 'the_clickme_button',
                              },
                            );
                          },
                          child: Text("Trigger Payment Info Click")),

单击此按钮时,将得到以下错误,而不是将logEvent发送到fb:

代码语言:javascript
运行
复制
E/MethodChannel#flutter.oddbit.id/facebook_app_events(32475): Failed to handle method call
E/MethodChannel#flutter.oddbit.id/facebook_app_events(32475): kotlin.UninitializedPropertyAccessException: lateinit property appEventsLogger has not been initialized
E/MethodChannel#flutter.oddbit.id/facebook_app_events(32475):   at id.oddbit.flutter.facebook_app_events.FacebookAppEventsPlugin.handleLogEvent(FacebookAppEventsPlugin.kt:99)
E/MethodChannel#flutter.oddbit.id/facebook_app_events(32475):   at id.oddbit.flutter.facebook_app_events.FacebookAppEventsPlugin.onMethodCall(FacebookAppEventsPlugin.kt:48)
E/MethodChannel#flutter.oddbit.id/facebook_app_events(32475):   at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/MethodChannel#flutter.oddbit.id/facebook_app_events(32475):   at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:84)
E/MethodChannel#flutter.oddbit.id/facebook_app_events(32475):   at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:865)
E/MethodChannel#flutter.oddbit.id/facebook_app_events(32475):   at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#flutter.oddbit.id/facebook_app_events(32475):   at android.os.MessageQueue.next(MessageQueue.java:336)
E/MethodChannel#flutter.oddbit.id/facebook_app_events(32475):   at android.os.Looper.loop(Looper.java:174)
E/MethodChannel#flutter.oddbit.id/facebook_app_events(32475):   at android.app.ActivityThread.main(ActivityThread.java:7438)
E/MethodChannel#flutter.oddbit.id/facebook_app_events(32475):   at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#flutter.oddbit.id/facebook_app_events(32475):   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/MethodChannel#flutter.oddbit.id/facebook_app_events(32475):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:989)
E/flutter (32475): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(error, lateinit property appEventsLogger has not been initialized, null, kotlin.UninitializedPropertyAccessException: lateinit property appEventsLogger has not been initialized
E/flutter (32475):  at id.oddbit.flutter.facebook_app_events.FacebookAppEventsPlugin.handleLogEvent(FacebookAppEventsPlugin.kt:99)
E/flutter (32475):  at id.oddbit.flutter.facebook_app_events.FacebookAppEventsPlugin.onMethodCall(FacebookAppEventsPlugin.kt:48)
E/flutter (32475):  at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/flutter (32475):  at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:84)
E/flutter (32475):  at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:865)
E/flutter (32475):  at android.os.MessageQueue.nativePollOnce(Native Method)
E/flutter (32475):  at android.os.MessageQueue.next(MessageQueue.java:336)
E/flutter (32475):  at android.os.Looper.loop(Looper.java:174)
E/flutter (32475):  at android.app.ActivityThread.main(ActivityThread.java:7438)
E/flutter (32475):  at java.lang.reflect.Method.invoke(Native Method)
E/flutter (32475):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/flutter (32475):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:989)
E/flutter (32475): )
E/flutter (32475): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
E/flutter (32475): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18)
E/flutter (32475): <asynchronous suspension>

我删除了.gradle文件夹,运行时仍然没有任何帮助。我对土生土长的科林知之甚少。任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-01-19 11:00:33

如果您已经执行了包中所有必需的步骤,并且得到了这种类型的错误。只需在AndroidManifest中执行以下操作

就在包建议我们添加的元数据下面:

代码语言:javascript
运行
复制
<meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id"/>

在上面的元数据下面的清单中添加以下代码

代码语言:javascript
运行
复制
        <activity
        android:name="com.facebook.FacebookActivity"
        android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
        android:label="appname" />
    <activity
        android:name="com.facebook.CustomTabActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data android:scheme="@string/fb_login_protocol_scheme" />
        </intent-filter>
    </activity>

您的舱单应如下所示:

代码语言:javascript
运行
复制
<application
    android:name="io.flutter.app.FlutterApplication"
    android:icon="@mipmap/ic_launcher"
    android:label="appname"
    android:usesCleartextTraffic="true">
    
    <meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id"/>
    <activity
        android:name="com.facebook.FacebookActivity"
        android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
        android:label="appname" />
    <activity
        android:name="com.facebook.CustomTabActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data android:scheme="@string/fb_login_protocol_scheme" />
        </intent-filter>
    </activity>

    <activity
        android:name=".MainActivity"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:launchMode="singleTop"
        android:screenOrientation="portrait"
        android:theme="@style/LaunchTheme"
        android:windowSoftInputMode="adjustResize">
        <!-- Specifies an Android theme to apply to this Activity as soon as
             the Android process has started. This theme is visible to the user
             while the Flutter UI initializes. After that, this theme continues
             to determine the Window background behind the Flutter UI. -->
        <meta-data
            android:name="io.flutter.embedding.android.NormalTheme"
            android:resource="@style/NormalTheme" />
        
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@drawable/ic_notification" />

        <meta-data
            android:name="com.google.firebase.messaging.default_notification_color"
            android:resource="@color/colorAccent" />

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="FLUTTER_NOTIFICATION_CLICK" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

</application>
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70271507

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档