facebook + android:只有全屏不透明活动才能请求定位

时间:2017-11-03 10:09:09

标签: android facebook android-8.0-oreo

Facebook SDK版 4.27.0

Android操作系统版 8.0

应用程序崩溃异常,这是我在Crashlytics上找到的跟踪日志:

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx.yyy/com.facebook.FacebookActivity}: java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2822)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2897)
       at android.app.ActivityThread.-wrap11(Unknown Source)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1598)
       at android.os.Handler.dispatchMessage(Handler.java:105)
       at android.os.Looper.loop(Looper.java:251)
       at android.app.ActivityThread.main(ActivityThread.java:6563)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation
       at android.app.Activity.onCreate(Activity.java:986)
       at android.support.v4.app.SupportActivity.onCreate(SupportActivity.java:66)
       at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:285)
       at com.facebook.FacebookActivity.onCreate(FacebookActivity.java:62)
       at android.app.Activity.performCreate(Activity.java:6975)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2775)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2897)
       at android.app.ActivityThread.-wrap11(Unknown Source)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1598)
       at android.os.Handler.dispatchMessage(Handler.java:105)
       at android.os.Looper.loop(Looper.java:251)
       at android.app.ActivityThread.main(ActivityThread.java:6563)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

任何人都可以帮我吗?

PS: 在Android Source中,在查看此行号987后,似乎这一行是罪魁祸首。

https://android.googlesource.com/platform/frameworks/base.git/+/master/core/java/android/app/Activity.java#1002

另外,在我的清单中:

<activity
    android:name="com.facebook.FacebookActivity"
    android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
    android:label="@string/app_name"
    android:screenOrientation="portrait" />

6 个答案:

答案 0 :(得分:27)

删除此属性:

android:screenOrientation="portrait"
来自FacebookActivity标记的

可能会解决问题。

答案 1 :(得分:2)

当我从样式问题中删除此<item name="android:windowIsTranslucent">true</item>时,问题就解决了。

答案 2 :(得分:1)

根据最新的fb集成指南,我们无需指定导致android 8.0崩溃的主题或方向。因此,我们应该使用最新的fb sdk及其新设置:

<activity android:name="com.facebook.FacebookActivity"
    android:configChanges=
            "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
    android:label="@string/app_name" />

https://developers.facebook.com/docs/facebook-login/android/#manifest

答案 3 :(得分:0)

从样式菜单中删除此行

  <item name="android:windowIsTranslucent">true</item>

答案 4 :(得分:0)

已更改

<style name="AppTheme" parent="android:Theme.Translucent.NoTitleBar"></style>`

 <style name="AppTheme" parent="android:Theme.Holo.NoActionBar.TranslucentDecor"></style>

然后删除

<item name="android:windowIsTranslucent">true</item>

答案 5 :(得分:0)

在Android O及更高版本中,设置该错误会发生

 android:screenOrientation="portrait"

此代码写在AndroidManifest文件中:

<activity
android:name="com.google.android.gms.ads.AdActivity"     android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Translucent"></activity>

manifest文件中删除

android:screenOrientation="portrait"

并将以下代码添加到setContentView之前的oncreate活动中:

 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

这将解决illegalStateException问题/