Spanish [SOLUCIONADO] Se puede cargar Java Sricpt en B4A?

ebqlabs

Active Member
Licensed User
Hola, estoy realizando los siguiente en html

index.php
B4X:
<html>
<head><title></title>
<script>
function textodeiframe()
{
var frame = document.getElementById('fram1');
var txt = frame.contentWindow.document.getElementById('txt1').value;
document.getElementById('txt2').value = txt;    
}
</script>
</head>
<body>

<iframe id="fram1" width="100%" frameborder="0" src="cargar.html">
</iframe>

Este es el contenido del control del iframe, tendra que estar en B4A:
<input type="text" name="txt2" id="txt2" />
<input type="button" value="Cambiar Texto" onClick="textodeiframe();">

</body>
</html>


cargar.html
B4X:
<html>
<head><title></title></head>
<body>
<input type="text" name="txt1" id="txt1" />
</body>
</html>


lo que quiero realizar es cargar la pagina html index.php en B4A
todo bien lo llamo así:

B4X:
WebView1.LoadUrl ("http://ebqlabs.cl/dario/index.php")

Lo que quiero realizar que al cargar la pagina en b4a, crear un boton y una caja de texto. al momento de presionar el botón llame la función y pase el texto de html a b4a

function textodeiframe()
{
var frame = document.getElementById('fram1');
var txt = frame.contentWindow.document.getElementById('txt1').value;
document.getElementById('txt2').value = txt;
}



pero dejarlo mas claro, le adjunto una imagen
espero que se entienda lo que quiero realizar y me puedan ayudar. saludos

2w31coj.png
 

bgsoft

Well-Known Member
Licensed User
Longtime User
Hola ebqlabs

Desde la versión de B4A 4.30 puedes incrustar código Java

Se hace asi:
B4X:
#If JAVA
public String FirstMethod() {
return "Hola!";
}
#End If

Necesitas una instancia al JavaObject para acceder a los métodos de Java:

B4X:
Sub Process_Globals
  Private NativoJ As JavaObject
End Sub

Sub Activity_Create(FirstTime As Boolean)

  If FirstTime Then NativoJ.InitializeContext
 

  Dim s As String = NativoJ.RunMethod("FirstMethod", Null)
  Log(s) ' Hola!
End Sub

Saludos
 

inakigarm

Well-Known Member
Licensed User
Longtime User

ebqlabs

Active Member
Licensed User
ya lo soluciones como pasar un texto de html a B4A

le mando el codigo por si alguno lo necesita...

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: True
    #IncludeTitle: False
#End Region

Sub Process_Globals

End Sub

Sub Globals
    Dim WebView1 As WebView

    Dim txt2 As EditText
   
    Dim WebViewExtras As WebViewExtras
End Sub

Sub Activity_Create(FirstTime As Boolean)

    txt2.Initialize("txt2")
    Activity.AddView(txt2, 0, 10%y, 100%x, 10%y)
   
    WebView1.Initialize("WebView1")
    Activity.AddView(WebView1, 0, 20%y, 100%x, 80%y)
   
    WebView1.LoadUrl ("file:///android_asset/index.php")

    WebViewExtras.addJavascriptInterface(WebView1, "B4A")
    WebViewExtras.addWebChromeClient(WebView1, "")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub boton_Click

End Sub

Sub xTest(strTest As String)
    txt2.Text = strTest
End Sub

y en la carpeta Files guarda este codigo html (index.php)

B4X:
<html>

<head><title></title>


<script type="text/javascript">
function test(){

var txt = document.getElementById('llevar').value;
    B4A.CallSub('xTest', true, txt);
}
</script>




</head>

<body>


<input type="text" name="llevar" id="llevar" />





<input type="button" value="Cambiar Texto a B4A" onClick="test();">



</body>

</html>

saludos.
 

ebqlabs

Active Member
Licensed User
Lo que estoy realizando ahora es como pasar a B4A a HTMl

alguien que me pueda ayudar con este código, saludos
 

ebqlabs

Active Member
Licensed User
En el código que puse fue pasar de html a B4A

ahora quiero hacerlo al revés

que una caja de texto en B4A pase a la caja de texto del html
 

inakigarm

