【发布时间】:2015-03-13 04:55:08
【问题描述】:
我的要求是从 Cordova 插件打开一个 android 原生的简单活动。
我尝试了this thread 中提到的解决方案。但我收到错误(示例应用程序,不幸停止)
这几天我快疯了。
这是我的代码 (Hello.java)。
package com.example.sample;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import org.json.JSONArray;
import org.json.JSONException;
import com.example.sample.MainActivity;
public class Hello extends CordovaPlugin
{
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext)
{
if (action.equals("greet"))
{
Context context=this.cordova.getActivity().getApplicationContext();
Intent intent=new Intent(context,MainActivity.class);
context.startActivity(intent);
return true;
}
else
{
return false;
}
}
}
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;
}
}
插件.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 插件都会对我有所帮助。
【问题讨论】:
-
AndroidManfist 文件在哪里?
-
您正在启动
Next_Activity但未添加到Plugin.xml中?使用MainActivity而不是Next_Activity -
对不起,我看不到你的 AndroidManifest.xml