我在我的应用程序中使用以下代码在 web 视图中接受 cookie:
CookieSyncManager.createInstance(this);
CookieSyncManager.getInstance().startSync();
CookieManager.setAcceptFileSchemeCookies(true);
CookieManager.getInstance().setAcceptCookie(true);
在 Android 4.x 上运行它运行良好。但我也在使用 2.3.6 的手机上对其进行了测试,并在那里崩溃并出现以下堆栈跟踪:
10-13 22:34:20.519: E/AndroidRuntime(2371): FATAL EXCEPTION: main
10-13 22:34:20.519: E/AndroidRuntime(2371): java.lang.NoSuchMethodError: android.webkit.CookieManager.setAcceptFileSchemeCookies
10-13 22:34:20.519: E/AndroidRuntime(2371): at de.fblike.facebook.FacebookActivity.onCreate(FacebookActivity.java:28)
10-13 22:34:20.519: E/AndroidRuntime(2371): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-13 22:34:20.519: E/AndroidRuntime(2371): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
10-13 22:34:20.519: E/AndroidRuntime(2371): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
10-13 22:34:20.519: E/AndroidRuntime(2371): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-13 22:34:20.519: E/AndroidRuntime(2371): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
10-13 22:34:20.519: E/AndroidRuntime(2371): at android.os.Handler.dispatchMessage(Handler.java:99)
10-13 22:34:20.519: E/AndroidRuntime(2371): at android.os.Looper.loop(Looper.java:130)
10-13 22:34:20.519: E/AndroidRuntime(2371): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-13 22:34:20.519: E/AndroidRuntime(2371): at java.lang.reflect.Method.invokeNative(Native Method)
10-13 22:34:20.519: E/AndroidRuntime(2371): at java.lang.reflect.Method.invoke(Method.java:507)
10-13 22:34:20.519: E/AndroidRuntime(2371): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
10-13 22:34:20.519: E/AndroidRuntime(2371): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
10-13 22:34:20.519: E/AndroidRuntime(2371): at dalvik.system.NativeStart.main(Native Method)
所以我问自己:我该如何修复它?好像2.3.6不支持这种方法。