This has full implementation of how to select app to be used as external download manager using
Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.i("Kiwi", "[DownloadPreferences] Received activity result, RQ: " + requestCode);
if (requestCode == 4242 && resultCode == Activity.RESULT_OK && data != null) {
ComponentName componentName = data.getComponent();
final String packageName = componentName.getPackageName();
final String activityName = componentName.getClassName();
Log.i("Kiwi", "[DownloadPreferences] Received activity result, PN: " + packageName + " - AN: " + activityName);
SharedPreferences.Editor sharedPreferencesEditor = ContextUtils.getAppSharedPreferences().edit();
sharedPreferencesEditor.putString("selected_external_download_manager_package_name", packageName);
sharedPreferencesEditor.putString("selected_external_download_manager_activity_name", activityName);
sharedPreferencesEditor.apply();
updateDownloadSettings();
}
}
How to share download target to external app
if ("enable_external_download_manager".equals(preference.getKey())) {
SharedPreferences.Editor sharedPreferencesEditor = ContextUtils.getAppSharedPreferences().edit();
sharedPreferencesEditor.putBoolean("enable_external_download_manager", (boolean)newValue);
sharedPreferencesEditor.apply();
if ((boolean)newValue == true) {
List<Intent> targetedShareIntents = new ArrayList<Intent>();
Intent shareIntent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://test.com/file.rar"));
// Set title and text to share when the user selects an option.
shareIntent.putExtra(Intent.EXTRA_TEXT, "http://test.com/file.rar");
List<ResolveInfo> resInfo = getActivity().getPackageManager().queryIntentActivities(shareIntent, 0);
if (!resInfo.isEmpty()) {
for (ResolveInfo info : resInfo) {
if (!"com.kiwibrowser.browser".equalsIgnoreCase(info.activityInfo.packageName)) {
Intent targetedShare = new Intent(android.content.Intent.ACTION_VIEW);
targetedShare.setPackage(info.activityInfo.packageName.toLowerCase(Locale.ROOT));
targetedShareIntents.add(targetedShare);
}
}
// Then show the ACTION_PICK_ACTIVITY to let the user select it
Intent intentPick = new Intent();
intentPick.setAction(Intent.ACTION_PICK_ACTIVITY);
// Set the title of the dialog
intentPick.putExtra(Intent.EXTRA_TITLE, "Download manager");
intentPick.putExtra(Intent.EXTRA_INTENT, shareIntent);
intentPick.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray());
// Call StartActivityForResult so we can get the app name selected by the user
this.startActivityForResult(intentPick, /* REQUEST_CODE_MY_PICK */ 4242);
}
}
}
return true;
}
https://github.com/kiwibrowser/src.next/blob/kiwi/chrome/browser/download/android/java/src/org/chromium/chrome/browser/download/settings/DownloadSettings.java
This has full implementation of how to select app to be used as external download manager using
How to share download target to external app
A simple web-intent uri will