tkporter / react-native-sms Goto Github PK
View Code? Open in Web Editor NEWSMS composer with callbacks for iOS and Android
SMS composer with callbacks for iOS and Android
Our logs show that the most popular crash of our app is
Caused by java.lang.NullPointerException
Attempt to invoke virtual method 'void com.tkporter.sendsms.SendSMSModule.onActivityResult(android.app.Activity, int, int, android.content.Intent)' on a null object reference
com.tkporter.sendsms.SendSMSPackage.onActivityResult (SendSMSPackage.java:49)
So, I understand that the sendSms
in this line is null
.
That's called from the app's MainActivity.java
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
SendSMSPackage.getInstance().onActivityResult(requestCode, resultCode, data);
...
Any idea on what's the problem?
Thanks in advance.
Hello,
When running in releaseMode
on real Android devices (tested on HTC one, samsung galaxy s7, samsung galaxy s5) the app crashes at the moment we run SendSMS.send
.
When connecting the device to the phone and running adb logcat gives a NativeArgumentsParseException: SendSMS.send got 4 arguments, expected 3
the full error looks like this :
.... AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
.... AndroidRuntime: Process: com.sp00t, PID: 1903
.... AndroidRuntime: com.facebook.react.bridge.NativeArgumentsParseException: SendSMS.send got 4 arguments, expected 3
.... AndroidRuntime: at com.facebook.react.bridge.BaseJavaModule$JavaMethod.invoke(BaseJavaModule.java:318)
.... AndroidRuntime: at com.facebook.react.cxxbridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:136)
.... AndroidRuntime: at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
.... AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:751)
.... AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
.... AndroidRuntime: at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
.... AndroidRuntime: at android.os.Looper.loop(Looper.java:154)
.... AndroidRuntime: at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:196)
.... AndroidRuntime: at java.lang.Thread.run(Thread.java:762)
The code sending the sms looks like this :
Alert.alert(
`${title}`,
message,
[
{
text: I18n.t('send'),
style: 'cancel',
onPress: () => {
SendSMS.send({
body: I18n.t('smsText'),
recipients: smsList.map(contact => contact.phone),
successTypes: ['sent', 'queued']
}, (completed, cancelled, error) => {
console.log(`SMS Callback: Completed: ${completed} Cancelled: ${cancelled} Error: ${error}`)
})
}
},
{
text: I18n.t('cancel'),
onPress: () => {
}
}
]
)
Changing the API
version does not seem to help (tested with 3 different android SDK version in the build.gradle
.
Interestingly It works on the emulator
Hey @tkporter, thanks for the great package :)
Just wondering why we need to request PermissionsAndroid.PERMISSIONS.READ_SMS
permission?
Also, we don't currently use the M Permission model in our android app, is it possible to declare this permission in the manifest instead of requesting it on send
?
New at this so apologies. In MainApplication.java is the following:
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
return packages;
}
but the readme shows:
protected List<ReactPackage> getPackages() {
//some variables
return Arrays.<ReactPackage>asList(
//probably some items like `new BlahPackage(),`
//just add into the list (don't forget commas!):
SendSMSPackage.getInstance()
);
}
Is there a way to get "SendSMSPackage.getInstance()" to work in there?
I got following error when npm install
npm ERR! code EISGIT
npm ERR! path /home/ksbae/overclass/node_modules/react-native-sms
npm ERR! git /home/ksbae/overclass/node_modules/react-native-sms: Appears to be a git repo or submodule.
npm ERR! git /home/ksbae/overclass/node_modules/react-native-sms
npm ERR! git Refusing to remove it. Update manually,
npm ERR! git or move it out of the way first.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/ksbae/.npm/_logs/2020-01-10T06_30_28_458Z-debug.log
avishayil/react-native-restart#71 (comment)
It looks like .git is included in library deployment.
@tkporter Hello again :D
Fatal Exception: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND typ=text/plain...
It is quite rare but some Android devices do not have any apps which may consume android.intent.action.SEND. Need to add checking for it :)
Also small suggestion, please add TAG to Commit where you bump version number :)
In the readme, there is a section describing
Currently, only user-initiated sending of an SMS is supported. This means you can't use react-native-sms to send an SMS in the background-- this package displays the native SMS view (populated with any recipients/body you want), and gives a callback describing the status of the SMS (completed/cancelled/error). PRs are welcome!
Is there a particular reason for not doing it? I'm very new to this and thanks your time for answering!
Getting the following warning when we use your library:
"PermissionsAndroid.requestPermission" is deprecated. Use "PermissionsAndroid.request" instead
I think it's how the permission is checked in index.js.
Not sure if this is a problem with Android or the lib, but figured I'd bring this up.
If I create an SMS to two recipients in Android, my screen looks like this:
However if I create an SMS to two recipients via the lib, I get this:
Notice how only the last recipient is shown. This is what the "People & Options" menu looks like:
It appears that both numbers are being added (hence the block text) but that only the last is taken into account (hence the "people in this conversation" list). I'm not testing this on an actual device yet so I don't know if it's just a display issue or if the SMS will actually only be sent to the second recipient, but at the very least this could be confusing for the user from a UX standpoint.
Hi @tkporter
Thank you for your awesome package.
I'm able to integrate your package to my RN-app.
But I'm facing an issue while checking the callback function, it always return error = false.
I use same code as your example:
SendSMS.send({
body: 'The default body of the SMS!',
recipients: ['6285921010XXX'],
successTypes: ['sent', 'queued'],
allowAndroidSendWithoutReadPermission: true
}, (completed, cancelled, error) => {
console.log('SMS Callback: \ncompleted: ' + completed + '\ncancelled: ' + cancelled + '\nerror: ' + error);
});
How to fix this?
Need your advice.
Thanks before.
Version:
react-native; 0.57.7
react-native-sms: 1.9.0
It's not letting npm to install other packages after installing react-native-sms in the project
npm ERR! path /var/www/html/project-name/node_modules/react-native-sms
npm ERR! code EISGIT
npm ERR! git /var/www/html/project-name/node_modules/react-native-sms: Appears to be a git repo or submodule.
npm ERR! git /var/www/html/project-name/node_modules/react-native-sms
npm ERR! git Refusing to remove it. Update manually,
npm ERR! git or move it out of the way first.npm ERR! A complete log of this run can be found in:
npm ERR! /home/user-name/.npm/_logs/2020-01-15T14_29_55_570Z-debug.log
When build a production version the app I keep getting this error:
Execution failed for task ':react-native-sms:verifyReleaseResources'.
java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
Output: error: resource android:style/TextAppearance.Material.Widget.Button.Borderless.Colored not found.
/Path-to-project/node_modules/react-native-sms/android/build/intermediates/res/merged/release/values-v26/values-v26.xml:7: error: resource android:attr/colorError not found.
/Path-to-project/node_modules/react-native-sms/android/build/intermediates/res/merged/release/values-v26/values-v26.xml:11: error: resource android:attr/colorError not found.
/Path-to-project/node_modules/react-native-sms/android/build/intermediates/res/merged/release/values-v26/values-v26.xml:15: error: style attribute 'android:attr/keyboardNavigationCluster' not found.
/Path-to-project/node_modules/react-native-sms/android/build/intermediates/res/merged/release/values/values.xml:226: error: resource android:attr/fontStyle not found.
/Path-to-project/node_modules/react-native-sms/android/build/intermediates/res/merged/release/values/values.xml:226: error: resource android:attr/font not found.
/Path-to-project/node_modules/react-native-sms/android/build/intermediates/res/merged/release/values/values.xml:226: error: resource android:attr/fontWeight not found.
error: failed linking references.
and I cant just find any means to comprehend whats happening here. Can anyone help please when I remove this package everything seems to be working fine back
Using the latest release (1.3.0) I'm unable to use this on android. It looks like a fix was merged in PR #3 but a new release needs to be made.
Hi.
i use this code:
SendSMS.send({
body: this.state.activateCode,
recipients: ["+44..."],
successTypes: ['sent', 'queued']
}, (completed, cancelled, error) => {
if (completed) {
} else {
}
});
and open default android sms manager!
i want to send in background.
How do I do this?
Thanks for help.
Can someone merge the pull request?
Would be nice you have those pull request features/fixes.
Thanks, Adri
Hi all,
Very nice package. I would like to ask you guys, if you know if there´s possible to send an SMS in the background, without going to the iMassage interface, so I can keep the user on my app, all the time. Thanks for your help.
I've got this error:
Fatal Exception: java.lang.SecurityException: Permission Denial: reading com.android.providers.telephony.SmsProvider uri content://sms/ from pid=23329, uid=10322 requires android.permission.READ_SMS, or grantUriPermission()
at android.os.Parcel.readException(Parcel.java:1620)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:421)
at android.content.ContentResolver.query(ContentResolver.java:502)
at android.content.ContentResolver.query(ContentResolver.java:445)
at com.tkporter.sendsms.SendSMSObserver.onChange(SendSMSObserver.java:99)
at android.database.ContentObserver.onChange(ContentObserver.java:130)
at android.database.ContentObserver.onChange(ContentObserver.java:145)
at android.database.ContentObserver$NotificationRunnable.run(ContentObserver.java:216)```
How should I handle this properly?
I'm noticing with your example:
SendSMS.send({
body: 'The default body of the SMS!',
recipients: ['1234567890'],
successTypes: ['sent', 'queued']
}, (completed, cancelled, error) => {
console.log('SMS Callback: completed: ' + completed + ', cancelled: ' + cancelled + ', error: ' + error)
})
The body message doesn't get filled in at all. In fact, it happens to say MMS instead of SMS and there is a blank second recipient, ie there's a comma at the end of my only recipient, even though my recipients parameter looks like ["1234567890"]
I'm having this issue on Android (my actual phone with KitKat). I've used react-native-communications and that pre-fills the content, it just doesn't have a callback feature.
most modules in RN>0.6 is no longer needed react-native-link.
Is this module want this command or not?
best regards... kamran
Hi, I just installed this module and when I try to send a message I get this error:
Possible Unhandled Promise Rejection (id: 0): TypeError: Cannot read property 'send' of undefined
If I do console.log(SendSMS) I can see that it is not undefined, so why I get this error?
Hello,
In order to make it build on my ubuntu machine for react-native run-android
I had to do
mv ./node_modules/react-native-sms/Android ./node_modules/react-native-sms/android
.
Hello there.
I'm trying to get the status of the sms using the function on your example ("someFunction") but as soon as the sms app opens it goes directly to cancelled. I would need to get a success status when the sms is sent. Is it possible? Thanks very much
I'm running into a hiccup on android, with the error below.
Cannot read property 'send' of undefined
TypeError: Cannot read property 'send' of undefined
points to the following section of the js bundle:
_reactNative.NativeModules.SendSMS.send(options,callback);case 10:case'end':return _context.stop();}}},null,this,[[1,7]]);}
I've re-installed this library and gone through the whole setup a couple of times now.
I'm running RN 38.1 on this project and have triple checked the android install instructions as well as the Troubleshooting section. Everything on the iOS side is fine. Thanks in advance for guidance!
After successfully sending an sms, I'm currently not being automatically redirected to my app. For that, I have to push the back button. Surely this is something that should be built-in to this library, is it not?
If so, how to implement?
(I am testing on Samsung Galaxy S8)
I'm not getting any results from the callback OTHER than 'completed: false, cancelled: true, error: false", whether I press back during the message composition or I actually send the message.
Is there a way to know whether the text messages were actually sent or not? I'm needing both Android and iOS solutions, but it seems like I'm more than likely going to have to move away from SMS and toward push notifications if I want more robust/automated/failureproof peer-to-peer communication.
We are starting to get this error during daily builds:
/Users/buildadm/workspace/flare-one/flare/node_modules/react-native-sms/Android/src/main/java/com/tkporter/sendsms/SendSMSModule.java:34: error: method does not override or implement a method from a supertype
@Override
^
/Users/buildadm/workspace/flare-one/flare/node_modules/react-native-sms/Android/src/main/java/com/tkporter/sendsms/SendSMSModule.java:43: error: method does not override or implement a method from a supertype
@Override
^
When I test on my Android device but when the SMS is sent then the resultCode is always 0 (e.g. Activity.RESULT_CANCELED). Any ideas why?
I log the resultCode in the onActivityResult method.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_CANCELED) {
Log.i("APP", "SMS CANCELLED");
}
super.onActivityResult(requestCode, resultCode, data);
SendSMSPackage.getInstance().onActivityResult(requestCode, resultCode, data);
}
SendSMS.send({
body: `Hi, ${smsBody}`,
recipients: [''],
successTypes: ['all']
}, (completed, cancelled, error) => {
console.log('SMS Callback: completed: ' + completed + ' cancelled: ' + cancelled + 'error: ' + error);
});
First of all, as shown above, I wished to have a non-filled recipients but in the sms composer it will shows Buddy Name
by default? And second issue is that instead of New Message
, it's showing New MMS
?
Upgrading react-native
version to 0.60.5
is showing this warning regarding this library.
warn The following packages use deprecated "rnpm" config that will stop working from next release
Please fix this so that we continue to use your library with react-native
upgrades :)
Hello got some strange behaviour when trying to send sms via android without defining at least one phone number in "recipients" folder:
it provides android recipient choosing page and when i choose one - it opens sms window BUT without prefilled text defined in "body". How could i solve this problem?
Same code works fine on iOS. If predefine recipient - everything works fine as well.
Thanks for help.
Hello,
I have installed and configured this library on my Android phone, following the example in documentation when I invoke someFunction
it composes a text message window that has the body and recipients, however it doesn't send the SMS message unless I press send.
How can I go about automating that? so that when I call someFunction
it will send the text message without having to press send on Android text message app.
Thanks
It seems like there is no way to know when the sms is successfully sent, the callback is not being called after sending the SMS on android. but, if I do cancel the sms taping back, it gets into the callback. otherwise it does not know it. is there any delay or something when the sms has been sent?
SendSMS.send({
body: 'The default body of the SMS!',
recipients: ['0123456789', '9876543210'],
successTypes: ['sent', 'queued'],
allowAndroidSendWithoutReadPermission: true
}, (completed, cancelled, error) => {
console.log('SMS Callback: completed: ' + completed + ' cancelled: ' + cancelled + 'error: ' + error);
});
I am successfully using this in one part of my ios app but it does not work in another spot. I call the send method and it flashes black for less then a second. It is not being blocked by another modal. There does not appear to be any errors in the xcode logs. Has anyone else experienced this issue?
Thanks!
Hello @tkporter
I've got an issue with my android phone, as the lib is always adding an extra number which corresponds to a white space :
I think it's coming from this line, as the separator is adding a whitespace :
I will investigate further :)
I have got crash on Mi MAX 2. The solution for it is do not call registerContentObserver
:
private static final Uri uri = Uri.parse("content://sms/"); resolver.registerContentObserver(uri, true, this);
@robinaugh this is for you may be interesting
I've got the module working great, but no matter what body I put in (the default, blank spaces, the word TEST, etc), it always gets put in twice when pre-filling the message.
<Button title="Text" onPress={() => SendSMS.send({
body: 'TEST',
recipients: [this.props.number],
successTypes: ['sent', 'queued']
}, (completed, cancelled, error) => {
console.log('SMS Callback: completed: ' + completed + ' cancelled: ' + cancelled + 'error: ' + error);
})} />
Hi there,
I previously wanted to use this library but it became problematic because of the 'READ_SMS' permission.
Is it possible to not include that permission at all and then use the allowAndroidSendWithoutReadPermission
?
Or does the app require this as a baseline and the allowAndroidSendWithoutReadPermission
is only used to handle the case where the user denies the permission?
Gradle build error when attempting to build on Android:
Project with path ':ReactAndroid' could not be found in project ':react-native-sms'
Hi @tkporter ,
Thank's a lot for the package, could you please change the description from "SMS sender with callbacks for iOS and Android" . to "SMS sender with callbacks for Android only iOS doesn't support sending SMS programmatically"
Hey
I get package com.tkporter.sendsms does not exist when trying to follow your example
Could you please help me with that?
Here is a piece of code:
SendSMS.send(
{
body: message,
recipients: [phoneNumber],
successTypes: ['all'],
allowAndroidSendWithoutReadPermission: true,
},
(completed, cancelled, error) => {
// If Message was sent successfully we have to disable button and update backend
if (completed) {
updateReminded({
variables: {
inviterAccountId: accountId,
inviteeSeatId: invitedSeatId,
},
});
setIsReminded(true);
}
}
);
For any Android after sms send completed, cancelled and error are false
With Google's new restrictions on sms/call log permissions, how do you recommend filling out the permissions declaration form when submitting your new APK to use react-native-sms.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.