首页 > 解决方案 > 从当前 Java 上下文调用方法

问题描述

目前,我正在使用 Android 从 Android 发送短信,SmsManager并且工作正常。

但我确实想听听 Intent 结果并基于此采取一些行动,以下代码应该可以工作,但我getResultCode在运行时得到了未定义的结果(但它可以在调试控制台上工作)

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

如何getResultCode正确地从方法中获取价值?

标签: nativescript

解决方案


您将需要使用application公开 android 上下文的模块。

https://docs.nativescript.org/api-reference/classes/应用程序.androidapplication#context

编辑

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

// then below is the Android context object
app.android.context;

推荐阅读