Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On devices lower than Android 6.0 #47

Closed
muzaffer652 opened this issue May 18, 2017 · 2 comments
Closed

On devices lower than Android 6.0 #47

muzaffer652 opened this issue May 18, 2017 · 2 comments
Assignees

Comments

@muzaffer652
Copy link

Hello,

Marshmallow does not download on low-end devices

Status = 905 in log output

`public class SingleDownloadActivity extends AppCompatActivity implements FetchListener {

private static final int STORAGE_PERMISSION_CODE = 100;

private View rootView;
private TextView progressTextView;
private TextView titleTextView;

private long downloadId = -1;
private Fetch fetch;
private  String url,path,fname;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_single_download);

    rootView = findViewById(R.id.activity_single_download);
    progressTextView = (TextView) findViewById(R.id.progressTextView);
    titleTextView = (TextView) findViewById(R.id.titleTextView);


    Bundle extras = getIntent().getExtras();
    url = extras.getString("url");
    path = extras.getString("path");
    fname = extras.getString("name");
    fetch = Fetch.getInstance(this);
    clearAllDownloads();
}

@Override
protected void onResume() {
    super.onResume();

    if(downloadId != -1) {

        RequestInfo info = fetch.get(downloadId);

        if (info != null) {
            setProgressView(info.getStatus(),info.getProgress());
        }

        fetch.addFetchListener(this);
    }
}

@Override
protected void onPause() {
    super.onPause();
    fetch.removeFetchListener(this);
}

@Override
protected void onDestroy() {
    super.onDestroy();
    fetch.release();
}

/*Removes all downloads managed by Fetch*/
private void clearAllDownloads() {

    fetch.removeAll();
    createRequest();
}

private void createRequest() {

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
    {

        requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}
                ,STORAGE_PERMISSION_CODE);
    }else
    {
        enqueueDownload();
    }
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {

    if(requestCode == STORAGE_PERMISSION_CODE || grantResults.length > 0
            && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

        enqueueDownload();

    }else {
        Snackbar.make(rootView,R.string.permission_not_enabled,Snackbar.LENGTH_LONG).show();
    }
}

private void enqueueDownload() {

    Request request = new Request(url,path,fname);

    downloadId = fetch.enqueue(request);

    setTitleView(request.getFilePath());
    setProgressView(Fetch.STATUS_QUEUED,0);
}

@Override
public void onUpdate(long id, int status, int progress, long downloadedBytes, long fileSize, int error) {

    if(id == downloadId) {

        if(status == Fetch.STATUS_ERROR) {

            showDownloadErrorSnackBar(error);

        }else {

            setProgressView(status,progress);
        }
    }
}

private void setTitleView(String fileName) {

    Uri uri = Uri.parse(fileName);
    titleTextView.setText("yükleniyor");
}

private void setProgressView(int status,int progress) {


    switch (status) {

        case Fetch.STATUS_QUEUED : {
            progressTextView.setText(R.string.queued);
            break;
        }
        case Fetch.STATUS_DOWNLOADING :
        case Fetch.STATUS_DONE : {

            if(progress == -1) {

                progressTextView.setText(R.string.downloading);
            }else {

                String progressString = getResources()
                        .getString(R.string.percent_progress,progress);

                progressTextView.setText(progressString);
            }
            finish();
            break;
        }
        default: {
            Log.d("SingleDownloadActivity",status + "asd");
            progressTextView.setText(R.string.status_unknown);
            break;
        }
    }
}

private void showDownloadErrorSnackBar(int error) {

    final Snackbar snackbar = Snackbar.make(rootView,"Download Failed: ErrorCode: "
            + error,Snackbar.LENGTH_INDEFINITE);

    snackbar.setAction(R.string.retry, new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            fetch.retry(downloadId);
            snackbar.dismiss();
        }
    });

    snackbar.show();
}`
@tonyofrancis
Copy link
Owner

@muzaffer652 A status of 905 means that the request was removed/deleted. There may be a race condition going on. I am looking into this and will update this issue with what I find.

@tonyofrancis tonyofrancis self-assigned this May 19, 2017
@muzaffer652
Copy link
Author

fetch.removeall (); Erased.
And everything worked fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants