提问者:小点点

我们可以通过打开下载文件夹吗。意图


实际上,我需要从我的应用程序中打开默认的下载文件夹。可以吗?如果可以,请提供一些参考。

我可以在以下帮助下获取下载文件夹的路径:

Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)

任何帮助都将不胜感激。


共3个答案

匿名用户

您可以按以下意图显示最近的下载活动

startActivity(new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS));

自API 9起提供

匿名用户

三星解决方案:

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

通过反编译Samsung My Files应用程序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);
            }

匿名用户

我在三星和LG的下载中显示文件时遇到了类似的问题,我刚刚为DownloadManager添加了文件参数“downloaded”,并在下载中显示文件:

  DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
        downloadManager.addCompletedDownload(file.getName(), file.getName(), true,
                "application", file.getPath(), file.length(), true);