nativescript - 从当前 Java 上下文调用方法
问题描述
目前,我正在使用 Android 从 Android 发送短信,SmsManager
并且工作正常。
但我确实想听听 Intent 结果并基于此采取一些行动,以下代码应该可以工作,但我getResultCode
在运行时得到了未定义的结果(但它可以在调试控制台上工作)
app.android.registerBroadcastReceiver(this.id, () => {
if(this.getResultCode() == android.app.Activity.RESULT_OK){
// Sucess
} else {
// Failure
}
});
如何getResultCode
正确地从方法中获取价值?
解决方案
您将需要使用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;
推荐阅读
- python - 为什么我不能在函数内修改列表(作为一个整体)?
- java - GCP Cloud Run API(SDK) - 以编程方式创建服务
- mysql - 如何在 Golang 中处理 Bit(1) 类型
- elasticsearch - 如何在elasticsearch中更新字段的数据类型
- flutter - 如何从 Webflow 加载 Flutter Web 应用程序?
- python - 如何选择 texbox 并搜索内容并在 selenium - python 中选择第一个选项?
- solver - 如何使用 Python 解决以字符串格式给出的布尔表达式?
- bitbucket - Bitbucket Pipeline:我们可以在构建开始时获取参数值吗
- python-multiprocessing - python多处理突然只使用一个核心
- toad - 如何在 Toad for Oracle 中按项目组织连接