2017-08-18 17 views
0

からダウンロードした後、Pdf/.docファイルが壊れています。1)ダウンロードマネージャーからアンドロイドスタジオに.docx/pdfファイルをダウンロードした後、「ファイルに読み込めないコンテンツがあります。それを回復する?
2)しかし、私はjpgまたはmp3をダウンロードすると、正常に動作します。Androidスタジオでダウンロードマネージャ

マイコード:

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; 
} 

答えて

0

パブリッククラスPuneuniversity_mechanical_Engineering_SEがAppCompatActivityを拡張{// は、独自の広告ユニットIDを定義した後、以下の行を削除します。 プライベート静的ボタン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); 

       } 
      } 
    ); 


} 
関連する問題