LoginManager.logInWithReadPermissions 在 Android 上从未解决
Posted
技术标签:
【中文标题】LoginManager.logInWithReadPermissions 在 Android 上从未解决【英文标题】:LoginManager.logInWithReadPermissions never resolved on Android 【发布时间】:2016-10-25 09:51:50 【问题描述】:我得到了适用于 ios 的 sdk,但对于 android,当我调用 LoginManager.logInWithReadPermissions 时,承诺永远不会得到解决。 模态出现,我插入 facebook 凭据,我授权应用程序,模态关闭但没有承诺解决。
这是按钮点击代码(适用于IOS)
LoginManager.logInWithReadPermissions(['public_profile', 'email', 'user_friends', 'user_birthday']).then(
function(result)
console.log('Login success')
else
console.log('Login error')
,
function(error)
console.log('Login error')
);
MainApplication.java
package com.situa;
import android.support.annotation.NonNull;
import com.facebook.react.ReactPackage;
import com.reactnativenavigation.NavigationApplication;
import com.facebook.CallbackManager;
import com.facebook.appevents.AppEventsLogger;
import com.facebook.FacebookSdk;
import com.facebook.reactnative.androidsdk.FBSDKPackage;
import com.BV.LinearGradient.LinearGradientPackage;
import com.react.rnspinkit.RNSpinkitPackage;
import com.cmcewen.blurview.BlurViewPackage;
import com.imagepicker.ImagePickerPackage;
import com.airbnb.android.react.maps.MapsPackage;
import com.learnium.RNDeviceInfo.RNDeviceInfo;
import java.util.List;
import java.util.Arrays;
public class MainApplication extends NavigationApplication
@Override
public boolean isDebug()
return BuildConfig.DEBUG;
private static CallbackManager mCallbackManager = CallbackManager.Factory.create();
protected static CallbackManager getCallbackManager()
return mCallbackManager;
@Override
public void onCreate()
super.onCreate();
FacebookSdk.sdkInitialize(getApplicationContext());
// If you want to use AppEventsLogger to log events.
AppEventsLogger.activateApp(this);
@NonNull
@Override
public List<ReactPackage> createAdditionalReactPackages()
return Arrays.<ReactPackage>asList(
new FBSDKPackage(mCallbackManager),
new LinearGradientPackage(),
new RNSpinkitPackage(),
new BlurViewPackage(),
new ImagePickerPackage(),
new RNDeviceInfo(),
new MapsPackage()
);
MainActivity.java
package com.situa;
import com.reactnativenavigation.controllers.SplashActivity;
import android.content.Intent;
public class MainActivity extends SplashActivity
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
super.onActivityResult(requestCode, resultCode, data);
MainApplication.getCallbackManager().onActivityResult(requestCode, resultCode, data);
在 AndroidManifest 中
<uses-permission android:name="android.permission.INTERNET" />
...
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name" />
...
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
settings.gradle
include ':react-native-fbsdk'
project(':react-native-fbsdk').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fbsdk/android')
build.gradle
repositories
mavenCentral()
dependencies
compile project(':react-native-device-info')
compile project(':react-native-share')
compile project(':react-native-fbsdk')
compile project(':react-native-image-picker')
compile project(':react-native-geocoder')
compile project(':react-native-maps')
compile project(':react-native-blur')
compile project(':react-native-linear-gradient')
compile project(':react-native-spinkit')
compile project(':react-native-vector-icons')
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.facebook.react:react-native:+'
debugCompile project(path: ':react-native-navigation', configuration: 'libraryDebug')
releaseCompile project(path: ':react-native-navigation', configuration: 'libraryRelease')
RN 0.35
react-native-navigation@2.0.0-experimental.105
react-native-fbsdk : 0.3.0
安卓模拟器 SDK 23
【问题讨论】:
我看到您设法通过GitHub 找到了解决方案。您愿意在这里发布它作为答案吗? 【参考方案1】:这里是github上解决方案的要点,供以后参考:
在 MainApplication.java 中添加:
@Override
public void onCreate()
super.onCreate();
setActivityCallbacks(new ActivityCallbacks()
@Override
public void onActivityResumed(Activity activity)
// Do stuff
@Override
public void onActivityPaused(Activity activity)
// Do stuff
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
mCallbackManager.onActivityResult(requestCode, resultCode, data);
);
FacebookSdk.sdkInitialize(getApplicationContext());
// If you want to use AppEventsLogger to log events.
AppEventsLogger.activateApp(this);
【讨论】:
以上是关于LoginManager.logInWithReadPermissions 在 Android 上从未解决的主要内容,如果未能解决你的问题,请参考以下文章