【问题标题】:How to start ActivityMain from Phonegap's html file如何从 Phonegap 的 html 文件启动 ActivityMain
【发布时间】:2014-10-16 20:25:40
【问题描述】:

这是我的js函数

<script type="text/javascript">
            function callNewActivity() {
            window.plugins.StartBarcodeReader.gecis();                   
            }
</script>

这是我的 StartBarcodeReader.java 文件

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);
    }
}

我想从 phonegap 的 index.html 文件开始新的主要活动

例如,在 index.html 上单击按钮而不是开始新活动。

我的英语不好:-(,请帮帮我。

【问题讨论】:

    标签: android cordova android-activity main


    【解决方案1】:

    此代码从 cordova/phonegap 的 index.html 访问 android 代码。无论您在 index.html 的输入字段中写什么,它都会传递给 android 代码并返回到 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.
    }
    
    }
    

    我正在上传一个工作示例。您可以下载并测试它。link。如果您仍然遇到任何问题。请随时发表评论:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-16
      • 2013-09-22
      • 1970-01-01
      • 2023-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多