我的应用支持 Android 1.5 (API3) 到 4.1.2 (API16)。当我添加 GoogleAnalyticsV2 并重新测试它时 - 它在模拟器中出现 API3 错误:
11-08 20:00:58.813: E/dalvikvm(732): Could not find method
android.content.pm.PackageManager.getInstallerPackageName, referenced
from method
com.google.analytics.tracking.android.GAThread.fillAppParameters 11-08
20:00:58.887: W/dalvikvm(732): VFY: unable to resolve virtual method
226: Landroid/content/pm/PackageManager;.getInstallerPackageName
(Ljava/lang/String;)Ljava/lang/String; 11-08 20:00:58.925:
W/dalvikvm(732): VFY: rejecting opcode 0x6e at 0x000c 11-08
20:00:58.934: W/dalvikvm(732): VFY: rejected
Lcom/google/analytics/tracking/android/GAThread;.fillAppParameters
(Ljava/util/Map;)V 11-08 20:00:58.934: W/dalvikvm(732): Verifier
rejected class Lcom/google/analytics/tracking/android/GAThread; 11-08
20:00:58.964: D/AndroidRuntime(732): Shutting down VM 11-08
20:00:58.964: W/dalvikvm(732): threadid=3: thread exiting with
uncaught exception (group=0x4000fe70) 11-08 20:00:58.985:
E/AndroidRuntime(732): Uncaught handler: thread main exiting due to
uncaught exception 11-08 20:00:59.084: E/AndroidRuntime(732):
java.lang.VerifyError: com.google.analytics.tracking.android.GAThread
11-08 20:00:59.084: E/AndroidRuntime(732): at
com.google.analytics.tracking.android.GoogleAnalytics.<init>(GoogleAnalytics.java:55)
11-08 20:00:59.084: E/AndroidRuntime(732): at
com.google.analytics.tracking.android.GoogleAnalytics.getInstance(GoogleAnalytics.java:91)
11-08 20:00:59.084: E/AndroidRuntime(732): at
com.google.analytics.tracking.android.EasyTracker.setContext(EasyTracker.java:309)
11-08 20:00:59.084: E/AndroidRuntime(732): at
com.tonycode.primenumbers.ListNumsActivity.onCreate(ListNumsActivity.java:32)
11-08 20:00:59.084: E/AndroidRuntime(732): at
...
虽然在真实设备上测试 Android 2.3.3 和 Android 4.0.3 都可以。
在上面的日志中,我发现 Analytics 无法启动,因为 API3 中不存在方法 android.content.pm.PackageManager.getInstallerPackageName,它仅存在于 [API5][http://developer.android.com /reference/android/content/pm/PackageManager.html#getInstallerPackageName(java.lang.String] 1
那么,您能帮帮我吗 - (1) 有什么方法可以在 API3 和 API4 中启用 GoogleAnalyticsV2 吗?(2) 如果没有,如果应用程序安装在 API3/4 上,如何在代码中禁用 GoogleAnalyticsV2?