Reputation: 2342
I am sending this Base64 string to javascript and want to display on a textarea in webview but not succeeded,this is the string:
Rk1SACAyMAAAAAF6AAAA/AFEAMUAxQEAAABpE0BkABZgXUDLAFBZXUCOAFZcXUA+AFtiXUBaAGPg XUAkAGfkXUBYAHZmXUBEAIFkXUA7AJRnXUBGALRtXYDTABNKRICzAC9YXYBGADVfXYBxAJdnXYCh AJ9kXYBaAN9sXUA1ACbhV0BCAGziV4AzADRbUQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
also when i hardcode this string on a single line then it is display on web view correctly.. HArdcode single line String:
String bsiso1 = "Rk1SACAyMAAAAAF6AAAA/AFEAMUAxQEAAABpE0BkABZgXUDLAFBZXUCOAFZcXUA+AFtiXUBaAGPgXUAkAGfkXUBYAHZmXUBEAIFkXUA7AJRnXUBGALRtXYDTABNKRICzAC9YXYBGADVfXYBxAJdnXYChAJ9kXYBaAN9sXUA1ACbhV0BCAGziV4AzADRbUQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
This is my code:
public void showDialog(String dialogMsg){
browser.loadUrl("javascript:test(\""+bsiso+"\")");
Log.d("Bluetooth", "Bluetooth imei" + bsiso);
}
This is my method:
private void ReceiveCommand(byte[] data)
{
if((data[0]=='F')&&(data[1]=='T'))
{
switch(data[4])
{
case CMD_CAPTUREHOST:
{
int size=(byte)(data[5])+((data[6]<<8)&0xFF00)-1;
if(data[7]==1)
{
memcpy(mMatData,0,data,8,size);
mMatSize=size;
if(mMatData[0]==3){
bsiso=Base64.encodeToString(mMatData,0,mMatSize/*378*/,Base64.DEFAULT);
mEditText.setText(bsiso);
SaveTextToFile(bsiso);
AddStatusList("Capture Succeed");
}else{
bsiso=Base64.encodeToString(mMatData,0,378,Base64.DEFAULT);
mEditText.setText(bsiso);
SaveTextToFile(bsiso);
AddStatusList("Capture Succeed");
}
}
else
AddStatusList("Capture Fail");
}
break;
case CMD_GETSN:
{
int size=(byte)(data[5])+((data[6]<<8)&0xFF00)-1;
if(data[7]==1)
{
byte[] snb=new byte[32];
memcpy(snb,0,data,8,size);
String sn = null;
try {
sn = new String(snb,0,size,"UNICODE");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
AddStatusList("SN:"+sn);
}
else
AddStatusList("Get SN Fail");
}
break;
}
}
}
Note:- the hardcoded string in single line display well on webview..but when i send the string in a parameter then it is not display..waht is problem please help.
Upvotes: 0
Views: 510
Reputation: 2038
The problem is that the line breaks are breaking the javascript code. Remove the EOLs from the string or display the string in separate lines or paragraphs in the html code.
Notice that this won´t compile in any javascript capable browser (you can test it in the Chrome console or something):
test("a line
another");
Upvotes: 1