实际上,我需要从我的应用程序中打开默认的“下载”文件夹。可能吗?如果是,那么请提供一些参考。
我可以通过以下方式获取Download文件夹的路径:
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
任何帮助都将受到赞赏。
答案 0 :(得分:32)
您可以使用以下Intent
startActivity(new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS));
自API 9起可用
答案 1 :(得分:6)
三星解决方案:
public static void openDownloads(@NonNull Activity activity) {
if (isSamsung()) {
Intent intent = activity.getPackageManager()
.getLaunchIntentForPackage("com.sec.android.app.myfiles");
intent.setAction("samsung.myfiles.intent.action.LAUNCH_MY_FILES");
intent.putExtra("samsung.myfiles.intent.extra.START_PATH",
getDownloadsFile().getPath());
activity.startActivity(intent);
}
else activity.startActivity(new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS));
}
public static boolean isSamsung() {
String manufacturer = Build.MANUFACTURER;
if (manufacturer != null) return manufacturer.toLowerCase().equals("samsung");
return false;
}
public static File getDownloadsFile() {
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
}
通过反编译三星My Files app dex并了解MainActivity如何处理意图找到。
public static final String MYFILES_NOTIFICATION_LAUNCH_INTENT_NAME = "samsung.myfiles.intent.action.LAUNCH_MY_FILES";
public static final String NOTIFICATION_START_PATH = "samsung.myfiles.intent.extra.START_PATH";
public static final String START_PATH = "FOLDERPATH";
if (Constant.MYFILES_NOTIFICATION_LAUNCH_INTENT_NAME.equals(intent.getAction())) {
String startNotificationPath = intent.getStringExtra(Constant.NOTIFICATION_START_PATH);
if (startNotificationPath != null) {
Bundle newArgument = new Bundle();
newArgument.putString(Constant.START_PATH, startNotificationPath);
if (new File(startNotificationPath).exists()) {
startBrowser(513, newArgument);
}
}
intent.removeExtra(Constant.NOTIFICATION_START_PATH);
}
答案 2 :(得分:0)
我在三星和LG的Downloads中显示文件时遇到了类似的问题,我只是为DownloadManager添加了文件参数“ downloaded”,并在Downloads中显示了文件:
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
downloadManager.addCompletedDownload(file.getName(), file.getName(), true,
"application", file.getPath(), file.length(), true);