如何摆脱强制关闭添加Facebook Sdk跟踪移动应用程序安装广告?

时间:2014-04-06 21:58:43

标签: android facebook facebook-android-sdk

我正在运行Facebook广告进行移动安装,这就是为什么我将Facebook sdk添加到我的应用程序以跟踪安装,并按照说明添加代码。但现在我正在接近力量,我也检查了所有新的和旧的Android版本。当我评论代码一切正常。

以下是我添加的代码: -

...
@Override
    protected void onResume() {
        super.onResume();
        if (adView != null) {
            adView.resume();
        }

            //Below Code which i added.
        com.facebook.AppEventsLogger.activateApp(context, "263969900451122");
    }

...

全部工作正常但是当我按照指示添加onResume添加此代码时,应用程序强行关闭:

com.facebook.AppEventsLogger.activateApp(context," 263969900451122");


根据请求的日志猫: -

04-07 04:04:54.591: D/dalvikvm(345): DexOpt: couldn't find field Landroid/content/res/Configuration;.smallestScreenWidthDp
04-07 04:04:54.591: W/dalvikvm(345): VFY: unable to resolve instance field 48
04-07 04:04:54.591: D/dalvikvm(345): VFY: replacing opcode 0x52 at 0x0012
04-07 04:04:54.591: D/dalvikvm(345): VFY: dead code 0x0014-0018 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.b (Landroid/content/res/Resources;)Z
04-07 04:04:54.621: I/dalvikvm(345): Could not find method android.app.Activity.getFragmentManager, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.showErrorDialogFragment
04-07 04:04:54.621: W/dalvikvm(345): VFY: unable to resolve virtual method 21: Landroid/app/Activity;.getFragmentManager ()Landroid/app/FragmentManager;
04-07 04:04:54.621: D/dalvikvm(345): VFY: replacing opcode 0x6e at 0x0023
04-07 04:04:54.631: D/dalvikvm(345): VFY: dead code 0x0026-0030 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.showErrorDialogFragment (ILandroid/app/Activity;ILandroid/content/DialogInterface$OnCancelListener;)Z
04-07 04:04:54.661: W/GooglePlayServicesUtil(345): Google Play services is missing.
04-07 04:04:54.681: I/dalvikvm(345): Could not find method java.io.IOException.<init>, referenced from method com.google.android.gms.internal.k.f
04-07 04:04:54.681: W/dalvikvm(345): VFY: unable to resolve direct method 28279: Ljava/io/IOException;.<init> (Ljava/lang/Throwable;)V
04-07 04:04:54.681: D/dalvikvm(345): VFY: replacing opcode 0x70 at 0x0050
04-07 04:04:54.691: D/dalvikvm(345): VFY: dead code 0x0053-0053 in Lcom/google/android/gms/internal/k;.f (Landroid/content/Context;)Lcom/google/android/gms/internal/k$a;
04-07 04:04:54.961: D/dalvikvm(345): DexOpt: --- BEGIN 'ads18470.jar' (bootstrap=0) ---
04-07 04:04:55.141: D/dalvikvm(345): DexOpt: --- END 'ads18470.jar' (success) ---
04-07 04:04:55.141: D/dalvikvm(345): DEX prep '/data/data/com.hello.app/cache/ads18470.jar': unzip in 1ms, rewrite 182ms
04-07 04:04:55.251: D/dalvikvm(345): GC_FOR_MALLOC freed 4110 objects / 299632 bytes in 66ms
04-07 04:04:55.311: I/Ads(345): Use AdRequest.Builder.addTestDevice("B3EEABB8EE11C2BE770B684D95219ECB") to get test ads on this device.
04-07 04:04:55.351: I/Ads(345): Starting ad request.
04-07 04:04:55.731: D/AndroidRuntime(345): Shutting down VM
04-07 04:04:55.731: W/dalvikvm(345): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-07 04:04:55.761: E/AndroidRuntime(345): FATAL EXCEPTION: main
04-07 04:04:55.761: E/AndroidRuntime(345): java.lang.RuntimeException: Unable to resume activity {com.hello.app/com.hello.app.MainActivity}: java.lang.IllegalArgumentException: Both context and applicationId must be non-null
04-07 04:04:55.761: E/AndroidRuntime(345):  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3128)
04-07 04:04:55.761: E/AndroidRuntime(345):  at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3143)
04-07 04:04:55.761: E/AndroidRuntime(345):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2684)
04-07 04:04:55.761: E/AndroidRuntime(345):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-07 04:04:55.761: E/AndroidRuntime(345):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-07 04:04:55.761: E/AndroidRuntime(345):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-07 04:04:55.761: E/AndroidRuntime(345):  at android.os.Looper.loop(Looper.java:123)
04-07 04:04:55.761: E/AndroidRuntime(345):  at android.app.ActivityThread.main(ActivityThread.java:4627)
04-07 04:04:55.761: E/AndroidRuntime(345):  at java.lang.reflect.Method.invokeNative(Native Method)
04-07 04:04:55.761: E/AndroidRuntime(345):  at java.lang.reflect.Method.invoke(Method.java:521)
04-07 04:04:55.761: E/AndroidRuntime(345):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-07 04:04:55.761: E/AndroidRuntime(345):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-07 04:04:55.761: E/AndroidRuntime(345):  at dalvik.system.NativeStart.main(Native Method)
04-07 04:04:55.761: E/AndroidRuntime(345): Caused by: java.lang.IllegalArgumentException: Both context and applicationId must be non-null
04-07 04:04:55.761: E/AndroidRuntime(345):  at com.facebook.AppEventsLogger.activateApp(AppEventsLogger.java:286)
04-07 04:04:55.761: E/AndroidRuntime(345):  at com.hello.app.MainActivity.onResume(MainActivity.java:192)
04-07 04:04:55.761: E/AndroidRuntime(345):  at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1149)
04-07 04:04:55.761: E/AndroidRuntime(345):  at android.app.Activity.performResume(Activity.java:3823)
04-07 04:04:55.761: E/AndroidRuntime(345):  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3118)
04-07 04:04:55.761: E/AndroidRuntime(345):  ... 12 more
04-07 04:04:56.031: I/dalvikvm(345): Could not find method java.io.IOException.<init>, referenced from method com.google.android.gms.ads.identifier.AdvertisingIdClient.g
04-07 04:04:56.071: W/dalvikvm(345): VFY: unable to resolve direct method 28279: Ljava/io/IOException;.<init> (Ljava/lang/Throwable;)V
04-07 04:04:56.071: D/dalvikvm(345): VFY: replacing opcode 0x70 at 0x0032
04-07 04:04:56.071: D/dalvikvm(345): VFY: dead code 0x0035-0035 in Lcom/google/android/gms/ads/identifier/AdvertisingIdClient;.g (Landroid/content/Context;)Lcom/google/android/gms/common/a;
04-07 04:05:00.681: W/GAV3(345): Thread[GAThread,5,main]: Service unavailable (code=1), will retry.
04-07 04:05:00.681: I/GAV3(345): Thread[GAThread,5,main]: No campaign data found.
04-07 04:05:05.711: W/GAV3(345): Thread[Service Reconnect,5,main]: Service unavailable (code=1), using local store.
04-07 04:05:05.922: D/dalvikvm(345): GC_FOR_MALLOC freed 6190 objects / 372304 bytes in 63ms
04-07 04:05:06.572: D/dalvikvm(345): GC_FOR_MALLOC freed 5121 objects / 284528 bytes in 59ms
04-07 04:05:56.649: W/Ads(345): Timed out waiting for ad response.
04-07 04:09:55.822: I/Process(345): Sending signal. PID: 345 SIG: 9

1 个答案:

答案 0 :(得分:2)

从您的logcat中可以清楚地看到您正在传递null上下文。所以在您的代码中进行以下更改。

if(context!=null){
    com.facebook.AppEventsLogger.activateApp(context, "263969900451122");
}

您可以通过

获取申请的上下文
context = this;

context= getActivity().getApplicationContext();

所以在if语句上面写下这些行,看看它是否正常工作。