6

I'm using SMS Retriever API to send and receive otp message. When I tested my app in release and debug mode it works fine and automatically read otp but when I uploaded my app on play store it stops working. I have to type manually my otp. Please review my code what I'm doing wrong.

I have generated 11 character string Hash code using AppSignatureHashHelper class and pass 11 character code to the server. Then I read sms using Broadcast receiver and parse otp from sms and send back to server.

/////////////////Sending phone number and hashKey to server/////////////

phoneNo = phoneText.getText().toString();
            System.out.println( phoneNo );
            params.put( "mob_no", phoneNo );
            //String debugHashKey = "Yq%2BZIxNoG%2BK";
            //String releaseHashKey = "h9mVMD4POjg";
            String appSigningKey = "b4epgGrrtyp";
            params.put( "uniqueKey", releaseHashKey );
            asyncHttpClient.post( mob_validate, params, new JsonHttpResponseHandler() {
                @Override
                public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                    try {
                        System.out.println( "onSuccess" );
                        status = response.getString( "status" );
                        msg = response.getString( "msg" );
                        Toast.makeText( getApplicationContext(), msg, Toast.LENGTH_SHORT ).show();
                        if (status.equals( "success" )) {
                            Intent intent = new Intent( MainActivity.this, OTPConfirmationActivity.class );
                            intent.putExtra( "phone_no", phoneNo );
                            startActivity( intent );
                            finish();
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }

                @Override
                public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
                    //Toast.makeText( getApplicationContext(), R.string.onFailure, Toast.LENGTH_SHORT ).show();
                }

/////////////////Reading sms using broadcast receiver and send back to server//////////////////////

params.put( "otp", otp );
            params.put( "mob_no", phoneNo );
            asyncHttpClient.post( verify_otp, params, new JsonHttpResponseHandler() {
                @Override
                public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                    try {
                        status = response.getString( "status" );
                        msg = response.getString( "msg" );
                        Toast.makeText( OTPConfirmationActivity.this, msg, Toast.LENGTH_SHORT ).show();
                        if (status.equals( "success" )) {
                            endTimer();
                            sharedPreferences.edit().putBoolean( "logged", true ).apply();
                            Intent intent = new Intent( getBaseContext(), HomeActivity.class );
                            startActivity( intent );
                            finish();
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }

                @Override
                public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
                    //Toast.makeText( getApplicationContext(), R.string.onFailure, Toast.LENGTH_SHORT ).show();
                }

////////////Build.gradle file////////////////////////

android {
    signingConfigs {
        release {
            storeFile file('/home/eazysoft/Documents/finalKey/releaseKey.jks')
            storePassword 'password'
            keyAlias = 'upload'
            keyPassword 'password'
        }
    }
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.eazysoft.lookAround"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 3
        versionName "1.0.2"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
        signingConfig signingConfigs.release
    }
    buildTypes {
        release {
            minifyEnabled true
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
            debuggable = true
        }

        debug {
            debuggable true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha4'
    testImplementation 'junit:junit:4.13-beta-2'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:exifinterface:28.0.0'

    implementation 'com.google.android.gms:play-services-maps:16.1.0'
    implementation 'com.google.android.gms:play-services-location:16.0.0'
    implementation 'com.google.android.gms:play-services-base:16.1.0'
    implementation 'com.google.android.gms:play-services-identity:16.0.0'
    implementation 'com.google.android.gms:play-services-auth:16.0.1'
    implementation 'com.google.android.gms:play-services-auth-api-phone:16.0.0'

    implementation 'com.loopj.android:android-async-http:1.4.9'
}

Please review my code and help me with the configuration on google play store.

Solution: I found a solution to my question and it is a problem with the configuration.

Step 1: After uploading your app to google play store google generated two certificates (App signing) first is upload certificate(Upload key) which is your app signing key you generated. This key is used for updating or uploading your app to the Google play store.

Second is App signing certificate which is used when a user installs your app from play store. This certificate helps us to generate another 11 digit string code. To do so first download App signing certificate.

Step 2: Use your android studio terminal and paste this piece of command

keytool -importcert -alias myalias -file /home/Downloads/deployment_cert.der -keystore certificate.jks -storepass mypassword

Keep the alias name and storepass as it is only change file path

Step 3: After running this command one message will show "Trust this certificate? [no]: " then type 'y' after that another message will show "Certificate was added to keystore". This certificate.jks file stored in your project or just search this file.

Step 4: After generating certificate.jks file generate 11 digit hash code using following command

keytool -exportcert -alias myalias -keystore /home/user/AndroidStudioProjects/LookAround/certificate.jks | xxd -p | tr -d "[:space:]" | echo -n com.root.lookAround `cat` | sha256sum | tr -d "[:space:]-" | xxd -r -p | base64 | cut -c1-11 

Keep alias name same you provide while generating certificate.jks file i.e myalias. When it will ask you for password provide "mypassword" and you are done. Send this 11 digit hash code to the server and embedded it to sms format.

Rohan
  • 96
  • 8
  • Can you paste an example of the message you are receiving in phone? – mnp343 Apr 29 '19 at 12:42
  • <#> Your verification code is : 4156 hFmVMD4X1DR – Rohan Apr 29 '19 at 12:51
  • I am unable to identify as of now, but you should double check with your hash. And Play Store doesn't require any configuration. – mnp343 Apr 29 '19 at 12:59
  • It works fine when I tested before uploading on play store. I have also rechecked my hash code using the terminal command – Rohan Apr 29 '19 at 13:07
  • 1
    Found the answer to my question read the solution – Rohan Apr 30 '19 at 10:55
  • Glad you found what was the problem. – mnp343 Apr 30 '19 at 14:42
  • @Rohan , Hi rohan this 11 digit(in your way) is for debug mode or release mode how can we found it, earlier i used app signer and i earn difference 11 digit in debug mode and release mode. – milad salimi Mar 29 '20 at 07:10
  • Hi @miladsalimi, As I have uploaded my app to play store in release mode so the 11 digit hashcode generated itself in release mode. Yes, you will get different 11 digit hashcode for release and debug mode but you have to choose release mode if you are uploading your app to play store with debuggable false. – Rohan Mar 29 '20 at 14:29
  • @Rohan, Hi rohan , in step 2 it wants to me `keypassword` when i import it , i face with this error : `keytool error: java.lang.Exception: Public keys in reply and keystore don't match` what is your idea? – milad salimi Mar 30 '20 at 17:30
  • @Rohan , Rohan in step 2 `certificate.jks` does not need to address of keystore.jks?? – milad salimi Mar 30 '20 at 18:54
  • @Rohan , Hi Rohan where is the address of `certificate.jks`? – milad salimi Mar 30 '20 at 21:47
  • Hi @miladsalimi, You first have to download "deployment_cert.der" file from your play store console. If you have already done that then you have to create a certificate.jks file using step 2 command. We don't need the address of the certificate.jks file since we are creating a certificate.jks file. This file is created in your current terminal path. To see the current terminal path run 'pwd' command. – Rohan Mar 31 '20 at 04:41
  • Thank you @Rohan , by this way our sms automatic does not work in other store. – milad salimi Mar 31 '20 at 08:09
  • @Rohan that worked for me. the documentation given [here](https://developers.google.com/identity/sms-retriever/verify) is confusing. – Vishal Naikawadi Mar 19 '21 at 15:13
  • @vishal I'm glad that it helped to you. If you liked my question and solution please do upvote my question – Rohan Apr 10 '21 at 10:54

0 Answers0