Java Code Examples for android.content.Intent#ACTION_CREATE_DOCUMENT

The following examples show how to use android.content.Intent#ACTION_CREATE_DOCUMENT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BackupProgressActivity.java    From revolution-irc with GNU General Public License v3.0 6 votes vote down vote up
public void onBackupDone(File file) {
    if (file == null) {
        setDone(R.string.error_generic);
        return;
    }
    if (Build.VERSION.SDK_INT >= 19) {
        mBackupFile = file;
        Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType(MimeTypeMap.getSingleton().getMimeTypeFromExtension("zip"));
        String date = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(new Date());
        intent.putExtra(Intent.EXTRA_TITLE, "irc-client-backup-" + date + ".zip");
        startActivityForResult(intent, BACKUP_FILE_REQUEST_CODE);
        setSlideAnimation(false);
    } else {
        // TODO:
    }
}
 
Example 2
Source File: HashCalculatorFragment.java    From hash-checker with Apache License 2.0 6 votes vote down vote up
private void saveTextFile(@NonNull String filename) {
    try {
        Intent saveTextFileIntent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
        saveTextFileIntent.addCategory(Intent.CATEGORY_OPENABLE);
        saveTextFileIntent.setType("text/plain");
        saveTextFileIntent.putExtra(
                Intent.EXTRA_TITLE,
                filename + ".txt"
        );
        startActivityForResult(
                saveTextFileIntent,
                SettingsHelper.FILE_CREATE
        );
    } catch (ActivityNotFoundException e) {
        L.e(e);
        showSnackbarWithoutAction(
                getString(R.string.message_error_start_file_selector)
        );
    }
}
 
Example 3
Source File: SettingsFragment.java    From hash-checker with Apache License 2.0 6 votes vote down vote up
private void saveUserData() {
    if (HelperFactory.getHelper().isHistoryItemsListIsEmpty()) {
        try {
            Intent saveFileIntent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
            saveFileIntent.addCategory(Intent.CATEGORY_OPENABLE);
            saveFileIntent.setType("application/zip");
            saveFileIntent.putExtra(
                    Intent.EXTRA_TITLE,
                    DatabaseExporter.EXPORT_FILE
            );
            startActivityForResult(
                    saveFileIntent,
                    SettingsHelper.FILE_CREATE
            );
        } catch (ActivityNotFoundException e) {
            L.e(e);
            showSnackbar(
                    getString(R.string.message_error_start_file_selector)
            );
        }
    } else {
        showSnackbar(
                getString(R.string.history_empty_view_message)
        );
    }
}
 
Example 4
Source File: FileSelection.java    From APDE with GNU General Public License v2.0 5 votes vote down vote up
@NonNull
public static Intent createFileCreatorIntent(@Nullable CharSequence title) {
	Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
	intent.addCategory(Intent.CATEGORY_OPENABLE);
	intent.setType("*/*");
	intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] {"*/*"});
	if (title != null) {
		intent.putExtra(Intent.EXTRA_TITLE, title);
	}
	return intent;
}
 
Example 5
Source File: SAFUtil.java    From VinylMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
public static void openFilePicker(Fragment fragment) {
    Intent i = new Intent(Intent.ACTION_CREATE_DOCUMENT);
    i.addCategory(Intent.CATEGORY_OPENABLE);
    i.setType("audio/*");
    i.putExtra("android.content.extra.SHOW_ADVANCED", true);
    fragment.startActivityForResult(i, SAFUtil.REQUEST_SAF_PICK_FILE);
}
 
Example 6
Source File: SAFUtil.java    From VinylMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
public static void openFilePicker(Activity activity) {
    Intent i = new Intent(Intent.ACTION_CREATE_DOCUMENT);
    i.addCategory(Intent.CATEGORY_OPENABLE);
    i.setType("audio/*");
    i.putExtra("android.content.extra.SHOW_ADVANCED", true);
    activity.startActivityForResult(i, SAFUtil.REQUEST_SAF_PICK_FILE);
}
 
