Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve API Level #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.appmason.jetplayground.ui.screens

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.IntentFilter
import android.os.Build
import android.util.Log
import androidx.annotation.RequiresApi
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
Expand Down Expand Up @@ -58,7 +58,6 @@ import com.appmason.jetplayground.ui.components.OtpInputField
import com.google.android.gms.auth.api.phone.SmsRetriever

@OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class)
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
@Composable
fun OtpScreen(navController: NavHostController) {
val context = LocalContext.current
Expand Down Expand Up @@ -191,7 +190,7 @@ fun OtpScreen(navController: NavHostController) {

}

@RequiresApi(Build.VERSION_CODES.TIRAMISU)
@SuppressLint("UnspecifiedRegisterReceiverFlag")
@Composable
fun OtpReceiverEffect(
context: Context,
Expand Down Expand Up @@ -231,11 +230,19 @@ fun OtpReceiverEffect(
try {
Log.e("OTPReceiverEffect ", "Lifecycle.Event.ON_RESUME")
Log.e("OTPReceiverEffect ", "Registering receiver")
context.registerReceiver(
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
context.registerReceiver(
otpReceiver,
IntentFilter(SmsRetriever.SMS_RETRIEVED_ACTION),
Context.RECEIVER_EXPORTED
)
}else{
context.registerReceiver(
otpReceiver,
IntentFilter(SmsRetriever.SMS_RETRIEVED_ACTION),
Context.RECEIVER_EXPORTED
)
)}


} catch (e: IllegalArgumentException) {
Log.e("OTPReceiverEffect ", "Error in registering receiver: ${e.message}}")
}
Expand All @@ -250,4 +257,4 @@ fun OtpReceiverEffect(
}
}
}
}
}