DownloadDataクラスWEL上記のコードの
private long DownloadData (Uri uri, View v) {
long downloadReference;
// Create request for android download manager
downloadManager = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(uri);
//Setting title of request
request.setTitle("Data Download");
//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,"AndroidTutorialPoint.mp3");
else if(v.getId() == R.id.DownloadImage)
request.setDestinationInExternalFilesDir(MainActivity.this,
Environment.DIRECTORY_DOWNLOADS,"AndroidTutorialPoint.jpg");
//Enqueue download and save into 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;
}
説明を英語を話すことができないので、それは私たちが特定のダウンロード要求のために参照する一意のIDです。
要求:DownloadManagerのインスタンスが
DOWNLOAD_SERVICEを渡すことによってgetSystemServiceを通じて作成されます。 DownloadManager.Request(uri)を使用して次のステートメントに新しい要求が生成されます。
setDestinationInExternalFilesDir:外部ダウンロードフォルダにファイルを保存するために使用されます。
downloadManager.enqueue(request):要求に対応する新しいダウンロードをエンキューします。ダウンロードマネージャは、ダウンロードマネージャが実行準備ができて接続が可能になると、自動的に起動します。
出典:https://www.codeproject.com/Articles/1112730/Android-Download-Manager-Tutorial-How-to-Download
あなたは私の質問を理解していないと思います。私が知りたいのは、ユーザーがダウンロードリンクをタッチすると、ファイルをダウンロードできるアプリケーションが表示されます。私はAndroidのマニフェストにコードを書く必要があります。しかし、私はどのようなコードを知りません。 – Hadi
こちらの回答:https://stackoverflow.com/questions/7721905/register-an-app-to-show-in-complete-action-using-dialog-in-android – Hangman