2

I try implement Request SMS Verification in an Android App and my code work like a charm in debug but when i generate sign apk app and run it as release my BroadcastReceiver class seems not execute , i try so many ways like define my receiver as inner class of activity but still the same problem!

definition in manifest in application tag:

  <receiver android:name="com.hellow.CustomViews.BroadcastReceiverr" android:exported="true">
            <intent-filter>
                <action android:name="com.google.android.gms.auth.api.phone.SMS_RETRIEVED"/>
            </intent-filter>
        </receiver>

and this is my reciver class :

public class BroadcastReceiverr extends BroadcastReceiver {


    @Override
    public void onReceive(Context context, Intent intent) {

        if (SmsRetriever.SMS_RETRIEVED_ACTION.equals(intent.getAction())) {

            contextt = context;
            prefs = contextt.getSharedPreferences("MyPrefsFile", MODE_PRIVATE);
            editor = prefs.edit();



            Bundle extras = intent.getExtras();
            Status status = (Status) extras.get(SmsRetriever.EXTRA_STATUS);

            switch(status.getStatusCode()) {
                case CommonStatusCodes.SUCCESS:
                    // Get SMS message contents
                    String message = (String) extras.get(SmsRetriever.EXTRA_SMS_MESSAGE);


                        Toast.makeText(context, "done", Toast.LENGTH_SHORT).show();


                    Log.d("messageeeeee",message);
                    // Extract one-time code from the message and complete verification
                    // by sending the code back to your server.
                    break;
                case CommonStatusCodes.TIMEOUT:
                    // Waiting for SMS timed out (5 minutes)
                    // Handle the error ...
                    Log.d("Faileddd","dfg");
                    break;
            }
        }

and this is intialization of SmsRetrieverClient :

SmsRetrieverClient client = SmsRetriever.getClient(this);
        Task<Void> task = client.startSmsRetriever();

        task.addOnSuccessListener(new OnSuccessListener<Void>() {
            @Override
            public void onSuccess(Void aVoid) {
                Log.d("onSuccess","onSuccessssssssssss");
            }
        });

        task.addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                Log.d("onFailure","onFailureeeeee");
            }
        });

but I wonder how receiver method execute and toast "done" in debug but no in release!

Milind Mevada
  • 3,145
  • 1
  • 14
  • 22
Erfan
  • 3,059
  • 3
  • 22
  • 49
  • Erfan sir, I'm also having same issue please Guide me [My Question](https://stackoverflow.com/questions/68408228/app-is-working-fine-in-usb-debug-mode-but-when-i-generate-signed-apk-and-instal) –  Jul 17 '21 at 03:30

1 Answers1

1

The HashCode is different for debug app and release app, make sure they are same.

Release app:

(In app’s root folder)

keytool -exportcert -alias {keyAlias} -keystore {Keystore/jks file} | xxd -p | tr -d "[:space:]" | echo -n {packageName} cat | shasum -a 256 | tr -d "[:space:]-" | xxd -r -p | base64 | cut -c1-11

Debug app:

(In ~/.android)

keytool -exportcert -alias androiddebugkey -keystore debug.keystore | xxd -p | tr -d "[:space:]" | echo -n {packageName} cat | shasum -a 256 | tr -d "[:space:]-" | xxd -r -p | base64 | cut -c1-11

Harpreet Singh
  • 543
  • 2
  • 10
  • 29