Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
mohdfarhanakram
Posts: 73
Registered: ‎12-30-2011
My Device: All devices
Accepted Solution

How to Display HTML Contents in message body part

Hi Every one

 

  I get all part of the message like address, subject, sending time & get HTML text of body , and the i want to create new message using HTML text  please help me how it will be created new message using HTML text body.

Thanks

Mohd Farhan
BlackBerry Development Advisor
MSohm
Posts: 14,757
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: How to Display HTML Contents in message body part

BlackBerry Smartphones do not support sending email messages in HTML format.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Regular Contributor
mohdfarhanakram
Posts: 73
Registered: ‎12-30-2011
My Device: All devices

Re: How to Display HTML Contents in message body part

Thanks Mark to give me solution .

Thanks

Mohd Farhan
New Contributor
diorefovs
Posts: 3
Registered: ‎04-02-2012
My Device: 9800

Re: How to Display HTML Contents in message body part

public class BrowserField extends Manager implements RenderingApplication {
static String AGENT_STRING = getAgentString();
String content;
Padding margin = new Padding(20, 5, 0, 0).applyRatio();

static String getAgentString() {
StringBuffer buf = new StringBuffer();
buf.append("Blackberry");
buf.append(DeviceInfo.getDeviceName());
buf.append("/");
buf.append(DeviceInfo.getSoftwareVersion());
buf.append(" Profile/");
buf.append(System.getProperty("microedition.profiles"));
buf.append(" Configuration/");
buf.append(System.getProperty("microedition.configuration"));
buf.append(" VendorID/");
buf.append(Branding.getVendorId());
return buf.toString();
}

protected void sublayout(int width, int height) {
int wid = Display.getWidth() - margin.left - margin.right;
if (getFieldCount() > 0) {
Field fd = this.getField(0);
layoutChild(fd, wid, height);
setPositionChild(fd, margin.left, 0);
setExtent(width, fd.getHeight());
} else {
setExtent(0, 0);
}
}

public BrowserField(String content) {
super(USE_ALL_WIDTH | VERTICAL_SCROLL);
deleteAll();
this.content = content;
createBroserField(false);
}

public Object eventOccurred(Event event) {
switch (event.getUID()) {
case Event.EVENT_URL_REQUESTED:
UrlRequestedEvent urlRequestedEvent = (UrlRequestedEvent) event;
String url = urlRequestedEvent.getURL();

Browser.getDefaultSession().displayPage(url);
break;
}
return null;
}

public int getAvailableHeight(BrowserContent browserContent) {
// TODO Auto-generated method stub
return Display.getHeight();
}

public int getAvailableWidth(BrowserContent browserContent) {
// TODO Auto-generated method stub
return Display.getWidth() - margin.left - margin.right;
}

public String getHTTPCookie(String url) {
// TODO Auto-generated method stub
return null;
}

public int getHistoryPosition(BrowserContent browserContent) {
// TODO Auto-generated method stub
return 0;
}

public HttpConnection getResource(RequestedResource resource,
BrowserContent referrer) {
if (resource == null || resource.getUrl() == null)
return null;
try {
return (HttpConnection) Connector.open(Util.getConnString(resource
.getUrl()));
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

public void invokeRunnable(Runnable runnable) {
UiApplication.getUiApplication().invokeLater(runnable);
}

private void createBroserField(boolean bigFont) {
int fontSize = bigFont ? 8 : 6;
final RenderingSession rs = RenderingSession.getNewInstance();
final RenderingOptions ro = rs.getRenderingOptions();
ro.setProperty(RenderingOptions.CORE_OPTIONS_GUID,
RenderingOptions.CSS_MEDIA_TYPE, "screen");
ro.setProperty(RenderingOptions.CORE_OPTIONS_GUID,
RenderingOptions.MINIMUM_FONT_SIZE, 1);
ro.setProperty(RenderingOptions.CORE_OPTIONS_GUID,
RenderingOptions.DEFAULT_FONT_SIZE, fontSize);
ro.setProperty(RenderingOptions.CORE_OPTIONS_GUID,
RenderingOptions.USER_AGENT, AGENT_STRING);
ro.setProperty(RenderingOptions.CORE_OPTIONS_GUID,
RenderingOptions.JAVASCRIPT_ENABLED, true);
ro.setProperty(RenderingOptions.CORE_OPTIONS_GUID,
RenderingOptions.OVERWRITE_CHARSET_MODE, true);
ro.setProperty(RenderingOptions.CORE_OPTIONS_GUID,
RenderingOptions.DEFAULT_CHARSET_VALUE, "UTF-8");

UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
try {
final ByteArrayInputStream stream = new ByteArrayInputStream(
content.getBytes("UTF-8"));
final HttpConnection httpCon = new FakeHttpConnection(
stream);
final BrowserContent browserContent = rs.getBrowserContent(
httpCon, BrowserField.this, null);
deleteAll();
add(browserContent.getDisplayableContent());
new Thread() {
public void run() {
try {
browserContent.finishLoading();
} catch (RenderingException e) {
e.printStackTrace();
} finally {
try {
httpCon.close();
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}.start();
} catch (RenderingException e) {
e.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
}

public void changeFont(boolean big) {
if (big) {
if (!isBigFont) {
createBroserField(true);
}
} else {
if (isBigFont) {
createBroserField(false);
}
}
isBigFont = big;
}

private boolean isBigFont = false;

}

 

 

 

//==================

 

BrowserField bField = new BrowserField(
html.toString());

 

这个html类似于<html></html>