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.