Automatically Pick Mobile Number and Otp autofill without Sms Permission in Debug/Release/Production

Varun Singhal
2 min readOct 1, 2023

--

First We Pick Mobile Number

Step 1 — Install react-native-device-number

Step2 — import DeviceNumber from ‘react-native-device-number’;

DeviceNumber.get().then(res => {console.log ( res.mobileNumber.replace(‘+91’, ‘’).trim())
});

Here you get Mobile no , then you have use an Api Call for send OTP

Step 3 — npm install react-native-otp-auto-fill

import { Alert, NativeSyntheticEvent, StyleSheet, View } from 'react-native';
import OtpAutoFillViewManager from 'react-native-otp-auto-fill';
const handleComplete = ({
nativeEvent: { code },
}: NativeSyntheticEvent<{ code: string }>) => {
Alert.alert('OTP Code Received!', code);
};

// This is only needed once to get the Android Signature key for SMS body
const handleOnAndroidSignature = ({
nativeEvent: { code },
}: NativeSyntheticEvent<{ code: string }>) => {
console.log('Android Signature Key for SMS body:', code);
};

return (
<View style={styles.container}>
<OtpAutoFillViewManager
onComplete={handleComplete}
onAndroidSignature={handleOnAndroidSignature}
style={styles.box}
length={4} // Define the length of OTP code. This is a must.
/>
</View>
);

Example of Sms Body

Your ExampleApp code is: 8468

4H456ffg/hb1

Step 4 — Now question is How we get signature in Debug / Release / Production which we have to send in sms body

In Debug Mode

In Debug Mode you get Signature

const handleOnAndroidSignature = ({
nativeEvent: { code },
}: NativeSyntheticEvent<{ code: string }>) => {
console.log('Android Signature Key for SMS body:', code);
};

In Release Mode

You get hash signature from keystore

keytool -exportcert -alias PlayDeploymentCert -keystore android.keystore | xxd -p | tr -d "[:space:]" | echo -n com.example.myapp `cat` | sha256sum | tr -d "[:space:]-" | xxd -r -p | base64 | cut -c1-11

Then password prompt please enter password and get android hash

Production

First of all go to your Google Play Console and download your app signing certificate(deployment_cert.der). Then go to folder where you have installed your Java Jdk and open the bin folder in terminal. Then type the following command to import the app signing certificate into a temporary key store:

keytool -importcert -file deployment_cert.der -keystore temporary.keystore -alias PlayDeploymentCert

In the docs which you have mentioned above, all the steps are explained but to just get the Hash Key for your app type the following command,

Then

keytool -exportcert -alias PlayDeploymentCert -keystore MyProductionKeys.keystore | xxd -p | tr -d "[:space:]" | echo -n com.example.myapp `cat` | sha256sum | tr -d "[:space:]-" | xxd -r -p | base64 | cut -c1-11

Then password prompt please enter password and get android hash

--

--

Varun Singhal
Varun Singhal

Written by Varun Singhal

React Native/iOS Developer (Mobile App Developer)

Responses (1)