Can We Open Download Folder Via. Intent?
Actually, I need to open the default Download folder from my application. Is it possible? If yes, then please provide some reference. I am able to get the path of Download folder w
Solution 1:
You can show the recent downloads activity with the following Intent
startActivity(new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS));
Available since API 9
Solution 2:
Samsung solution:
publicstaticvoidopenDownloads(@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(newIntent(DownloadManager.ACTION_VIEW_DOWNLOADS));
}
publicstaticbooleanisSamsung() {
String manufacturer = Build.MANUFACTURER;
if (manufacturer != null) return manufacturer.toLowerCase().equals("samsung");
returnfalse;
}
publicstaticFilegetDownloadsFile() {
returnEnvironment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
}
Found by decompiling the Samsung My Files app dex and seeing how the MainActivity deals with intents.
publicstaticfinalStringMYFILES_NOTIFICATION_LAUNCH_INTENT_NAME="samsung.myfiles.intent.action.LAUNCH_MY_FILES";
publicstaticfinalStringNOTIFICATION_START_PATH="samsung.myfiles.intent.extra.START_PATH";
publicstaticfinalStringSTART_PATH="FOLDERPATH";
if (Constant.MYFILES_NOTIFICATION_LAUNCH_INTENT_NAME.equals(intent.getAction())) {
StringstartNotificationPath= intent.getStringExtra(Constant.NOTIFICATION_START_PATH);
if (startNotificationPath != null) {
BundlenewArgument=newBundle();
newArgument.putString(Constant.START_PATH, startNotificationPath);
if (newFile(startNotificationPath).exists()) {
startBrowser(513, newArgument);
}
}
intent.removeExtra(Constant.NOTIFICATION_START_PATH);
}
Solution 3:
I had similar problem showing files in Downloads in Samsung and LG and i just added file-parameter "downloaded" for DownloadManager and file showing in Downloads:
DownloadManagerdownloadManager= (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
downloadManager.addCompletedDownload(file.getName(), file.getName(), true,
"application", file.getPath(), file.length(), true);
Post a Comment for "Can We Open Download Folder Via. Intent?"