@smartface/extension-sms-receiver
v4.0.0
Published
Smartface sms receiver extension.
Downloads
1
Readme
SMS Receiver Extension from Smartface
This extension works only for Android.
SMS Receiver
This extension is reading incoming SMS content on Android devices. To learn more about how to handle SMS on both systems, refer to this document.
Installation
Smartface SMS Receiver can be installed via npm. Execute this command on scripts directory:
yarn add @smartface/extension-smsreceiver
Open this line in config/Android/AndroidManifest.xml file.
<!-- Required for receive sms. -->
<uses-permission android:name="android.permission.RECEIVE_SMS" />
You must request permission for sms receive. (API LEVEL 23 AND UPPER)
Application.android.requestPermissions(1002, Application.Android.Permissions.RECEIVE_SMS);
Note: You can also use the permission utility by Smartface Extension Utils.
How to use
import Page1Design from 'generated/pages/page1';
import Permission from '@smartface/extension-utils/lib/permission';
import Application from '@smartface/native/application';
import SMSReceiver from '@smartface/extension-smsreceiver';
import System from '@smartface/native/device/system';
export default class Page1 extends Page1Design {
router: any;
constructor() {
super();
this.onShow = onShow.bind(this, this.onShow.bind(this));
this.onLoad = onLoad.bind(this, this.onLoad.bind(this));
this.onHide = onHide.bind(this, this.onHide && this.onHide.bind(this));
}
requestSMSPermission() {
if (System.OS === 'iOS') {
// Prevent unnecessary prompt on iOS. iOS doesn't have this permission.
return;
}
Permission.getPermission({
androidPermission: Application.Android.Permissions.RECEIVE_SMS,
permissionText: "Requesting to Receive SMS to do awesome stuff",
permissionTitle: "Permission Required"
})
.then(() => {
SMSReceiver.registerReceiver();
SMSReceiver.callback = (e) => {
console.info(e);
}
})
}
}
function onHide(superOnHide: () => void) {
superOnHide();
/**
* This will be triggered when user leaves the page.
*/
SMSReceiver.unRegisterReceiver();
}
function onShow(superOnShow: () => void) {
superOnShow();
}
function onLoad(superOnLoad: () => void) {
superOnLoad();
this.requestSMSPermission();
}
License
This project is licensed under the terms of the MIT license. See the LICENSE file. Within the scope of this license, all modifications to the source code, regardless of the fact that it is used commercially or not, shall be committed as a contribution back to this repository.