1

1) After downloading a .docx/pdf file in android studio through download manager it shows me a message "Unreadable content in file. Do you want to recover it?"
2) But when i download a jpg or a mp3, it works fine.

My code:

private long DownloadData (Uri uri, View v) {

    long downloadReference;

    downloadManager = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
    DownloadManager.Request request = new DownloadManager.Request(uri);

    //Setting title of request
    request.setTitle("ZoraizCV");
    request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);

    //Setting description of request
    request.setDescription("Android Data download using DownloadManager.");

    //Set the local destination for the downloaded file to a path within the application's external files directory
    if(v.getId() == R.id.DownloadMusic)
      request.setDestinationInExternalFilesDir(MainActivity.this, Environment.DIRECTORY_DOWNLOADS,"zoraizCV.docx");


    request.allowScanningByMediaScanner();
    //Enqueue download and save the referenceId
    downloadReference = downloadManager.enqueue(request);



    Button DownloadStatus = (Button) findViewById(R.id.DownloadStatus);
    DownloadStatus.setEnabled(true);
    Button CancelDownload = (Button) findViewById(R.id.CancelDownload);
    CancelDownload.setEnabled(true);

    return downloadReference;
}
Zoraiz Ejaz
  • 127
  • 11

1 Answers1

0

public class Puneuniversity_mechanical_Engineering_SE extends AppCompatActivity { // Remove the below line after defining your own ad unit ID. private static Button Btn_Download; DownloadManager downloadManager;

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

    // Load an ad into the AdMob banner view.
    AdView adView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder()
            .setRequestAgent("android_studio:ad_template").build();
    adView.loadAd(adRequest);
    Btn_Download=(Button)findViewById(R.id.Download);
    Btn_Download.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    downloadManager= (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
                    Uri uri= Uri.parse("https://drive.google.com/uc?export=download&id=0B6C5vNWHm0sCSVlXZ3ljTnA3Tjg");
                    DownloadManager.Request request=new DownloadManager.Request(uri);
                    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                    Long reference=downloadManager.enqueue(request);

                }
            }
    );


}
Jayesh Thakkar
  • 113
  • 2
  • 12