My requirement is to open an android native simple activity from Cordova Plugin.
I tried the solutions mentioned in this thread. But I am getting error (Sample App, Unfortunately stopped)
I am going crazy over past few days.
Here is my code (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;
}
}
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>
Note: When I look at the log in my device in debug mode, it seems like it is not finding MainActivity.java Can anyone help me with this, any sample Cordova Plugin to open an native android activity would help me.