1

Home.java

public void updatePhoto(Bitmap bitmap) {
   String bitmapStr = BitMapToString(bitmap);
   Home.currentBmp = bitmap;

   String parameter = "data:image/jpeg;base64," + bitmapStr;

   webView1.loadUrl("javascript:var script = document.createElement('script');" + 
      "script.type='text/javascript';script.src='form.js';" + 
      "script.onload=" + "processImage('" + parameter + "');" +
      //"script.onload=" + "processImage(':/;//');" +
      "document.getElementsByTagName('head').item(0).appendChild(script);");
   Log.v(parameter, "QWERTY");
   Log.v("QWERTY", parameter);
}

form.js

function processImage(img) {
   alert('process image end');
}

this function converts the Bitmap object into a base64 String, then executes an external javascript function (form.js -> processImage(var)). However it doesn't execute processImage and gives an Uncaught SyntaxError: Unexpected token ILLEGAL. However when i uncomment the

//"script.onload=" + "processImage(':/;//');" + 

line and comment in

"script.onload=" + "processImage('" + parameter + "');" +

it seems that the function is working well. The possible value for parameter variable would be

data:image/jpeg;base64,iVBORw0KgoAAAANSHUEgAAA......

What I am asking is how am I gonna make the javaScript function work with the parameter? Thanks!

Erwin
  • 4,757
  • 3
  • 31
  • 41
Dearwolves
  • 443
  • 4
  • 16
  • 1
    I don't think your `BitMapToString` is working correctly, also you'll have to wrap `processImage` in a function to pass it to `script.onload`. – Musa Sep 12 '12 at 02:16
  • Thanks I actually forgot to encrypt the string. I followed steps [here](http://stackoverflow.com/questions/8172730/in-android-how-to-concatenate-base64-encoded-strings) to encrypt the string with no wraps .. Thanks @Musa !! – Dearwolves Sep 12 '12 at 08:48
  • @RjMatt hi, I am looking extatly for your solution, have you find out best BitMapToString function ? – Ata Feb 21 '14 at 11:46

0 Answers0