Skip to content

Commit

Permalink
Fix redirect bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ABPSoft committed Feb 13, 2019
1 parent 5afa04b commit 44f5f28
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,21 @@ public void run()

Log.i("ABPDownloader","Response Code: "+responseCode);

if(responseCode==200)
// With redirect
if(followRedirect)
{
if(responseCode >= 300 && responseCode<=399)
{
Log.i("ABPDownloader","Redirect URL: "+httpURLConnection.getHeaderField("Location"));

setSourceUrl(httpURLConnection.getHeaderField("Location"));
start();

return;
}
}

if(responseCode >= 200)
{
totalSize=httpURLConnection.getContentLength();

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.aminbahrami.abpdownloaderlib">

<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand All @@ -12,7 +14,7 @@
<activity android:name=".ActivityMain">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ProgressBar;

import com.aminbahrami.abpdownloader.ABPDownloader;

public class ActivityMain extends Activity
{
Expand All @@ -10,5 +15,53 @@ protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

findViewById(R.id.download).setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
download();
}
});
}

private void download()
{
final ProgressBar progressBar=findViewById(R.id.progressBar);

ABPDownloader downloader=new ABPDownloader();

downloader.setSourceUrl("http://www.14bazikon.com/14bazikon.apk")
.setDestinationPath(getFilesDir()+"/test.apk")
.setFollowRedirect(true)
.setDownloadListener(new ABPDownloader.IDownloadListener()
{
@Override
public void onProgressDownload(int percent)
{
progressBar.setProgress(percent);
}

@Override
public void onCompleteDownload()
{

}

@Override
public void onError(int errorCode,String errorString)
{
Log.i("LOG","Error: "+errorString);
}

@Override
public void onCancel()
{

}
})
.setFollowRedirect(true)
.start();
}
}
14 changes: 13 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context=".ActivityMain">


<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

<Button
android:id="@+id/download"
android:text="Download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

0 comments on commit 44f5f28

Please sign in to comment.