如何从phonegap HTML页面调用Android函数

How to call Android function from phonegap HTML page?

本文关键字:调用 Android 函数 HTML phonegap      更新时间:2023-09-26

我制作的Android应用程序可以与蓝牙打印机通信以打印一些文本,现在我想调用我从phonegap html文件中制作的printText()的Android函数。有人知道怎么做吗?谢谢. .:)

这是我的代码:

private void printText() {
        EditText EditText1;
        EditText1=(EditText)findViewById(R.id.editText1);
        String temp;
        try {           
            mPrinter.reset();  
            mPrinter.printTaggedText(EditText1.getText().toString());           
            mPrinter.feedPaper(110);
        } catch (IOException e) {
            error(R.drawable.text, getString(R.string.failed_print_text) + ". " + 
                    e.getMessage());            
        }
    }
这是我的HTML文件:
 <HTML>
    <BODY>
        <!-- What Should i Do?? -->
    </BODY>
</HTML>

你需要创建一个插件来完成这个:

http://wiki.phonegap.com/w/page/36753494/How%20to%20Create%20a%20PhoneGap%20Plugin%20for%20Android