0

Currently I'm sending a text message from Android using the SmsManager and its working fine.

But I do want to listen to the Intent result and take some actions based on that, the following code was supposed to work, but I'm getting getResultCode as undefined on the runtime (But it works on the debugging console)

app.android.registerBroadcastReceiver(this.id, () => {
        if(this.getResultCode() == android.app.Activity.RESULT_OK){
            // Sucess
        } else {
            // Failure
        }
    });

How do I get the value from the getResultCode method properly ?

2 Answers 2

1

You'll want to use the application module which exposes the android context.

https://docs.nativescript.org/api-reference/classes/application.androidapplication#context

EDIT

import * as app from 'tns-core-modules/application';

// then below is the Android context object
app.android.context;
Sign up to request clarification or add additional context in comments.

3 Comments

Can you please expand how to do that ? Right now I fixed the problem by moving from arrow function to a standard function. This way I can access the correct context from JS.
I wouldn't guess that would fix your problem. I believe you were wanting the Android Context, which is what the application module exposes a reference to. You're still using this in javascript. Unless you're using the Static Binding Generator to extend a native class here.
Now that I looked over what you're doing, I was wrong. what you're doing makes more sense now.
0

I was using the arrow function, thus getting the wrong context.

Changing from arrow function to a standard function fixed the problem

app.android.registerBroadcastReceiver(this.id, function(){
        if(this.getResultCode() == android.app.Activity.RESULT_OK){
            // Sucess
        } else {
            // Failure
        }
    });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.