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

Application crashes when SMS is received. #14

Open
sjdpk opened this issue Oct 2, 2023 · 5 comments
Open

Application crashes when SMS is received. #14

sjdpk opened this issue Oct 2, 2023 · 5 comments

Comments

@sjdpk
Copy link

sjdpk commented Oct 2, 2023

Here, I am using Firebase OTP. When I try to use autofill with the userConsent API .
Here is the Details Log when app crash.

I/PlayCore(17213): UID: [11666] PID: [17213] IntegrityService : reportBinderDeath
I/PlayCore(17213): UID: [11666] PID: [17213] IntegrityService : IntegrityService : Binder has died.
D/AndroidRuntime(17213): Shutting down VM
E/AndroidRuntime(17213): FATAL EXCEPTION: main
E/AndroidRuntime(17213): Process: , PID: 17213
E/AndroidRuntime(17213): java.lang.RuntimeException: Error receiving broadcast Intent { act=com.google.android.gms.auth.api.phone.SMS_RETRIEVED flg=0x200010 pkg=has extras) } in com.google.android.gms.internal.firebase-auth-api.zzaby@81dcfe5
E/AndroidRuntime(17213): at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1708)
E/AndroidRuntime(17213): at android.app.LoadedApk$ReceiverDispatcher$Args$$ExternalSyntheticLambda0.run(Unknown Source:2)
E/AndroidRuntime(17213): at android.os.Handler.handleCallback(Handler.java:938)
E/AndroidRuntime(17213): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(17213): at android.os.Looper.loopOnce(Looper.java:210)
E/AndroidRuntime(17213): at android.os.Looper.loop(Looper.java:299)
E/AndroidRuntime(17213): at android.app.ActivityThread.main(ActivityThread.java:8319)
E/AndroidRuntime(17213): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(17213): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
E/AndroidRuntime(17213): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1038)
E/AndroidRuntime(17213): Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'int java.lang.CharSequence.length()' on a null object reference
E/AndroidRuntime(17213): at java.util.regex.Matcher.reset(Matcher.java:256)
E/AndroidRuntime(17213): at java.util.regex.Matcher.(Matcher.java:167)
E/AndroidRuntime(17213): at java.util.regex.Pattern.matcher(Pattern.java:1040)
E/AndroidRuntime(17213): at com.google.android.gms.internal.firebase-auth-api.zzaby.onReceive(com.google.firebase:firebase-auth@@22.0.0:8)
E/AndroidRuntime(17213): at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1694)
E/AndroidRuntime(17213): ... 9 more
W/OOMEventManagerFK(17213): Failed to mkdir /data/mqsas/hprof/
I/Process (17213): Sending signal. PID: 17213 SIG: 9
Lost connection to device.

@Tkko
Copy link
Owner

Tkko commented Oct 2, 2023

If you are using FIrebaseAuth you don't need to use smart_auth to get the SMS code. You just need to handle verificationCompleted.

    await FirebaseAuth.instance.verifyPhoneNumber(
      verificationCompleted: (PhoneAuthCredential credential) {
        pinController.setText(credential.smsCode);
      },
      verificationFailed: (FirebaseAuthException e) {},
      codeSent: (String verificationId, int? resendToken) {},
      codeAutoRetrievalTimeout: (String verificationId) {},
    );

@sjdpk
Copy link
Author

sjdpk commented Oct 2, 2023

I receive messages on my phone, but the auto-fill feature is not working. Here is my code for this issue. Even after receiving a message, the controller value remains empty. Do I need to update something in this code, or is there any configuration I have to adjust in the project?
Here is my sample code:

import 'dart:developer';

import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:pinput/pinput.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final scaffoldKey = GlobalKey();
  final TextEditingController controller = TextEditingController();

  sendOtp() async {
    FirebaseAuth auth = FirebaseAuth.instance;
    await auth.verifyPhoneNumber(
      phoneNumber: "+9779860718700",
      verificationCompleted: (PhoneAuthCredential credential) async {
        controller.setText(credential.smsCode ?? "");
      },
      verificationFailed: (FirebaseAuthException e) {
        log('The provided phone number is not valid.${e.code}');
      },
      codeSent: (String verificationId, int? resendToken) {},
      codeAutoRetrievalTimeout: (String verificationId) {},
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        key: scaffoldKey,
        appBar: AppBar(
          title: const Text('Plugin example app'),
          actions: [
            IconButton(
              onPressed: () async {
                controller.setText("123456");
              },
              icon: const Icon(Icons.home),
            ),
            IconButton(
              onPressed: () async {
                log("This is log ${controller.text}");
              },
              icon: const Icon(Icons.abc),
            ),
            IconButton(
              onPressed: () => sendOtp(),
              icon: const Icon(Icons.send),
            )
          ],
        ),
        body: Center(
          child: Padding(
            padding: const EdgeInsets.all(40.0),
            child: Pinput(
              length: 6,
              androidSmsAutofillMethod: AndroidSmsAutofillMethod.none,
              // androidSmsAutofillMethod: AndroidSmsAutofillMethod.smsUserConsentApi,
              controller: controller,
            ),
          ),
        ),
      ),
    );
  }
}

@Tkko
Copy link
Owner

Tkko commented Oct 2, 2023

Is the verificationCompleted method called at all?

@sjdpk
Copy link
Author

sjdpk commented Oct 3, 2023

After invoking the function to send the OTP, the reCAPTCHA check occurs in Chrome. Upon successful verification, the page returns to the app. Subsequently, the SMS is received, but the 'verificationCompleted' method doesn't trigger. Is there an error in my code, or do I need to make any updates? Could you please review my code and correct it if necessary? Thank you.

@Tkko
Copy link
Owner

Tkko commented Oct 3, 2023

The code looks good, but I don't understand why firebase_auth is redirecting you to the reCAPTCHA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants