Java Cordova Android插件-从Cordova插件打开Android本机活动

Java Cordova Android插件-从Cordova插件打开Android本机活动,java,android,cordova,Java,Android,Cordova,我的要求是从Cordova插件打开一个android原生简单活动 我尝试了中提到的解决方案。但我遇到了错误(示例应用程序,不幸停止) 这几天我都快疯了 这是我的代码(Hello.java) MainActivity.java package com.example.sample; import android.os.Bundle; import android.app.Activity; import android.view.Menu; public class MainActivity

我的要求是从Cordova插件打开一个android原生简单活动

我尝试了中提到的解决方案。但我遇到了错误(示例应用程序,不幸停止)

这几天我都快疯了

这是我的代码(Hello.java)

MainActivity.java

package com.example.sample;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
}
Plugin.xml

<?xml version="1.0" encoding="utf-8"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
        id="com.example.sample"
        version="0.7.0">

  <name>Hello</name>

  <engines>
    <engine name="cordova" version=">=3.4.0"/>
  </engines>

  <asset src="www/hello.js" target="js/hello.js"/>

  <js-module src="www/hello.js" name="hello">
    <clobbers target="hello" />
  </js-module>

  <platform name="android">

    <config-file target="res/xml/config.xml" parent="/*">
      <feature name="Hello">
        <param name="android-package" value="com.example.sample.Hello"/>
      </feature>
    </config-file>
    <source-file src="src/android/src/com/example/sample/Hello.java" target-dir="src/com/example/sample/"/>
    <source-file src="src/android/src/com/example/sample/MainActivity.java" target-dir="src/com/example/sample/"/>
    <source-file src="src/android/src/com/example/sample/R.java" target-dir="src/com/example/sample/"/>
  </platform>

</plugin>

你好
注意: 当我在调试模式下查看设备中的日志时,它似乎没有找到MainActivity.java 有人能帮我吗?任何打开本机android活动的示例Cordova插件都能帮我。

opennative.js

cordova.define("com.example.opennative.OpenNative", function(require, exports, module) { 

function OpenNative() {
};

OpenNative.prototype.open = function(callbackContext) {
    callbackContext = callbackContext || {};
    cordova.exec(callbackContext.success || null, callbackContext.error || null, "OpenNative", "open", []);

};

/**
 * Load Plugin
 */

if(!window.plugins) {
    window.plugins = {};
}
if (!window.plugins.openNative) {
    window.plugins.openNative = new OpenNative();
}

});
OpenNative.java

public class OpenNative extends CordovaPlugin {

    /**
     * Executes the request and returns a boolean.
     * 
     * @param action
     *            The action to execute.
     * @param args
     *            JSONArry of arguments for the plugin.
     * @param callbackContext
     *            The callback context used when calling back into JavaScript.
     * @return boolean.
     */
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
                if (action.equals("open")) {
                        try {
                            openN();
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                    else {
                    }
                    return true;
            }
            private void openN() throws IOException {

                intent = new Intent(this.cordova.getActivity().getApplicationContext(), Second.class);

                this.cordova.getActivity().startActivityForResult(intent,0);
                this.cordova.getActivity().startActivity(intent);
                this.cordova.getActivity().overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
            }

        }
cordova_plugin.js

   {
        "file": "plugins/com.example.opennative/www/fileOpener.js",
        "id": "com.example.opennative.OpenNative",
        "clobbers": [
            "openNative.open"
        ]
    }
config.xml:

 <feature name="OpenNative">
        <param name="android-package" value="com.example.opennative.OpenNative" />
    </feature>

这里com.example.opennative是包名,opennative是文件名

在js中调用window.plugins.openNative.open。不需要导入js文件。
cordova_plugin.js/config.xml将自动处理映射。

最后,我在


它使用FakeR.java类来设置布局和所有设置。

AndroidManfist文件在哪里?您正在开始
下一个\u活动
,但没有添加到
Plugin.xml中?使用
MainActivity
而不是
Next_Activity
对不起,我看不到你的AndroidManifest.xml这是我的,你能告诉我如何使用cordova_plugin.js以及如何调用插件吗?我找不到符号“MainActivity.java”你使用MainActivity.java吗,你在清单中声明了吗?是的。我宣布了。
    public static int getId(Context context, String group, String key) {
        return context.getResources().getIdentifier(key, group, context.getPackageName());
    }
    public static int getId(Context context, String group, String key) {
        return context.getResources().getIdentifier(key, group, context.getPackageName());
    }