|
|
(Chilkat for Android™ API) HTTP Download any Type of File (binary or text)
The Download method may be called to download any type of file. It may be a binary file such as a .zip, .pdf, etc., or it may be text (.xml, .txt, etc.). There is no distinction. The Download method downloads the file from the web server and streams it to a file byte-for-byte exactly as received. Any web page may be downloaded in the same fashion. Passing a URL for a page that would normally be viewed in a browser would simply download to a file the HTML delivered by the web server.
SSL/TLS connections are fully supported by simply specifying a URL that begins with "https://".
Download: Chilkat for Android™ Java Libraries
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
String outStr = "";
CkHttp http = new CkHttp();
boolean success;
// Any string unlocks the component for the 1st 30-days.
success = http.UnlockComponent("Anything for 30-day trial");
if (success != true) {
outStr += http.lastErrorText() + "\n";
tv.setText(outStr);
setContentView(tv);
return;
}
String localFilePath;
// Download a .zip
localFilePath = "/temp/hamlet.zip";
success = http.Download("http://www.chilkatsoft.com/hamlet.zip",localFilePath);
if (success != true) {
outStr += http.lastErrorText() + "\n";
tv.setText(outStr);
setContentView(tv);
return;
}
// Download an XML file:
localFilePath = "/temp/hamlet.xml";
success = http.Download("http://www.chilkatsoft.com/hamlet.xml",localFilePath);
if (success != true) {
outStr += http.lastErrorText() + "\n";
tv.setText(outStr);
setContentView(tv);
return;
}
outStr += "OK!" + "\n";
tv.setText(outStr);
setContentView(tv);
}
static {
// Important: Make sure the name passed to loadLibrary matches the shared library
// found in your project's libs/armeabi directory.
// for "libchilkat.so", pass "chilkat" to loadLibrary
// for "libchilkatemail.so", pass "chilkatemail" to loadLibrary
// etc.
//
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}
|