Example usage for android.content Intent ACTION_CREATE_DOCUMENT

List of usage examples for android.content Intent ACTION_CREATE_DOCUMENT

Introduction

In this page you can find the example usage for android.content Intent ACTION_CREATE_DOCUMENT.

Prototype

String ACTION_CREATE_DOCUMENT

To view the source code for android.content Intent ACTION_CREATE_DOCUMENT.

Click Source Link

Document

Activity Action: Allow the user to create a new document.

Usage

From source file:com.anjalimacwan.MainActivity.java

@TargetApi(Build.VERSION_CODES.KITKAT)
private void reallyExportNote() {
    String filename = "";

    try {/*  w ww  .jav  a2  s.  co m*/
        filename = loadNoteTitle(filesToExport[fileBeingExported].toString());
    } catch (IOException e) {
        /* Gracefully fail */ }

    Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TITLE, generateFilename(filename));

    try {
        startActivityForResult(intent, EXPORT);
    } catch (ActivityNotFoundException e) {
        showToast(R.string.error_exporting_notes);
    }
}

From source file:android_network.hetnet.vpn_service.ActivityLog.java

private Intent getIntentPCAPDocument() {
    Intent intent;/*  www .j a v  a 2s .  c om*/
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        if (Util.isPackageInstalled("org.openintents.filemanager", this)) {
            intent = new Intent("org.openintents.action.PICK_DIRECTORY");
        } else {
            intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(
                    Uri.parse("https://play.google.com/store/apps/details?id=org.openintents.filemanager"));
        }
    } else {
        intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("application/octet-stream");
        intent.putExtra(Intent.EXTRA_TITLE,
                "netguard_" + new SimpleDateFormat("yyyyMMdd").format(new Date().getTime()) + ".pcap");
    }
    return intent;
}

From source file:eu.faircode.adblocker.ActivityLog.java

private Intent getIntentPCAPDocument() {
    Intent intent;/* w  ww . j a  v  a  2  s  . co m*/
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        if (Util.isPackageInstalled("org.openintents.filemanager", this)) {
            intent = new Intent("org.openintents.action.PICK_DIRECTORY");
        } else {
            intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(
                    Uri.parse("https://play.google.com/store/apps/details?id=org.openintents.filemanager"));
        }
    } else {
        intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("application/octet-stream");
        intent.putExtra(Intent.EXTRA_TITLE,
                "adblocker_" + new SimpleDateFormat("yyyyMMdd").format(new Date().getTime()) + ".pcap");
    }
    return intent;
}

From source file:com.maskyn.fileeditorpro.activity.MainActivity.java

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// w  w  w.j  a v  a  2s  . com
                    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");
        }

    }
}

From source file:com.orange.ocara.ui.activity.ResultAuditActivity.java

/**
 * To savge a document by its path.<br/>
 *
 * @param path the file path to share//w ww  .  j  av a 2s  . c om
 */
private void saveDocument(String path) {
    Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType(
            MimeTypeMap.getSingleton().getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(path)));
    startActivityForResult(intent, ACTION_SAVE_DOCUMENT);
}

From source file:org.drrickorang.loopback.LoopbackActivity.java

/**
 * Save five files: one .png file for a screenshot on the main activity, one .wav file for
 * the plot displayed on the main activity, one .txt file for storing various test results, one
 * .txt file for storing recorder buffer period data, and one .txt file for storing player
 * buffer period data.//w  w  w  . j  a v  a2  s. com
 */
