我附上了Java文件,依赖文件和Manifestfile的代码
我在外面宣布
private static final int MY_REQUEST_CODE = 123;
List<AuthUI.IdpConfig> providers = Arrays.asList(
new AuthUI.IdpConfig.PhoneBuilder().build(),
new AuthUI.IdpConfig.FacebookBuilder().build(),
new AuthUI.IdpConfig.EmailBuilder().build(),
new AuthUI.IdpConfig.GoogleBuilder().build(),
new AuthUI.IdpConfig.TwitterBuilder().build());
此后我提到了此
Intent intent = AuthUI.getInstance()
.createSignInIntentBuilder()
.setAvailableProviders(providers)
.setLogo(R.drawable.logo)
.setTheme(R.style.LoginTheme)
.setTosAndPrivacyPolicyUrls(
"https://example.com/terms.html",
"https://example.com/privacy.html")
.build();
最后我提到了startActivity
startActivityForResult(intent,MY_REQUEST_CODE);
现在是我的依赖文件
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0' //1.0.2
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
//Firebase
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.firebaseui:firebase-ui-auth:6.2.0'
//Facebook
implementation 'com.facebook.android:facebook-android-sdk:[5,6)'
implementation 'com.facebook.android:facebook-android-sdk:5.15.1'
implementation 'com.google.android.gms:play-services-auth:18.0.0'
implementation 'com.google.firebase:firebase-auth:19.3.0'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
//Cardview and Material
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.1.0' //1.1.0
//button
implementation 'info.hoang8f:fbutton:1.0.5'
implementation 'com.google.android.gms:play-services-location:17.0.0'
}
这是我的清单文件之后
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Geo_Activity"/>
<activity android:name=".Profile" />
<activity android:name=".HomeActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.facebook.sdk.ApplicationId"
tools:replace="android:value"
android:value="@string/facebook_app_id" />
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
</application>
现在的问题是,当我将Facebuilder()。build()行添加到数组列表中时,应用程序崩溃了
将您的依赖项更改为:
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0' //1.0.2
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
//Firebase
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.firebaseui:firebase-ui-auth:6.2.1'
//Facebook
implementation 'com.facebook.android:facebook-android-sdk:5.15.1'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
//Cardview and Material
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.1.0' //1.1.0
//button
implementation 'info.hoang8f:fbutton:1.0.5'
implementation 'com.google.android.gms:play-services-location:17.0.0'
编辑:
将这两个strng资源添加到您的strng中:
<string name="facebook_application_id">YOUR_APP_ID</string>
<string name="fb_login_protocol_scheme">YOUR_APP_LOGIN_SCHEME</string>
[如果您运行该应用程序,它将立即运行,但是在您获取应用程序ID和方案之前,单击Facebook按钮将不会对用户进行身份验证
要获取应用程序ID,请登录您的Facebook帐户,请访问开发人员页面https://developers.facebook.com/在此处创建一个应用,然后添加“ facebook登录”,然后按照给出的说明进行操作。您会在Facebook应用程序页面的顶部找到您的应用程序ID
仅两个注意事项:
您需要将Firebase控制台页面(启用Facebook身份验证时给出的链接)中的“ OAuth重定向URI”复制到您的Facebook应用程序的设置中。]
您将需要'Key hash',您可以按照此处的说明获得它https://stackoverflow.com/a/25524657/9006761然后,您将其复制到您的Facebook应用程序设置中