added HTTP get support for Android

This commit is contained in:
rnvahey@gmail.com 2009-02-25 15:56:43 +07:00
parent 0e2d4d6af7
commit 62961fb95d
7 changed files with 49 additions and 2 deletions

View File

@ -300,7 +300,13 @@ var Device = {
clearWatch: function(filter) {
window.DroidGap.notificationClearWatch(filter);
}
}
},
http: {
get: function(url, file) {
window.DroidGap.httpGet(url, file);
}
}
}
function gotLocation(lat, lon) {

View File

@ -102,6 +102,14 @@ function onReceiveSms(number, message)
$('message').value = message;
}
http = function(func)
{
if (func == 'get') {
Device.http.get($('httpGetUrl').value, $('httpGetFile').value)
}
}
addLoadEvent(initGap);
@ -123,6 +131,7 @@ addLoadEvent(initGap);
<li><a href="#vibration" onclick="Device.playSound('on.mp3")">Play Sound</a></li>
<li><a href="#photo" onclick="Device.Image.getFromPhotoLibrary();">Photo...</a></li>
<li><a href="#notification" onclick="notification();">Notification...</a></li>
<li><a href="#http" onclick="http();">HTTP...</a></li>
<li><a href="http://phonegap.com/" target="_self">About</a></li>
</ul>
@ -258,4 +267,26 @@ addLoadEvent(initGap);
</fieldset>
</div>
<div id="http" title="http" class="panel">
<h2>HTTP</h2>
<p><i>Make sure your Android sdk sdcard is mounted!</i></p>
<fieldset>
<div class="row">
<a class="button leftButton" type="submit" onclick="http('get');">HTTP get remote_url</a>
</div>
</fieldset>
<fieldset>
<div class="row">
<label>remote_url:</label>
<input type=text name="httpGetUrl" id="httpGetUrl" size=60 maxlength=2048 value="http://hullomail.com/hulloworld.mp3" style="width: 30ex"></input>
</div>
</fieldset>
<fieldset>
<div class="row">
<label>destination:</label>
<input type=text name="httpGetFile" id="httpGetFile" size=60 maxlength=2048 value="/hullophonegap.mp3" style="width: 30ex"></input>
</div>
</fieldset>
</div>
<div id="preloader"></div></body></html>

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -233,6 +233,16 @@ public class PhoneGap{
mCtx.unregisterReceiver(mSmsListener);
}
}
public void httpGet(String url, String file)
/**
* grabs a file from specified url and saves it to a name and location
* the base directory /sdcard is abstracted so that paths may be the same from one mobile OS to another
* TODO: JavaScript call backs and error handling
*/
{
HttpHandler http = new HttpHandler();
http.get(url, file);
}
}