title: SL4A + Intents + Jquery + Webview
body: <p>I am writing sl4a android app utilizing webviews. I am trying to achieve a call from the webview to an event handler in my python script that launches an intent to pick an image from the image gallery and send back an image path to the webview so it can append to a pop up screen via foundation 5 reveal module as well as a hidden input tag to submit. </p>
  
  <p>The problem I am having is twofold. I am looking for the correct way to loop the registerCallback function until the user clicks on a photo and returns the value from python i.e. an indefinite amount of time as the user decides which picture to select. As of now, if there is not a sleep or a setTimeout being looped, it is looking for the event before it has happened. Also, the url variable assigned by the anonymous function is not acknowledged as it passes through the if/else statements. I know this has to be a scope issue but I am not certain what I am doing wrong. </p>
  
  <p><strong>Jquery Code</strong></p>
  
  <pre><code>var picInc = 0;
  var url = undefined;
  
  $(function(){
    $('#picSelect').click( function(){
    picInc += 1;
    droid._pickPic();
    while( url == undefined ){
      sleep(3000);   // maybe setTimeout(function{ null function}, 1000);
      droid.registerCallback('picSelect', function(msg){
        url = msg.data;
    });
    }
    if( url == 'None' ){
      url = undefined;
    }else{
      var strip = url.split('\\').pop().split('/').pop();
    $('.PICADD').append(' /* add img tag with image path */ ');
    url = undefined;
    }
    });
    });
  </code></pre>
  
  <p><strong>Python Code</strong></p>
  
  <pre><code>while True:
      event = droid.eventWait().result
      name = event['name']
      data = event['data']
      if event['data'] == 'PIC':
          activity = droid.startActivityForResult('android.intent.action.GET_CONTENT', None, 'image/*') #, {'android.intent.action.extra.ALLOW_MULTIPLE': True}
          if activity.result == None:
              droid.eventPost('picSelect', 'None') 
          else:     
              result = activity.result['data']
              parsedUriPath = droid.queryContent(result)
              cleanParsed = parsedUriPath.result[0]['_data']
              droid.eventPost('picSelect', '{}'.format(str(cleanParsed)))
  </code></pre>