我将此Base64字符串发送到javascript并希望在webview中显示textarea但未成功,这是字符串:
Rk1SACAyMAAAAAF6AAAA / AFEAMUAxQEAAABpE0BkABZgXUDLAFBZXUCOAFZcXUA + AFtiXUBaAGPg XUAkAGfkXUBYAHZmXUBEAIFkXUA7AJRnXUBGALRtXYDTABNKRICzAC9YXYBGADVfXYBxAJdnXYCh AJ9kXYBaAN9sXUA1ACbhV0BCAGziV4AzADRbUQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
当我在一行上对此字符串进行硬编码时,它也正确显示在Web视图上。 HArdcode单行字符串:
String bsiso1 = "Rk1SACAyMAAAAAF6AAAA/AFEAMUAxQEAAABpE0BkABZgXUDLAFBZXUCOAFZcXUA+AFtiXUBaAGPgXUAkAGfkXUBYAHZmXUBEAIFkXUA7AJRnXUBGALRtXYDTABNKRICzAC9YXYBGADVfXYBxAJdnXYChAJ9kXYBaAN9sXUA1ACbhV0BCAGziV4AzADRbUQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
这是我的代码:
public void showDialog(String dialogMsg){
browser.loadUrl("javascript:test(\""+bsiso+"\")");
Log.d("Bluetooth", "Bluetooth imei" + bsiso);
}
这是我的方法:
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;
}
}
}
注意: - 单行显示的硬编码字符串在webview上显示良好..但是当我在参数中发送字符串然后它不显示..有问题请帮忙。
答案 0 :(得分:1)
问题是换行符打破了javascript代码。从字符串中删除EOL或在html代码中的单独行或段落中显示字符串。
请注意,这不会在任何支持JavaScript的浏览器中编译(您可以在Chrome控制台或其他东西中测试它):
test("a line
另一个“);