Example 7
Source File: GalleryActivity.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
private void saveImageTo(int page) {
    if (null == mGalleryProvider) {
        return;
    }
    File dir = getCacheDir();
    UniFile file;
    if (null == (file = mGalleryProvider.save(page, UniFile.fromFile(dir), mGalleryProvider.getImageFilename(page)))) {
        Toast.makeText(this, R.string.error_cant_save_image, Toast.LENGTH_SHORT).show();
        return;
    }
    String filename = file.getName();
    if (filename == null) {
        Toast.makeText(this, R.string.error_cant_save_image, Toast.LENGTH_SHORT).show();
        return;
    }
    mCacheFileName = filename;
    Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("image/*");
    intent.putExtra(Intent.EXTRA_TITLE, filename);
    try {
        startActivityForResult(intent, WRITE_REQUEST_CODE);
    } catch (Throwable e) {
        ExceptionUtils.throwIfFatal(e);
        Toast.makeText(this, R.string.error_cant_find_activity, Toast.LENGTH_SHORT).show();
    }
}
 
Example 8
Source File: ThemeEditorActivity.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        onBackPressed();
        return true;
    }
    if (item.getItemId() == R.id.action_rename) {
        View view = LayoutInflater.from(this)
                .inflate(R.layout.dialog_edit_text, null);
        EditText text = view.findViewById(R.id.edit_text);
        text.setText(getThemeInfo().name);
        new AlertDialog.Builder(this)
                .setTitle(R.string.action_rename)
                .setView(view)
                .setPositiveButton(R.string.action_ok, (dialog1, which) -> {
                    getThemeInfo().name = text.getText().toString();
                    notifyThemeNameChanged();
                })
                .setNegativeButton(R.string.action_cancel, null)
                .show();
        return true;
    } else if (item.getItemId() == R.id.action_export) {
        if (Build.VERSION.SDK_INT >= 19) {
            Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.setType("application/x-mrarm-irc-theme");
            intent.putExtra(Intent.EXTRA_TITLE, getThemeInfo().name + ".irctheme");
            startActivityForResult(intent, REQUEST_CODE_EXPORT);
        }
    }
    return super.onOptionsItemSelected(item);
}
 
Example 9
Source File: BackupActivity.java    From andOTP with MIT License 5 votes vote down vote up
private void showSaveFileSelector(String mimeType, Constants.BackupType backupType, int intentId) {
    if (settings.getBackupAsk()) {
        Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType(mimeType);
        intent.putExtra(Intent.EXTRA_TITLE, BackupHelper.backupFilename(this, backupType));
        startActivityForResult(intent, intentId);
    } else {
        if (settings.isBackupLocationSet()) {
            if (intentId == Constants.INTENT_BACKUP_SAVE_DOCUMENT_PLAIN) {
                BackupHelper.BackupFile plainBackupFile = BackupHelper.backupFile(this, settings.getBackupLocation(), Constants.BackupType.PLAIN_TEXT);

                if (plainBackupFile.file != null)
                    doBackupPlain(plainBackupFile.file.getUri());
                else
                    Toast.makeText(this, plainBackupFile.errorMessage, Toast.LENGTH_LONG).show();
            } else if (intentId == Constants.INTENT_BACKUP_SAVE_DOCUMENT_CRYPT) {
                BackupHelper.BackupFile cryptBackupFile = BackupHelper.backupFile(this, settings.getBackupLocation(), Constants.BackupType.ENCRYPTED);

                if (cryptBackupFile.file != null)
                    doBackupCrypt(cryptBackupFile.file.getUri());
                else
                    Toast.makeText(this, cryptBackupFile.errorMessage, Toast.LENGTH_LONG).show();
            } else if (intentId == Constants.INTENT_BACKUP_SAVE_DOCUMENT_PGP) {
                BackupHelper.BackupFile pgpBackupFile = BackupHelper.backupFile(this, settings.getBackupLocation(), Constants.BackupType.OPEN_PGP);

                if (pgpBackupFile.file != null)
                    backupEncryptedWithPGP(pgpBackupFile.file.getUri(), null);
                else
                    Toast.makeText(this, pgpBackupFile.errorMessage, Toast.LENGTH_LONG).show();
            }
        } else {
            Toast.makeText(this, R.string.backup_toast_no_location, Toast.LENGTH_LONG).show();
        }
    }
}
 
Example 10
Source File: Exporter.java    From masterpassword with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
private Intent getStorageAccessFrameworkIntent(String fileName) {
    Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);

    // Filter to only show results that can be "opened", such as
    // a file (as opposed to a list of contacts or timezones).
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    // Create a file with the requested MIME type.
    intent.setType("*/*");
    intent.putExtra(Intent.EXTRA_TITLE, fileName);
    return intent;
}
 
