4
import * as application from 'application';
const TnsOneSignal = require('nativescript-onesignal').TnsOneSignal

if (application.android) {
        application.on(application.launchEvent, function(args: application.ApplicationEventData) {
            try {
                console.log('TnsOneSignal', TnsOneSignal)
                TnsOneSignal.startInit(application.android.context).init()
            } catch (error) {
                console.log('error', error)
            }
        })
    }

I tried using above code and plugin but it does not work..

Can anyone help please with my code or provide better solution!

Nick Iliev
  • 9,610
  • 3
  • 35
  • 89
  • How does the plugin `nativescript-onesignal` relate to the SIM network strength? The plugin as far as I see provides a push notification functionality. – Nick Iliev Jul 16 '18 at 09:56
  • Yes you are right as i m new in nativescript, so i didnt understand that but now i know it, so help me to get sim network strength if u could please!! – UmerDeveloper Jul 16 '18 at 13:42

1 Answers1

1

TO get the signal strength of the current mobile phone you could use the native APIs on Android and iOS and convert the code to JavaScript based on the NativeScript's marshaling rules.

For example, let's take this native solution. Here is how it would look like in NativeScript

let telephonyManager = application.android.context.getSystemService(android.content.Context.TELEPHONY_SERVICE);
let cellinfogsm = telephonyManager.getAllCellInfo().get(0);
let cellSignalStrengthGsm = cellinfogsm.getCellSignalStrength();
cellSignalStrengthGsm.getDbm();

Of course, in Android to be able to get this information you would need an explicit permission for ACCESS_COARSE_LOCATION so you could use nativescript-permissions plugin to grant them.

Here you can find a test project demonstrating the above technique. based on the same principle you could find an iOS example and convert the code to JS using the marshaling from Objective-C to JS.

Nick Iliev
  • 9,610
  • 3
  • 35
  • 89
  • Thanks Nick. I also wanna ask if any plugin need for this solution as in the first line application gives error: application not known?? – UmerDeveloper Jul 17 '18 at 06:02
  • `application` is in fact the application module https://github.com/NickIliev/NS-Issues-2018-II/blob/master/stackoverflow/signalStreinght/app/main-view-model.ts#L2 – Nick Iliev Jul 17 '18 at 06:12
  • Note that the above code will work only on a real device and not on an emulator (where there is no SIM and telephone service) – Nick Iliev Jul 17 '18 at 06:16
  • 1
    Thank you soo much for your help Nick. – UmerDeveloper Jul 17 '18 at 09:38