@smartface/extension-sms-receiver
TypeScript icon, indicating that this package has built-in type declarations

4.0.0 • Public • Published

SMS Receiver Extension from Smartface

This extension works only for Android.

NPM Twitter: @Smartface_io License

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.

Readme

Keywords

Package Sidebar

Install

npm i @smartface/extension-sms-receiver

Weekly Downloads

0

Version

4.0.0

License

MIT

Unpacked Size

14.8 kB

Total Files

17

Last publish

Collaborators

  • sbasbug
  • alnyli07
  • smf
  • furkan.arabaci