Recent

Author Topic: android jini reguest and response  (Read 4130 times)

zeljkoc

  • Full Member
  • ***
  • Posts: 123
    • Zeljko Cvijanovic
android jini reguest and response
« on: March 17, 2013, 10:23:01 pm »
if you can help out send HTML  code and read the answer

request  (nativetest.pas) and response (webpage.java)

function strFromJNI(env:PJNIEnv; this:jobject): string; cdecl;
begin
 // Result := '<html><body>Hello, world!</body> </html>');
end;

nativetest.pas
Code: [Select]
library nativetest;

{$mode delphi}

uses jni;

const curVM:JClass=nil;

function strFromJNI(env:PJNIEnv; this:jobject): string; cdecl;
begin
 // Result := '<html><body>Hello, world!</body> </html>');
end;

function JNI_OnLoad(vm:PJavaVM;reserved:pointer):jint; cdecl;
begin
  curVM:=vm;
  result:=JNI_VERSION_1_6;
end;

procedure JNI_OnUnload(vm:PJavaVM;reserved:pointer); cdecl;
begin
end;

exports
  JNI_OnLoad name 'JNI_OnLoad',
  JNI_OnUnload name 'JNI_OnUnload',
  strFromJNI name 'Java_com_pascal_systeminfo_webpage_strFromJNI';

begin
end.

webpage.java
Code: [Select]
package com.pascal.systeminfo;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import java.util.Date;

public class webpage extends Activity {
  WebView browser;

  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);
    browser=(WebView)findViewById(R.id.webkit);

    browser.loadData("<html><body>Hello, world!</body> </html>",
              "text/html", "UTF-8");
  }

  /** ------------------------------- */
  public long nativeCodeLoaded=0;

    static {
    try {
    System.loadLibrary("nativetest");
    } catch(UnsatisfiedLinkError ule) {
            ule.printStackTrace();
        }
    }

}       

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: android jini reguest and response
« Reply #1 on: March 20, 2013, 08:20:12 am »
JNI does not use Pascal strings, also not PChar's. You need to create JNI Strings with the method env^.NewStringUTF

See this JNI example here: http://lazarus-ccr.svn.sourceforge.net/viewvc/lazarus-ccr/bindings/android-ndk/examples/jnitest/jni/nativetest.pas?revision=2167&view=markup

zeljkoc

  • Full Member
  • ***
  • Posts: 123
    • Zeljko Cvijanovic
Re: android jini reguest and response
« Reply #2 on: March 20, 2013, 09:11:19 am »
thanks felipemdc

translation examples  I just managed with FPC-2.5.1 (laz4android)
JNI example can to work only with FPC-2.5.1

what to do to  it works lazaurs-1.1 FPC-2.7.1 or
(I install: WinXp 32, Lazarus BigIDE, arm-android
how to work with CodeTyphon 4.10)

in order to could do with a Stream?

library nativetest;

{$mode delphi}

uses jni;

const curVM:JClass=nil;

function strFromJNI(env:PJNIEnv; this:jobject): JString; cdecl;
var
Str: string;
begin
Str := '<html><body>Hello, world!</body> </html>';
Result := PEnv^.NewStringUTF(PEnv, PChar(Str));
end;

exports
strFromJNI name 'Java_com_pascal_systeminfo_webpage_strFromJNI';

begin
end.
package com.pascal.systeminfo;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import java.util.Date;

public class webpage extends Activity {
WebView browser;

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
browser=(WebView)findViewById(R.id.webkit);

try {
browser.loadData(strFromJNI(),"text/html", null);
} catch(UnsatisfiedLinkError ule) {
ule.printStackTrace();
}
}

}
/**
*/
public native String strFromJNI();
/**
*/
public long nativeCodeLoaded=0;

static {
try {
System.loadLibrary("nativetest");
} catch(UnsatisfiedLinkError ule) {
ule.printStackTrace();
}
}

}
« Last Edit: March 24, 2013, 06:54:56 am by zeljkoc »

zeljkoc

  • Full Member
  • ***
  • Posts: 123
    • Zeljko Cvijanovic
Re: android jini reguest and response
« Reply #3 on: April 01, 2013, 07:22:52 am »
I found a solution is bug

Quote
what to do to  it works lazaurs-1.1 FPC-2.7.1 or
(I install: WinXp 32, Lazarus BigIDE, arm-android
how to work with CodeTyphon 4.10)

problems:

Lazarus find lacation libdl.so to settings FLD:\Programs\android-ndk-r8d\platforms\android-8\arch-arm\usr\lib\libdl.so
to android

lazarus blank settings patch -Fl
copy libdl.so too root source pascal

« Last Edit: April 01, 2013, 07:30:30 am by zeljkoc »

 

TinyPortal © 2005-2018