public class ConsumeFactoryThread extends Thread {
private String url;
public ConsumeFactoryThread(String url){
this.url = url;
}
public void run(){
ConnectionFactory connFact = new ConnectionFactory();
ConnectionDescriptor connDesc;
connDesc = connFact.getConnection(url);
if(connDesc != null)
{
HttpConnection httpConn;
httpConn = (HttpConnection) connDesc.getConnection();
try
{
final int iResponseCode = httpConn.getResponseCode();
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
//data retrieved
}
});
}
catch(IOException e)
{
System.err.println("Caught IOException: " + e.getMessage());
}
}
}
}
我得到了上面的代碼從黑莓的文章之一,但我不能完全肯定,我怎麼獲得的URL的內容的原始字符串,這在我案件將是一個JSON字符串。使用ConnectionFactory和檢索URL數據
我知道什麼時候我沒有使用ConnectionFactory我使用了一個inputstream來獲取數據,但我不知道它是否與較新的api相同。
感謝