Android 允许其他应用在用户触摸下载链接时启动“我的活动”
ADM(下载管理器)中有一个功能,如果用户触摸下载链接(而不是网页),ADM(下载管理器)将显示为一个能够下载文件的应用程序 如果用户点击了下载链接,我的应用程序将显示为一个能够下载文件的应用程序,我该怎么办?DownloadData类Android 允许其他应用在用户触摸下载链接时启动“我的活动”,android,android-manifest,android-implicit-intent,Android,Android Manifest,Android Implicit Intent,ADM(下载管理器)中有一个功能,如果用户触摸下载链接(而不是网页),ADM(下载管理器)将显示为一个能够下载文件的应用程序 如果用户点击了下载链接,我的应用程序将显示为一个能够下载文件的应用程序,我该怎么办?DownloadData类 private long DownloadData (Uri uri, View v) { long downloadReference; // Create request for android download mana
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;
}
上述代码的说明:
downloadReference:这是一个唯一的id,我们将为特定的下载请求引用它
请求:DownloadManager的实例将通过传递
下载服务。在下一条语句中使用DownloadManager.request(uri)生成一个新请求
SetDestinationNexternalFilesDir:这将用于将文件保存在外部下载文件夹中
排队(请求):将对应于请求的新下载排队。下载管理器准备好执行并且连接可用后,下载将自动启动
来源:我想你没有正确理解我的问题。我只是想知道,如果用户点击了下载链接,我的应用程序将显示为一个能够下载文件的应用程序,我应该怎么做?我应该在Android清单中编写代码。但我不知道什么代码。请回答: