有没有办法在我的BB应用程序中显示LOCAL html字符串?
例如:我有一个字符串
"<b>text-text-text</b> <A href="http://stackoverflow.com">link</A>
“
我如何解析并将其显示为
text-text-text link?
感谢。
答案 0 :(得分:2)
您可以使用BrowserField将应用程序中的内容呈现为字段。为了呈现HTML作为String而不是URL提供,请参阅this answer,其中涉及模拟HttpConnection。
答案 1 :(得分:1)
import javax.microedition.io.Connection;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import java.util.*;
import java.io.*;
import net.rim.blackberry.api.browser.Browser;
import net.rim.blackberry.api.browser.BrowserSession;
import net.rim.device.api.ui.*;
import net.rim.device.api.browser.field.*;
import net.rim.device.api.browser.plugin.BrowserPageContext;
import net.rim.device.api.io.Base64OutputStream;
import net.rim.device.api.io.http.HttpHeaders;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.system.Application;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.Status;
import net.rim.device.api.ui.component.TextField;
final class bFieldExample extends UiApplication
{
private static final String REFERER = "referer";
public static final HttpConnection Utilities = null;
// private static final HttpConnection HttpConnection = null;
private RenderingSession rs;
private MainScreen ms;
private HttpConnection conn;
public static void main(String[] args)
{
bFieldExample app = new bFieldExample();
app.enterEventDispatcher();
}
public bFieldExample()
{
ms = new MainScreen();
pushScreen(ms);
rs = RenderingSession.getNewInstance();
String s = "<b>text-text-text</b> <A href="http://stackoverflow.com">link</A>"
//rs.getRenderingOptions().setProperty(RenderingOptions.CORE_OPTIONS_GUID,RenderingOptions.JAVASCRIPT_ENABLED, true);
//LabelField l = new LabelField("Browser",LabelField.ELLIPSIS|LabelField.USE_ALL_WIDTH);
ms.setTitle(new LabelField("Browser",LabelField.ELLIPSIS|LabelField.USE_ALL_WIDTH));
myThread thread = new myThread(s);
thread.start();
}
class myThread extends Thread
{
private String _url;
myThread(String url)
{
_url=url;
}
public void run()
{
try {
ByteArrayOutputStream output = new ByteArrayOutputStream();
Base64OutputStream boutput = new Base64OutputStream( output );
output.write( "data:text/html;base64,".getBytes() );
boutput.write( _url.getBytes() );
boutput.flush();
boutput.close();
output.flush();
output.close();
BrowserSession bSession = Browser.getDefaultSession();
bSession.displayPage( output.toString() );
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
答案 2 :(得分:1)
myBrowserField.displayContent("<b>text-text-text</b> <A href="http://stackoverflow.com">link</A>", "http://localhost");
答案 3 :(得分:0)
试试这个:
BrowserField myBrowserField;
myBrowserField = new BrowserField();
add(myBrowserField);
String content ="<html><head></head><body>"+
"<b>text-text-text</b> <A href="http://stackoverflow.com">link</A>"+
"</body></html>";
myBrowserField.displayContent(content,"");//"http://localhost"