Inside you manifest file you need to add an intent filter:
<activity
android:name="Downloader">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="domain.com"
android:scheme="http" />
</intent-filter>
</activity>
Then inside your "Download" activity's onCreate:
public class Download extends Activity {
private String filename;
@Override
protected void onCreate (final Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView(<your layout file>);
final Intent intent = getIntent ();
final Uri data = intent.getData ();
if (data != null) {
final List<String> pathSegments = data.getPathSegments ();
fileName = pathSegments.get (pathSegments.size () - 1);
}
}
Then in the clickhandler for the download button you can use a view intent to act like a link in android.
button.setOnClickListener (new View.OnClickListener () {
@Override public void onClick (final View v) {
Uri intentUri = Uri.parse("http://domain.com/" + filename);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(intentUri);
startActivity(intent);
}
});