Well-Known Member
Licensed User
Longtime User
Te paso parte de un ejemplo que hice para entrar automáticamente el login y un usuario en un formulario de una página Web (el Webview estaba oculto y en la pantalla tenía sólo el cuadro de texto de Login y PW del programa B4A

B4X:
Dim MyWebViewExtras As WebViewExtras       
Javascript="document.forms.new_user.user_login.value='" & EditText1.Text & "';document.forms.new_user.user_password.value='" & EditText2.Text &"';document.forms.new_user.submit();"      
MyWebViewExtras.executeJavascript(WebView1, Javascript)
 

ebqlabs

Active Member
Licensed User
Algo por ahí va lo que quiero realizar.
me cuesto un poco plantearlo, no se si me podrías a replicarlo en el ejemplo (lo adjunto )

saludos
 

Attachments

  • b4a javas.zip
    350.4 KB · Views: 326

Carlos marin

Active Member
Licensed User
Longtime User
amigo me sale este error en todo lo que intento abrir no se por que,
Not allowed to load local resource: file:///android_asset/webkit/android-weberror.png in data:text/html,chromewebdata (Line: 12)
 

ebqlabs

Active Member
Licensed User
amigo me sale este error en todo lo que intento abrir no se por que,
Not allowed to load local resource: file:///android_asset/webkit/android-weberror.png in data:text/html,chromewebdata (Line: 12)


de html a b4a

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: True
    #IncludeTitle: False
#End Region

Sub Process_Globals

End Sub

Sub Globals
    Dim WebView1 As WebView

    Dim txt2 As EditText
  
    Dim WebViewExtras As WebViewExtras
End Sub

Sub Activity_Create(FirstTime As Boolean)

    txt2.Initialize("txt2")
    Activity.AddView(txt2, 0, 10%y, 100%x, 10%y)
  
    WebView1.Initialize("WebView1")
    Activity.AddView(WebView1, 0, 20%y, 100%x, 80%y)
  
    WebView1.LoadUrl ("file:///android_asset/index.php")

    WebViewExtras.addJavascriptInterface(WebView1, "B4A")
    WebViewExtras.addWebChromeClient(WebView1, "")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub boton_Click

End Sub

Sub xTest(strTest As String)
    txt2.Text = strTest
End Sub




y en la carpeta Files guarda este codigo html (index.php)


B4X:
<html>

<head><title></title>


<script type="text/javascript">
function test(){

var txt = document.getElementById('llevar').value;
    B4A.CallSub('xTest', true, txt);
}
</script>




</head>

<body>


<input type="text" name="llevar" id="llevar" />





<input type="button" value="Cambiar Texto a B4A" onClick="test();">



</body>

</html>
 

Carlos marin

Active Member
Licensed User
Longtime User
amigo muchas gracias, me va tocar estudiar mucho ese codigo php pero gracias. tengo este codigo que lo vi en el tutorial kio4 y la idea es poder llevarle las variables de latitud y longitud para que los consulte, no quedan en cajas de texto como tu ejemplo sino como variables VARIABLES A,B,C


B4X:
<div id="map1div" style="height: 400px;"></div>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?v=3&amp;sensor=false&amp"></script>
<script type="text/javascript">
  function map1_initialize( ) {
    var cwc2011_venue_data = [ {
      name: "VARIABLE C",
      latlng: new google.maps.LatLng( VARIABLE A, VARIABLE B )
    } ];
    var map = new google.maps.Map( document.getElementById( "map1div" ), {
      center: new google.maps.LatLng( 0, 0 ),
      zoom: 0,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    } );
    for ( var i = 0; i < cwc2011_venue_data.length; i++ ) {
      new google.maps.Marker( {
        position: cwc2011_venue_data[ i ].latlng,
        map: map,
        title: cwc2011_venue_data[ i ].name
      } );
    }
    var latlngbounds = new google.maps.LatLngBounds( );
    for ( var i = 0; i < cwc2011_venue_data.length; i++ ) {
      latlngbounds.extend( cwc2011_venue_data[ i ].latlng );
    }
    map.fitBounds( latlngbounds );
    new google.maps.Rectangle( {
      bounds: latlngbounds,
      map: map,
      fillColor: "#000000",
      fillOpacity: 0,
      strokeWeight: 0
    } );
  }
  google.maps.event.addDomListener( window, 'load', map1_initialize );
</script>


Otro caso seria poder insertar la cadena completa esta variable
B4X:
var cwc2011_venue_data = [ {
      name: "VARIABLE C",
      latlng: new google.maps.LatLng( VARIABLE A, VARIABLE B )
    } ];

si algo te estaria muy agradecido esto me tiene loco por que mis conocimientos en php y html son muy pocos
 
Top