Example 11
Source File: DetailActivity.java    From GetApk with MIT License 5 votes vote down vote up
private void createApk(String fileName) {
    Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("application/vnd.android.package-archive");
    intent.putExtra(Intent.EXTRA_TITLE, fileName);
    startActivityForResult(intent, REQUEST_COPY);
}
 
Example 12
Source File: MainActivity.java    From rcloneExplorer with MIT License 5 votes vote down vote up
public void exportConfigFile() {
    Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("text/*");
    intent.putExtra(Intent.EXTRA_TITLE, "rclone.conf");
    startActivityForResult(intent, WRITE_REQUEST_CODE);
}
 
Example 13
Source File: TGSafProvider.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void saveDocumentAs(TGFileFormat fileFormat) {
	Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
	intent.addCategory(Intent.CATEGORY_OPENABLE);
	intent.setType(MIME_TYPE);
	intent.putExtra(EXTRA_SHOW_ADVANCED, true);
	intent.putExtra(Intent.EXTRA_TITLE, this.createDefaultFileName(fileFormat));

	this.getActionHandler().callStartActivityForResult(intent, new TGSafSaveHandler(this, fileFormat));
}
 
Example 14
Source File: ActivityDns.java    From NetGuard with GNU General Public License v3.0 5 votes vote down vote up
private Intent getIntentExport() {
    Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("*/*"); // text/xml
    intent.putExtra(Intent.EXTRA_TITLE, "netguard_dns_" + new SimpleDateFormat("yyyyMMdd").format(new Date().getTime()) + ".xml");
    return intent;
}
 
Example 15
Source File: IntentUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 获取创建文件的意图
 * <pre>
 *     getCreateDocumentIntent("text/plain", "foobar.txt");
 *     getCreateDocumentIntent("image/png", "mypicture.png");
 *     <p></p>
 *     创建后在 onActivityResult 中获取到 Uri, 对 Uri 进行读写
 * </pre>
 * @param mimeType 资源类型
 * @param fileName 文件名
 * @return 创建文件的意图
 */
public static Intent getCreateDocumentIntent(final String mimeType, final String fileName) {
    try {
        Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType(mimeType);
        intent.putExtra(Intent.EXTRA_TITLE, fileName);
        return intent;
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "getCreateDocumentIntent");
    }
    return null;
}
 
Example 16
Source File: StorageController.java    From slide with MIT License 5 votes vote down vote up
private void createPdf(Activity a) {
    Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("application/pdf");
    intent.putExtra(Intent.EXTRA_TITLE, a.getString(R.string.pdf_name_prefix)+getTimestamp());
    a.startActivityForResult(intent, EXPORT_PDF_REQUEST_CODE);
}
 
Example 17
Source File: MainActivity.java    From openScale with GNU General Public License v3.0 5 votes vote down vote up
private void startActionCreateDocumentForExportIntent() {
    OpenScale openScale = OpenScale.getInstance();
    ScaleUser selectedScaleUser = openScale.getSelectedScaleUser();

    Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("text/csv");
    intent.putExtra(Intent.EXTRA_TITLE, getExportFilename(selectedScaleUser));

    startActivityForResult(intent, EXPORT_DATA_REQUEST);
}
 
Example 18
Source File: ActivitySetup.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
private static Intent getIntentExport() {
    Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("*/*");
    intent.putExtra(Intent.EXTRA_TITLE, "fairemail_" +
            new SimpleDateFormat("yyyyMMdd").format(new Date().getTime()) + ".backup");
    Helper.openAdvanced(intent);
    return intent;
}
 
Example 19
Source File: HistoryFragment.java    From Stringlate with MIT License 5 votes vote down vote up
private void exportToSd() {
    String filename = mLastSelectedRepo.getProjectName() + ".zip";

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);

        intent.setType("application/zip");
        intent.putExtra(Intent.EXTRA_TITLE, filename);
        startActivityForResult(intent, RESULT_CREATE_FILE);
    } else {
        File output = new File(getCreateExportRoot(), filename);
        doExportToSd(Uri.fromFile(output));
    }
}
 
Example 20
Source File: StorageController.java    From slide with MIT License 5 votes vote down vote up
private void openDocument(Activity a) {
    Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TITLE, a.getString(R.string.default_new_doc_name));
    a.startActivityForResult(intent, OPEN_DOCUMENT_REQUEST_CODE);
}