From 54c6c2a0a478b4585429c202a53d56d0f4d323f2 Mon Sep 17 00:00:00 2001 From: Bilal Abdeen Date: Fri, 23 Apr 2021 11:11:36 +1000 Subject: [PATCH] Added a permission check to the example code I added a permission check to the example code. https://github.com/briankabiro/react-native-get-sms-android/issues/16 --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index 181c786..9086c54 100644 --- a/README.md +++ b/README.md @@ -198,7 +198,32 @@ Send an sms directly with React without user interaction. ```javascript import SmsAndroid from 'react-native-get-sms-android'; +import { PermissionsAndroid, Alert } from 'react-native'; + +// Note that Google Play Store may NOT allow an application to send SMS messages directly (without user interaction.) +// https://support.google.com/googleplay/android-developer/answer/10208820 + +// Check if permission is granted (if you like) +async componentDidMount() { + try { + let granted = await PermissionsAndroid.request( + PermissionsAndroid.PERMISSIONS.SEND_SMS, { + title: 'Send SMS', + message: 'Need access to send sms', + }, + ); + if (granted === PermissionsAndroid.RESULTS.GRANTED) { + console.log('SEND_SMS permissions granted', granted); + } else { + Alert.alert('SEND_SMS permissions denied'); + console.log('SEND_SMS permissions denied'); + } + } catch (err) { + Alert.alert(err); + } +}; +// actual code SmsAndroid.autoSend( phoneNumber, message,