Naman Yadav
Naman Yadav

Reputation: 1

File doesn't download

I am creating an app which downloads a pdf file whenever I click a button. But the issue is that whenever I click the button, the notification bar shows "File Downloading" but it doesn't download in the end. After a very long time, it shows "Download Unsuccessful". My pdf file is in my downloads folder(LocaDisk C/Users/Lenovo/Downloads/Papers/Test.pdf).

package io.app.hasura.imad.namanyadav123.mydtu;

import android.app.DownloadManager;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.cuboid.cuboidcirclebutton.CuboidButton;

public class Notes1 extends AppCompatActivity {
CuboidButton b1;
    DownloadManager dm;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notes1);



        b1=(CuboidButton) findViewById(R.id.m1);
        b1.setOnClickListener(new View.OnClickListener(){


            @Override

              public void onClick(View view){

                dm=(DownloadManager)getSystemService(Context.DOWNLOAD_SERVICE);
               Uri uri=Uri.parse("http://192.168.178.26/Papers/Test.pdf");

                DownloadManager.Request request=new DownloadManager.Request(uri);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                Long reference=dm.enqueue(request);


            }
        });
    }
}

Upvotes: 0

Views: 68

Answers (1)

Gabsii
Gabsii

Reputation: 456

In your case I would lay the file on a webserver and use this url. check out this instructables blog entry on how to setup a webserver

Upvotes: 1

Related Questions