问题
This is my js function
<script type="text/javascript">
function callNewActivity() {
window.plugins.StartBarcodeReader.gecis();
}
</script>
This is my StartBarcodeReader.java file
package com.blogspot.ehamutcu.barcodereader;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
public class StartBarcodeReader extends ActionBarActivity {
public void gecis(){
Intent i = new Intent(this,BarcodeReader.class);
startActivity(i);
}
}
I want to start new main activity from phonegap's index.html file
For example, One click button on the index.html than start new activity.
My english is bad :-( , please help me.
回答1:
This code access the android code from cordova/phonegap's index.html.What ever you write in the input field on index.html it will then pass to the android code and came back to the index.html
public class AlertBack extends CordovaPlugin {
@Override
public boolean execute(String action, JSONArray args,
CallbackContext callbackContext) throws JSONException {
if (action.equals("alertBack")) {
<!-- Here you should write your intent-->
Context context = this.cordova.getActivity(); //getting context
Intent intent = new Intent(context,Yourclass.class); //mention your activity in manifest
context.startActivity(intent);//start activity
<!-- Intent end -->
Toast.makeText(cordova.getActivity(), "Using Toast You Entered "+
args.getString(0), Toast.LENGTH_LONG).show();
callbackContext.success("Returning from native You Entered "
+ args.getString(0));
return true;
}
return false; // Returning false results in a "MethodNotFound" error.
}
}
I am uploading a working example.You can download and test it.link.If you still face any troubles.Feel free to comment :)
来源:https://stackoverflow.com/questions/25456222/how-to-start-activitymain-from-phonegaps-html-file