I've the following code in my jsp file:
<script>
var linkto = magicnumber.devuelveMagicNumber();
document.writeln("<a href='"+linkto+".com'>"+linkto+"</a>");
</script>
On Clase.java I've declared the following class:
public class MagicNumber
{
Clase padre;
public MagicNumber(Clase padre)
{
this.padre=padre;
}
@JavascriptInterface
public String devuelveMagicNumber()
{
return padre.devuelveMagicNumber();
}
}
And in the class Clase of Class.java
public String devuelveMagicNumber()
{
return magicnumber;
}
But when I load the page on my app it doesn't show anything where it should show the link, it should be showing a magic number that my android app has generated.
What I find pretty strange is that the following code do works:
On my jsp file:
<a href="javascript:void();" onclick="scanner.doScan('<%=Utils.parseString(request,"accion")%>');return false;">Tengo tarjeta ></a>
And on my Clase.java I've defined the following class
public class Scanner
{
Clase padre;
public Scanner(Clase padre)
{
this.padre=padre;
}
@JavascriptInterface
public void doScan(String accion)
{
padre.doScan(accion);
}
}
And finally the following is in the Class Clase in Clase.java.
public void doScan(String accion)
{
this.accion=accion;
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
try
{
intent.putExtra("SCAN_MODE","QR_CODE_MODE");
startActivityForResult(intent,0);
}
catch(Exception e)
{ Toast.makeText(this,R.string.error_app_qr,Toast.LENGTH_LONG).show();
}
}
I don't have a clue why the second one works and the first one doesn't... Could anyone please guide me about what could I be missing?
Thanks for your attention.