roblav96 / nativescript-telephony

A Nativescript plugin to get the device's SIM data (carrier name, mcc mnc, country code, telephonenumber, etc)
Other
22 stars 9 forks source link

Permission error even when permission granted! #2

Closed terhoraj closed 7 years ago

terhoraj commented 7 years ago

I have granted permissions (phone and all others) from permissions manually and I'm getting this error:

JS: Error: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.content.Context.checkPermission(java.lang.String, int, int)' on a null object reference JS: android.support.v4.content.ContextCompat.checkSelfPermission(ContextCompat.java:387) JS: com.tns.Runtime.callJSMethodNative(Native Method) JS: com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:862) JS: com.tns.Runtime.callJSMethodImpl(Runtime.java:727) JS: com.tns.Runtime.callJSMethod(Runtime.java:713) JS: com.tns.Runtime.callJSMethod(Runtime.java:694) JS: com.tns.Runtime.callJSMethod(Runtime.java:684) JS: com.tns.NativeScriptActivity.onCreate(NativeScriptActivity.java:13) JS: android.app.Activity.performCreate(Activity.java:6658) JS: android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) JS: android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2584) JS: android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2692) JS: android.app.ActivityThread.-wrap12(ActivityThread.java) JS: android.app.ActivityThread$H.handleMessage(ActivityThread.java:1445) JS: android.os.Handler.dispatchMessage(Handler.java:102) JS: android.os.Looper.loop(Looper.java:154) JS: android.app.ActivityThread.main(ActivityThread.java:6044) JS: java.lang.reflect.Method.invoke(Native Method) JS: com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) JS: com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

Here's my code that I'm running:

var telephonyPlugin = require("nativescript-telephony");

    telephonyPlugin.Telephony().then(function (resolved) {
        console.log(resolved)
    }).catch(function (error) {
        console.log(error);

});

roblav96 commented 7 years ago

It seems like you're attempting to call telephonyPlugin.Telephony before the app has been boostrapped/started.

Are you using core or angular nativescript?

terhoraj commented 7 years ago

core and I'm recuiring this plugin at main view's view model module. I have only tested this with Android N emulator, I'm going to test with physical device tomorrow. Why is this error about permission, any idea?

roblav96 commented 7 years ago

Well it's saying that android.content.Context does not exist yet. So make sure you call it after application.start() and after application.AndroidApplication.activityStartedEvent.

I have not tested this on Android N before.

terhoraj commented 7 years ago

I added loaded event on my xml file and thru that I get what I need :+1: