【发布时间】:2022-10-05 22:30:29
【问题描述】:
我正在使用 firebase 制作登录应用程序,我启用了电子邮件/密码和谷歌提供商都在小于 31 的 Api 上完美运行,但在高于谷歌工作的级别上,但电子邮件/密码没有,我不知道问题所在。
我试图做的事情:
-将所有依赖项更新到最新版本。
-添加实现'androidx.work:work-runtime-ktx:2.7.0'
- 以及我找到的每一个解决方案。enter image description here
class AuthenticationActivity : AppCompatActivity() {
private lateinit var binding: ActivityAuthenticationBinding
private val viewModel by viewModels<LoginViewModel>()
companion object {
const val TAG = "LoginFragment"
const val SIGN_IN_RESULT_CODE = 1001
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityAuthenticationBinding.inflate(layoutInflater)
val view = binding.root
setContentView(view)
binding.authButton.setOnClickListener { launchSignInFlow() }
viewModel.authenticationState.observe(this) { authenticationState ->
when (authenticationState) {
LoginViewModel.AuthenticationState.AUTHENTICATED -> switchActivities()
else -> Log.e(
TAG,
"Authentication state that doesn't require any UI change $authenticationState"
)
}
}
}
private fun launchSignInFlow() {
val providers = arrayListOf(
EmailBuilder().build(), GoogleBuilder().build()
)
startActivityForResult(
AuthUI.getInstance().createSignInIntentBuilder().setAvailableProviders(providers)
.build(), AuthenticationActivity.SIGN_IN_RESULT_CODE
)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == SIGN_IN_RESULT_CODE) {
val response = IdpResponse.fromResultIntent(data)
if (resultCode == Activity.RESULT_OK) {
startActivity(Intent(this@AuthenticationActivity, MyApp::class.java))
finish()
return
} else {
if (response == null) {
Log.e("Login", "Login canceled by User")
return
}
if (response.error!!.errorCode == ErrorCodes.NO_NETWORK) {
Log.e("Login", "No Internet Connection")
return
}
if (response.error!!.errorCode == ErrorCodes.UNKNOWN_ERROR) {
Log.e("Login", "Unknown Error")
return
}
}
Log.e("Login", "Unknown sign in response")
}
}
private fun switchActivities() {
val switchActivityIntent = Intent(this, RemindersActivity::class.java)
startActivity(switchActivityIntent)
}
}
private fun sendNotification(triggeringGeofences: List<Geofence>) {
triggeringGeofences.forEach {
val requestId = it.requestId
val remindersRepository: ReminderDataSource by inject()
//Interaction to the repository has to be through a coroutine scope
CoroutineScope(coroutineContext).launch(SupervisorJob()) {
//get the reminder with the request id
val result = remindersRepository.getReminder(requestId)
if (result is Result.Success<ReminderDTO>) {
val reminderDTO = result.data
//send a notification to the user with the reminder details
sendNotification(
this@GeofenceTransitionsJobIntentService, ReminderDataItem(
reminderDTO.title,
reminderDTO.description,
reminderDTO.location,
reminderDTO.latitude,
reminderDTO.longitude,
reminderDTO.id
)
)
}
}
}
}
【问题讨论】:
-
您在使用 Firebase 通知吗?
-
使用通知,但不是来自 firebase。定期发送通知的乐趣
-
你能把那个代码贴出来吗?
-
在帖子中输入图片
-
Sir 图像不包含导致崩溃的代码。我想检查您已实现的通知代码。
标签: android firebase kotlin google-cloud-console