小编NS1*_*114的帖子

如何在PhoneGap中编写基本的"Hello World"java脚本插件?

我已经阅读了Cordova的教程,但我不确定他们是否给了我足够的信息.

已编辑以显示更新的代码:

让我告诉你我的代码:

从config.xml:

<plugin name="someMethod" value="MyPluginClass" />
Run Code Online (Sandbox Code Playgroud)

现在为Plugin.h:

#import <Cordova/CDV.h>

@interface MyPluginClass : CDVPlugin

- (void)someMethod:(CDVInvokedUrlCommand*)command;

@end
Run Code Online (Sandbox Code Playgroud)

现在为Plugin.m:

#import "Plugin.h"

@implementation MyPluginClass

- (void)someMethod:(CDVInvokedUrlCommand *)command
{
    NSLog(@"YOU ARE READING THIS NATIVELY FROM A PLUGIN");
}

@end
Run Code Online (Sandbox Code Playgroud)

显示的第一个html页面称为"index.html"

我只想要一个空白的html页面,它只运行一个调用cordova.exec()函数的脚本.我这样做的尝试失败了.我不知道我的脚本是否有问题,或者其他地方我做错了但是这里是我的index.html:

<!DOCTYPE html>
<html>
<head>
    <title>Cordova Device Ready Example</title>

    <script type="text/javascript" charset="utf-8" src="cordova-2.3.0.js"></script>
    <script type="text/javascript" charset="utf-8">

        // Call onDeviceReady when Cordova is loaded.
        //
        // At this point, the document has loaded but cordova-2.3.0.js has not.
        // When Cordova is loaded and …
Run Code Online (Sandbox Code Playgroud)

javascript html5 objective-c phonegap-plugins cordova

4
推荐指数
1
解决办法
3386
查看次数

创建BufferedReader以读取导致错误的URL:无法启动活动

我正在尝试阅读URL的内容.BufferedReader的初始化会导致崩溃.

我试过查找人们的解决方案,但无论我做什么,我都会遇到这个错误.

这是我的代码:

 try {
        String sUrl = "http://www.google.com";
        System.out.println("About to create URL.");
        URL url = new URL(sUrl);
        System.out.println("Created URL");

        System.out.println("About to create URLConnection");
        URLConnection urlc = url.openConnection();
        System.out.println("Created URLConnection");

        System.out.println("About to create the BufferedReader");
        BufferedReader bR = new BufferedReader(new 
            InputStreamReader(urlc.getInputStream()));
        System.out.println("Created the BufferedReader");

        System.out.println("About to create a StringBuilder");
        StringBuilder sBuilder = new StringBuilder();
        System.out.println("Created StringBuilder");

        int byteRead;
        System.out.println("About to enter while loop and build string");
        while ((byteRead = bR.read()) != -1)
        {
            sBuilder.append((char) byteRead);
        }
        System.out.println("Built string");

        bR.close();
        System.out.println("Buffered …
Run Code Online (Sandbox Code Playgroud)

java android urlconnection bufferedreader

1
推荐指数
1
解决办法
3050
查看次数