我的下载管理器无法下载apk文件

时间:2016-09-10 12:25:53

标签: java android

在我的项目中,我可以下载jpg或png或pdf等文件。 但是当我输入apk链接时,它会下载但无法打开它。 并且它显示了与不同的文件夹,我认为它根本不是apk,虽然我给apk链接。

当我收到下载链接时,这是我的代码:

final Dialog dialog = new Dialog(DownloadDataActivity.this);                        
dialog.setContentView(R.layout.alert_custom);
dialog.setTitle(getResources().getString(R.string.title_dialog));

// set the custom dialog components - text, image and button
final EditText text = (EditText) dialog.findViewById(R.id.text);
final String link = text.getText().toString();
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        if (text.getText().toString().equals("")) {
            Toast.makeText(getApplicationContext(), getResources().getString(R.string.no_link), Toast.LENGTH_LONG).show();
            TextView showCountries = (TextView) findViewById(R.id.countryData);
            showCountries.setText("");
        } else {

            downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
            Uri Download_Uri = Uri.parse(text.getText().toString());
            DownloadManager.Request request = new DownloadManager.Request(Download_Uri);

            //Restrict the types of networks over which this download may proceed.
            request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
            //Set whether this download may proceed over a roaming connection.
            request.setAllowedOverRoaming(false);
            //Set the title of this download, to be displayed in notifications (if enabled).
            request.setTitle("");
            //Set a description of this download, to be displayed in notifications (if enabled)
            request.setDescription("");
            //Set the local destination for the downloaded file to a path within the application's external files directory
            request.setDestinationInExternalFilesDir(DownloadDataActivity.this, Environment.DIRECTORY_DOWNLOADS, Download_Uri+"");

            //Enqueue a new download and same the referenceId
            downloadReference = downloadManager.enqueue(request);

            showCountries.setText(getResources().getString(R.string.download));
        }
        dialog.dismiss();

例如此链接: http://cdn.p30download.com/?b=p30dl-mobile&f=CarX.Drift.Racing.v1.3.8_p30download.com.apk

它显示了我的" cdn.p30download.com" 并说它不能开放。

0 个答案:

没有答案