mirror of
https://github.com/apache/cordova-android.git
synced 2025-03-04 00:13:20 +08:00
added HTTP get support for Android
This commit is contained in:
parent
0e2d4d6af7
commit
62961fb95d
@ -300,6 +300,12 @@ var Device = {
|
|||||||
clearWatch: function(filter) {
|
clearWatch: function(filter) {
|
||||||
window.DroidGap.notificationClearWatch(filter);
|
window.DroidGap.notificationClearWatch(filter);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
http: {
|
||||||
|
get: function(url, file) {
|
||||||
|
window.DroidGap.httpGet(url, file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,6 +102,14 @@ function onReceiveSms(number, message)
|
|||||||
$('message').value = message;
|
$('message').value = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
http = function(func)
|
||||||
|
{
|
||||||
|
if (func == 'get') {
|
||||||
|
Device.http.get($('httpGetUrl').value, $('httpGetFile').value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
addLoadEvent(initGap);
|
addLoadEvent(initGap);
|
||||||
|
|
||||||
@ -123,6 +131,7 @@ addLoadEvent(initGap);
|
|||||||
<li><a href="#vibration" onclick="Device.playSound('on.mp3")">Play Sound</a></li>
|
<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="#photo" onclick="Device.Image.getFromPhotoLibrary();">Photo...</a></li>
|
||||||
<li><a href="#notification" onclick="notification();">Notification...</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>
|
<li><a href="http://phonegap.com/" target="_self">About</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
@ -258,4 +267,26 @@ addLoadEvent(initGap);
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</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>
|
<div id="preloader"></div></body></html>
|
||||||
|
BIN
bin/DroidGap.apk
BIN
bin/DroidGap.apk
Binary file not shown.
BIN
bin/classes.dex
BIN
bin/classes.dex
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -234,5 +234,15 @@ public class PhoneGap{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user