public void onButtonSave(View view) {
    if (!isBusy()) {
        //create filename with date
        String date = mCurrentTime; // the time the plot is acquired
        //String micSource = getApp().getMicSourceString(getApp().getMicSource());
        String fileName = "loopback_" + date;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TITLE, fileName + ".txt"); //suggested filename
            startActivityForResult(intent, SAVE_TO_TXT_REQUEST);

            Intent intent2 = new Intent(Intent.ACTION_CREATE_DOCUMENT);
            intent2.addCategory(Intent.CATEGORY_OPENABLE);
            intent2.setType("image/png");
            intent2.putExtra(Intent.EXTRA_TITLE, fileName + ".png"); //suggested filename
            startActivityForResult(intent2, SAVE_TO_PNG_REQUEST);

            //sometimes ".wav" will be added automatically, sometimes not
            Intent intent3 = new Intent(Intent.ACTION_CREATE_DOCUMENT);
            intent3.addCategory(Intent.CATEGORY_OPENABLE);
            intent3.setType("audio/wav");
            intent3.putExtra(Intent.EXTRA_TITLE, fileName + ".wav"); //suggested filename
            startActivityForResult(intent3, SAVE_TO_WAVE_REQUEST);

            fileName = "loopback_" + date + "_recorderBufferPeriod";
            Intent intent4 = new Intent(Intent.ACTION_CREATE_DOCUMENT);
            intent4.addCategory(Intent.CATEGORY_OPENABLE);
            intent4.setType("text/plain");
            intent4.putExtra(Intent.EXTRA_TITLE, fileName + ".txt");
            startActivityForResult(intent4, SAVE_RECORDER_BUFFER_PERIOD_TO_TXT_REQUEST);

            fileName = "loopback_" + date + "_playerBufferPeriod";
            Intent intent5 = new Intent(Intent.ACTION_CREATE_DOCUMENT);
            intent5.addCategory(Intent.CATEGORY_OPENABLE);
            intent5.setType("text/plain");
            intent5.putExtra(Intent.EXTRA_TITLE, fileName + ".txt");
            startActivityForResult(intent5, SAVE_PLAYER_BUFFER_PERIOD_TO_TXT_REQUEST);
        } else {
            saveAllTo(fileName);
        }
    } else {
        showToast("Test in progress... please wait");
    }
}

From source file:eu.faircode.adblocker.ActivitySettings.java

private Intent getIntentCreateExport() {
    Intent intent;//from  www.  j  a  v a 2 s  .  c om
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        if (Util.isPackageInstalled("org.openintents.filemanager", this)) {
            intent = new Intent("org.openintents.action.PICK_DIRECTORY");
        } else {
            intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(
                    Uri.parse("https://play.google.com/store/apps/details?id=org.openintents.filemanager"));
        }
    } else {
        intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("*/*"); // text/xml
        intent.putExtra(Intent.EXTRA_TITLE,
                "adblocker_" + new SimpleDateFormat("yyyyMMdd").format(new Date().getTime()) + ".xml");
    }
    return intent;
}

From source file:com.master.metehan.filtereagle.ActivityMain.java

private Intent getIntentLogcat() {
    Intent intent;//from   w  ww  .j a v  a  2  s . co  m
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        if (Util.isPackageInstalled("org.openintents.filemanager", this)) {
            intent = new Intent("org.openintents.action.PICK_DIRECTORY");
        } else {
            intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(
                    Uri.parse("https://play.google.com/store/apps/details?id=org.openintents.filemanager"));
        }
    } else {
        intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TITLE, "logcat.txt");
    }
    return intent;
}

From source file:android_network.hetnet.vpn_service.ActivitySettings.java

private Intent getIntentCreateExport() {
    Intent intent;/*from   ww  w  .  j  a  v a  2s.  co m*/
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        if (Util.isPackageInstalled("org.openintents.filemanager", this)) {
            intent = new Intent("org.openintents.action.PICK_DIRECTORY");
        } else {
            intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(
                    Uri.parse("https://play.google.com/store/apps/details?id=org.openintents.filemanager"));
        }
    } else {
        intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("*/*"); // text/xml
        intent.putExtra(Intent.EXTRA_TITLE,
                "netguard_" + new SimpleDateFormat("yyyyMMdd").format(new Date().getTime()) + ".xml");
    }
    return intent;
}

From source file:com.maskyn.fileeditorpro.activity.MainActivity.java

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 {// w  w  w .j av a2s .  c om
        newFileToOpen(new GreatUri(Uri.EMPTY, "", ""), "");
    }
}