0
我在另一個方法MyVimeo()中調用方法GetVal()。Codename1 - 未分配給變量的值
變量時間戳,隨機數,符號是全局的,並打印在方法GetVal()中。 但是,當在MyVimeo()方法中打印相同值時,這些值爲空。
是否有任何替代方法返回值作爲字符串從GetVal()?
public void GetVal(final String param) {
NetworkManager networkManager = NetworkManager.getInstance();
networkManager.start();
networkManager.addErrorListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
NetworkEvent n = (NetworkEvent) evt;
n.getError().printStackTrace();
}
});
ConnectionRequest request = new ConnectionRequest() {
int chr;
StringBuffer sb = new StringBuffer();
public String response = "";
public void readResponse(InputStream input)
throws IOException {
// do something with input stream
while ((chr = input.read()) != -1) {
sb.append((char) chr);
//System.out.println("reading...");
}
response = sb.toString();
res = response;
Log.p("param->" + param);
if(param=="timestamp") {
timestamp = res;
Log.p("Response->" + timestamp);//values printed inside method
}
else if(param=="nonce") {
nonce = res;
Log.p("Response->" + nonce);//values printed inside method
}
else if(param=="sign") {
sign = res;
Log.p("Response->" + sign);//values printed inside method
}
}
protected void handleException(Exception err) {
Dialog.show("Connection Err!!", "Are you connected to the internet? Check your connection",
"Ok", null);
}
};
request.setUrl("http://127.0.0.1/getvalues.php?param="+param);
request.setPost(false);
networkManager.addToQueue(request);
}
public void MyVimeo(final String file) {
new Thread(new Runnable() {
public void run() {
Log.p("File Name : " + file);
String consumer_key = "";
String consumer_secret = "";
String vimeoAPIURL = "http://vimeo.com/api/rest/v2";
String reqTokenEP = "http://vimeo.com/oauth/request_token";
String AUTHORIZATION_URL = "http://vimeo.com/oauth/authorize?oauth_token=";
String accTokenEP = "http://vimeo.com/oauth/access_token";
String accToken = "";
String accTokenPass = "";
NetworkManager networkManager = NetworkManager.getInstance();
networkManager.start();
networkManager.addErrorListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
NetworkEvent n = (NetworkEvent) evt;
n.getError().printStackTrace();
}
});
ConnectionRequest request = new ConnectionRequest() {
int chr;
StringBuffer sb = new StringBuffer();
String response = "";
protected void readResponse(InputStream input)
throws IOException {
// do something with input stream
while ((chr = input.read()) != -1) {
sb.append((char) chr);
// System.out.println("reading...");
}
response = sb.toString();
Log.p("Response->" + response);
if (response.equals("OK")) {
Dialog.show("Response", "Authenticated", "Ok", null);
} else {
Dialog.show("Response", "Failed", "Ok", null);
}
}
protected void handleException(Exception err) {
// do something with err
Dialog.show(
"Connection Err!!",
"Are you connected to the internet? Check your connection",
"Ok", null);
}
};
//timestamp = GetVal("timestamp");
//nonce = GetVal("nonce");
//sign = GetVal("sign");
GetVal("timestamp");//values printed inside method
GetVal("nonce");//values printed inside method
GetVal("sign");//values printed inside method
Log.p("TS->" + timestamp);//no values here
Log.p("NC->" + nonce);//no values here
Log.p("SIG->" + sign);//no values here
String url = vimeoAPIURL + "?format=xml"+
"&method=vimeo.videos.upload.getQuota"+
"&oauth_consumer_key="+ consumer_key +
"&oauth_version=1.0"+
"&oauth_signature_method=HMAC-SHA1"+
"&oauth_timestamp="+timestamp+
"&oauth_nonce="+nonce+
"&oauth_token="+accToken+
"&oauth_signature="+sign;
request.setPost(false);
request.setUrl(url);
Log.p("vimeoAPIURL->" + url);
networkManager.addToQueue(request);
}
}).start();
}
修改代碼addToQueueAndWait解決了它。謝謝。 – vasanthkumar