我有一个带有这个activityResultLauncher的代码去firebaseAuthUI:
//used for login
this.loginActivityLauncher = registerForActivityResult(new FirebaseAuthUIActivityResultContract(),
result -> {
String s;
//result success
if(result.getResultCode() == RESULT_OK) {
user.SignIn(MainActivity.this);
s = getString(R.string.welcome);
}
//user exited login screen
else if(result.getIdpResponse() == null){
s = getString(R.string.error_login_cancelled);
}
//error
else {
s = Objects.requireNonNull(result.getIdpResponse().getError()).getLocalizedMessage();
Utils.AlertBuild(null, s, null, MainActivity.this).show();
}
updateData(s);//update screen
});
但是,当我使用较新的操作系统尝试我的应用程序时,应用程序会因以下错误而崩溃:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.bigproject, PID: 2013
java.lang.IllegalArgumentException: com.example.bigproject: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
at android.app.PendingIntent.checkFlags(PendingIntent.java:401)
at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:484)
at android.app.PendingIntent.getActivity(PendingIntent.java:470)
at android.app.PendingIntent.getActivity(PendingIntent.java:434)
at com.google.android.gms.internal.auth-api.zzr.zzc(com.google.android.gms:play-services-auth@@19.0.0:19)
at com.google.android.gms.auth.api.credentials.CredentialsClient.getHintPickerIntent(com.google.android.gms:play-services-auth@@19.0.0:10)
at com.firebase.ui.auth.ui.phone.CheckPhoneHandler.fetchCredential(CheckPhoneHandler.java:28)
at com.firebase.ui.auth.ui.phone.CheckPhoneNumberFragment.setDefaultCountryForSpinner(CheckPhoneNumberFragment.java:246)
at com.firebase.ui.auth.ui.phone.CheckPhoneNumberFragment.onActivityCreated(CheckPhoneNumberFragment.java:130)
at androidx.fragment.app.Fragment.performActivityCreated(Fragment.java:2996)
at androidx.fragment.app.FragmentStateManager.activityCreated(FragmentStateManager.java:580)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:285)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2189)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2100)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3138)
at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:3072)
at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:251)
at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:502)
at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:246)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1467)
at android.app.Activity.performStart(Activity.java:7945)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3750)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2272)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7902)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:933)
我没有找到一种方法来转换或启动带有待处理意图的 firebaseAuthUI,我也通过这段代码制作了 Intent,但我不知道如何将其更改为 PendingIntent:
public Intent createIntent() {
return AuthUI.getInstance()
.createSignInIntentBuilder()
.setAvailableProviders(Collections.singletonList(new AuthUI.IdpConfig.PhoneBuilder().build()))
.setLogo(R.drawable.main_act_img)
.build();
}