Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can we open download folder via. intent?

Tags:

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 with the help of:

Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)

Any help will be well appreciated.

like image 908
abhishek kumar gupta Avatar asked Feb 07 '14 06:02

abhishek kumar gupta


People also ask

How do I open a download folder?

Look for the My Files (or File Manager) icon and tap it. If you don't see it, instead tap the Samsung icon with many smaller icons inside it — My Files will be among them. 3. Inside the My Files app, tap "Downloads."

How do I open download folder on Android?

Open the Files app, then scroll down on the Browse tab to the bottom of the screen. Under the Storage devices section, tap Internal storage. Locate, then tap the Download folder. Notice that it now shows Internal storage > Download at the top rather than just a shortcut tab for the Download folder.

What is the path for download folder?

By default, Chrome, Firefox and Microsoft Edge download files to the Downloads folder located at %USERPROFILE%\Downloads. USERPROFILE is a variable that refers to the logged in user's profile directory on the Windows computer, e.g. the path may look like C:\Users\YourUserName\Downloads.

How do I open file explorer in Android programmatically?

Intent intent = new Intent(Intent. ACTION_GET_CONTENT); intent. setType("*/*"); Intent i = Intent. createChooser(intent, "View Default File Manager"); startActivityForResult(i, CHOOSE_FILE_REQUESTCODE);


2 Answers

You can show the recent downloads activity with the following Intent

startActivity(new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS));

Available since API 9

like image 186
Ion Aalbers Avatar answered Oct 12 '22 17:10

Ion Aalbers


Samsung solution:

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

Found by decompiling the Samsung My Files app dex and seeing how the MainActivity deals with intents.

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);
            }
like image 29
Veedka Avatar answered Oct 12 '22 17:10

Veedka