Java Code Examples for android.content.Intent.ACTION_CREATE_DOCUMENT

The following are Jave code examples for showing how to use ACTION_CREATE_DOCUMENT of the android.content.Intent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: q-mail   File: Accounts.java   View Source Code Vote up 8 votes
private void performExport(final boolean includeGlobals, final Account account) {
    // TODO, prompt to allow a user to choose which accounts to export
    ArrayList<String> accountUuids = null;
    if (account != null) {
        accountUuids = new ArrayList<>();
        accountUuids.add(account.getUuid());
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        exportGlobalSettings = includeGlobals;
        exportAccountUuids = accountUuids;

        Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
        intent.setType("application/octet-stream");
        intent.putExtra(Intent.EXTRA_TITLE, SettingsExporter.generateDatedExportFileName());
        intent.addCategory(Intent.CATEGORY_OPENABLE);

        startActivityForResult(intent, ACTIVITY_REQUEST_SAVE_SETTINGS_FILE);
    } else {
        startExport(includeGlobals, accountUuids, null);
    }
}
 
Example 2
Project: foco   File: ImportExportUtils.java   View Source Code Vote up 7 votes
/**
 * This method starts create document system activity.
 * @param activity
 * @param doc
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
public static void exportDocument(Activity activity,
                                  DocumentMetadata doc) {
    Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);

    // show only results that can be "opened", such as a file
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    // create a file with plain text MIME type
    intent.setType(MIME_TYPE);
    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
    String currentDate = sdf.format(new Date());
    String suggestedName = String.format(SUGGESTED_NAME_FORMAT, doc.getName(), currentDate);
    intent.putExtra(Intent.EXTRA_TITLE, suggestedName);
    activity.startActivityForResult(intent, WRITE_REQUEST_CODE);
}
 
Example 3
Project: revolution-irc   File: BackupProgressActivity.java   View Source Code Vote up 7 votes
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 4
Project: CodeCompilerApp   File: MainActivity.java   View Source Code Vote up 7 votes
private void saveTheFile(boolean saveAs) {
    if (!saveAs && greatUri != null && greatUri.getUri() != null && greatUri.getUri() != Uri.EMPTY)
        new SaveFileTask(this, greatUri, pageSystem.getAllText(mEditor.getText()
                .toString()), currentEncoding, new SaveFileTask.SaveFileInterface() {
            @Override
            public void fileSaved(Boolean success) {
                savedAFile(greatUri, true);
            }
        }).execute();
    else {
        if (Device.hasKitKatApi() && PreferenceHelper.getUseStorageAccessFramework(this)) {
            Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
            intent.setType("*/*");
            intent.putExtra(Intent.EXTRA_TITLE, greatUri.getFileName());
            startActivityForResult(intent, SAVE_AS_REQUEST_CODE);
        } else {
            new NewFileDetailsDialog(
                    greatUri,
                    pageSystem.getAllText(mEditor.getText().toString()),
                    currentEncoding
            ).show(getFragmentManager().beginTransaction(), "dialog");
        }

    }
}
 
Example 5
Project: CodeCompilerApp   File: MainActivity.java   View Source Code Vote up 7 votes
public void CreateFile(View view) {
    if (Device.hasKitKatApi() && PreferenceHelper.getUseStorageAccessFramework(this)) {
        Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
        intent.setType("*/*");
        //intent.putExtra(Intent.EXTRA_TITLE, ".txt");
        startActivityForResult(intent, CREATE_REQUEST_CODE);
    } else {
        newFileToOpen(new GreatUri(Uri.EMPTY, "", ""), "");
    }
}
 
Example 6
Project: RetroMusicPlayer   File: SAFUtil.java   View Source Code Vote up 7 votes
@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 7
Project: RetroMusicPlayer   File: SAFUtil.java   View Source Code Vote up 6 votes
@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);
}