简体   繁体   English

在cordova项目中启动android活动

[英]start android activity within cordova project

Is it possible to call the following code within a cordova project? 是否可以在cordova项目中调用以下代码?

Intent intent = new Intent("android.net.vpn.SETTINGS");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

I tried to use WebIntent ( link ), but it does not support the set of a flag, furthermore I dont know how I have to set the options. 我尝试使用WebIntent( link ),但是它不支持标志集,而且我不知道如何设置选项。

Short answer 简短答案

No 没有

Detailed answer: 详细答案:

Cordova uses one Activity only (Web View) so you cannot open new Activity. Cordova仅使用一个活动(Web视图),因此您无法打开新的活动。

But Ionic (Angular) supports states and you can switch views inside web view 但是Ionic(Angular)支持状态,您可以在Web视图内切换视图


What you try to do is to open Settings that is not part of your application. 您尝试做的是打开不属于您的应用程序的设置。

So you can call Java method from Cordova and call your code 因此,您可以从Cordova调用Java方法并调用您的代码

Java Java的

private boolean openWifiSettings(final CallbackContext callbackContext) {

        final CordovaPlugin plugin = this;

        this.cordova.getThreadPool().execute(new Runnable() {
            public void run() {


                     cordova.startActivityForResult(plugin, new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS), 0);

                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));

            }
        });

        return true;
    }

and in javascript: 并在javascript中:

YourPlugin.prototype.openWifiSettings = function (successCallback, errorCallback) {
  cordova.exec(successCallback, errorCallback, "MoodoPlugin", "openWifiSettings", []); //
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM