0
該代碼是通過使用jsoup瞄準虎視眈眈的內容,我嘗試升級代碼如何將手機插件從1.6.x升級到2.7?
這裏是我到目前爲止的代碼:
package com.phonegap.g7.plugin;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.apache.cordova.api.CordovaPlugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class UrlFeedJava extends CordovaPlugin {
//@Override
public PluginResult execute(String action, JSONArray data, String callbackId) {
PluginResult.Status status = PluginResult.Status.OK;
PluginResult r=null;
try
{
String target = data.getString(0);
String selector = data.getString(1);
Document doc = Jsoup.connect(target).get();
Element masthead = doc.select(selector).first();
String content=masthead.toString();
String title = doc.title();
r=new PluginResult(status,content);
}
catch(Exception ee)
{
System.out.print("ee:"+ee.getMessage());
}
return r;
}
}
的PhonegapPlugin.js文件
UrlFeed.prototype = {
send: function(success, error, url, selector){
cordova.exec(success, error, "UrlFeedJava", "send", [url, selector]);
}
};
PhoneGap.addConstructor(function() {
PhoneGap.addPlugin('urlfeed', new UrlFeed());
});
中的index.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<script type='text/javascript' src='jquery-1.8.3.min.js'></script>
<script type='text/javascript' src='cordova-2.7.0.js'></script>
<script type='text/javascript' src='PhonegapPlugin.js'></script>
<script type='text/javascript'>
$(function(){
var onSend = function(){
var success = function(data){
$('#show').html(data);
};
var error = function(e){
alert(e);
};
var url = 'http://sports.163.com/12/0618/09/8496QLNG00051C8V.html';
var selector = $('#selector').val();
window.plugins.urlfeed.send(success, error, url, selector);
};
$('#send').bind('click', onSend);
});
</script>
</head>
<body>
<div id='messageDiv'>
<input type='text' id='selector'></input>
<div id='show'></div>
<button type='button' id='send'>Send Me</button>
</div>
</body>
</html>
尤其是我不明白的F構造函數的聯合。
謝謝,我的另一個問題http://stackoverflow.com/questions/18348751/how-to-return-a-array-or - 其他的集合元素型從-的PhoneGap-機器人 - 對 – hkguile