java.lang.Exception:类android.app.Activity上的解析方法startActivityForResult失败

时间:2018-08-29 09:11:01

标签: android nativescript

一个Nativescript(4.1)角项目(tns create app --ng)开始活动。但是我得到一个错误。

JS: ERROR Error: java.lang.Exception: Failed resolving method startActivityForResult on class android.app.Activity
JS:     com.tns.Runtime.resolveMethodOverload(Runtime.java:1062)
JS:     com.tns.Runtime.callJSMethodNative(Native Method)
JS:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1101)
JS:     com.tns.Runtime.callJSMethodImpl(Runtime.java:983)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:970)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:954)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:946)

ngAfterViewInit() {
    const intent = new android.content.Intent((android.provider.Settings as any).ACTION_MANAGE_OVERLAY_PERMISSION,
    android.net.Uri.parse('package:' + application.android.context.getPackageName()));
    const activity = application.android.foregroundActivity || application.android.startActivity;
    activity.startActivityForResult(intent);
}

1 个答案:

答案 0 :(得分:0)

我找到了解决此错误的方法。

ngAfterViewInit() {
        const application = require("application");
        const RESULT_CODE_OVERLAY_PERMISSION = 1234;
        const intent = new android.content.Intent((android.provider.Settings as any).ACTION_MANAGE_OVERLAY_PERMISSION,
        android.net.Uri.parse('package:' + application.android.context.getPackageName()));
        const activity = application.android.foregroundActivity || application.android.startActivity;
        application.android.on(application.AndroidApplication.activityResultEvent, (args) => console.log(args));
        activity.startActivityForResult(intent, RESULT_CODE_OVERLAY_PERMISSION);
    }