1

URLから返されたのではなく、ネイティブのBlackBerryアプリでHTMLのいくつかの単純なチャンクを表示できるようにしたい。これは既存のStackoverflowの質問(たとえばここここ)に似ていますが、実際のBlackBerryサンプルコードを実行するための支援が必要です(または、これが機能しない運命にある理由を誰かに教えてください!)。

BlackBerry Webサイトには、利用可能なさまざまなAPIバージョンに基づくサンプルの「ブラウザー」コードがあります
。V4.5APIサンプルV5.0API
サンプル

コンポーネントパックに付属しているサンプルコードを見つけ(詳細はこちら)、V4.5サンプルコードを機能させようとしました。これが有用な出発点になることを望んでいました...

BrowserFieldDemoをEclipseでコンパイルし、シミュレーターで実行することができました(BrowserContentManagerDemo.java全体をコメントアウトする必要がありました。そうしないと、そのクラスが代わりに実行されます)。

残念ながら、シミュレーターに白い画面が表示されます。ロギングを追加してデバッガーを使用すると、次のgetBrowserContent()行ですべてがうまくいかないようです。

BrowserContent browserContent = null;

try
{
    browserContent = _renderingSession.getBrowserContent(connection, this, e);
    <snip>
}
catch (RenderingException re)
{
  EventLogger.logEvent(ID, (re + "").getBytes(), EventLogger.ERROR);
  System.err.println(re);
}

返される例外は次のとおりです。

net.rim.device.api.browser.field.RenderingException:接続中のIOException

4.5.0および4.7.0コンポーネントパックでシミュレータを構築して使用しようとしましたが、どちらも同じ症状を示します。

samples.codファイルをデバイスにプッシュして起動すると、「サンプルの起動中にエラーが発生しました:モジュール'samples'が安全なAPIにアクセスしようとしました」というメッセージが表示されます。おそらく、コード署名キー(私が持っている)を使用してサンプルコードに署名する必要がありますが、Eclipseでの方法がわかりません。

だから、私の質問は次のとおりです。

1)誰かが実際にこのV4.5サンプルコードを機能させましたか?シミュレーターをあきらめて、代わりにデバイスを使用する必要がありますか?

2)このV4.5アプローチは、私が持っているいくつかの単純なHTMLデータを表示するために機能しますか?たとえば、ローカルホストURLを使用できますか、またはデータを提供するためにカスタムHttpConnectionを作成できますか?

可能であれば、V4.5、V4.7、V5.0を実行しているBlackBerryモデルをサポートする必要があります。

ヒントをいただければ幸いです。

4

2 に答える 2

5

コンストラクターでString引数を取り、getType()、getLength()、openInputStream()のInputStreamなどのすべての値を返す独自のHttpConnectionを実装する必要があります。次に、sdkBrowserFieldDemoの場合と同様にブラウザーフィールドで使用します。

public class HttpConnectionImpl implements HttpConnection {
    private long streamLength = 7000;
    private DataInputStream dataInput;
    private InputStream in;
    private String encoding = "text/html";

    public HttpConnectionImpl(String data) {
        try {
            in = new ByteArrayInputStream(data.getBytes("UTF-8"));
            dataInput = new DataInputStream(in);
        } catch (Exception e) {
            System.out.println("HttpConnectionImpl : Exception : " + e);
        }

    }

    public String getURL() {
        return "";
    }

    public String getProtocol() {
        return "";
    }

    public String getHost() {
        return "";
    }

    public String getFile() {
        return "";
    }

    public String getRef() {
        return "";
    }

    public String getQuery() {
        return "";
    }

    public int getPort() {
        return 0;
    }

    public String getRequestMethod() {
        return "";
    }

    public void setRequestMethod(String s) throws IOException {

    }

    public String getRequestProperty(String s) {
        return "";
    }

    public void setRequestProperty(String s, String s1) throws IOException {

    }

    public int getResponseCode() throws IOException {
        return 200;
    }

    public String getResponseMessage() throws IOException {
        return "";
    }

    public long getExpiration() throws IOException {
        return 0;
    }

    public long getDate() throws IOException {
        return 0;
    }

    public long getLastModified() throws IOException {
        return 0;
    }

    public String getHeaderField(String s) throws IOException {
        return "";
    }

    public int getHeaderFieldInt(String s, int i) throws IOException {
        return 0;
    }

    public long getHeaderFieldDate(String s, long l) throws IOException {
        return 0;
    }

    public String getHeaderField(int i) throws IOException {
        return "";
    }

    public String getHeaderFieldKey(int i) throws IOException {
        return "";
    }

    public String getType() {
        return "text/html";
    }

    public String getEncoding() {
        return encoding;
    }

    public long getLength() {
        return streamLength;
    }

    public InputStream openInputStream() throws IOException {
        return in;
    }

    public DataInputStream openDataInputStream() throws IOException {
        return dataInput;
    }

    public void close() throws IOException {

    }

    public OutputStream openOutputStream() throws IOException {
        return new ByteArrayOutputStream();
    }

    public DataOutputStream openDataOutputStream() throws IOException {
        return new DataOutputStream(new ByteArrayOutputStream());
    }
}

使用例を含む完全なコードを参照してください

于 2009-12-10T15:05:06.663 に答える
1

デバイスシミュレータを起動する前に、必ずMDSシミュレータを起動してください。HTTPを使用するすべてまたはほとんどのサンプルはトランスポートを指定しないため、デフォルトのMDSトランスポートを使用します。つまり、MDSシミュレーターを実行していない場合、HTTP接続を確立できません。

于 2009-12-10T05:51:28.130 に答える