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:de.j4velin.encrypter.EncryptedFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    RecyclerView recyclerView = (RecyclerView) inflater.inflate(R.layout.fragment_filelist, container, false);
    Database db = new Database(getContext());
    adapter = new FileAdapter(getContext(), new FileAdapter.ClickListener() {
        @Override//from   ww w.  j  a v a2  s.c  o m
        public void click(final File file) {
            selectedFile = file;
            Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.setType(selectedFile.mime);
            intent.putExtra(Intent.EXTRA_TITLE, selectedFile.name);
            EncryptedFragment.this.startActivityForResult(intent, REQUEST_OUTPUT);
        }
    }, new FileAdapter.DeleteListener() {
        @Override
        public boolean delete(final File file) {
            java.io.File f = new java.io.File(file.uri.getPath());
            if (!f.exists() || f.delete()) {
                Database db = new Database(getContext());
                db.deleteFile(file.id);
                db.close();
                return true;
            } else {
                return false;
            }
        }
    }, db.getFiles());
    db.close();
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    recyclerView.setAdapter(adapter);
    return recyclerView;
}

From source file:org.sufficientlysecure.keychain.util.FileHelper.java

/** Opens the storage browser on Android 4.4 or later for saving a file. */
@TargetApi(VERSION_CODES.KITKAT)/*from  www .jav a2 s  .c o  m*/
public static void saveDocument(Fragment fragment, String suggestedName, String mimeType, int requestCode) {
    Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType(mimeType);
    // Note: This is not documented, but works: Show the Internal Storage menu item in the drawer!
    intent.putExtra("android.content.extra.SHOW_ADVANCED", true);
    intent.putExtra(Intent.EXTRA_TITLE, suggestedName);
    fragment.startActivityForResult(intent, requestCode);
}

From source file:org.fitchfamily.android.wifi_backend.ui.MainSettingsFragment.java

@AfterPreferences
protected void init() {
    statistic = findPreference("db_size_preference");
    changedStat = findPreference("db_change_preference");
    permission = findPreference("grant_permission");
    final Preference exportAll = findPreference("db_export");
    final Preference exportChanged = findPreference("db_export_changed");
    final Preference importPref = findPreference("db_import");

    permission.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override/*ww w.  j a v  a 2s . co m*/
        public boolean onPreferenceClick(Preference preference) {
            requestPermission();
            return false;
        }
    });

    statistic.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Configuration.listOption(Configuration.LIST_OPTION_ALL);
            WifiListActivity_.intent(getActivity()).start();
            return true;
        }
    });

    changedStat.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Configuration.listOption(Configuration.LIST_OPTION_CHANGED);
            WifiListActivity_.intent(getActivity()).start();
            return true;
        }
    });

    exportAll.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                Configuration.exportOption(Configuration.EXPORT_OPTION_ALL);
                startActivityForResult(
                        new Intent(Intent.ACTION_CREATE_DOCUMENT).setType("text/comma-separated-values")
                                .addCategory(Intent.CATEGORY_OPENABLE).putExtra(Intent.EXTRA_TITLE, "wifi.csv"),
                        EXPORT_REQUEST_CODE);
            }
            return true;
        }
    });

    exportChanged.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                Configuration.exportOption(Configuration.EXPORT_OPTION_CHANGED);
                startActivityForResult(
                        new Intent(Intent.ACTION_CREATE_DOCUMENT).setType("text/comma-separated-values")
                                .addCategory(Intent.CATEGORY_OPENABLE).putExtra(Intent.EXTRA_TITLE, "wifi.csv"),
                        EXPORT_REQUEST_CODE);
            }
            return true;
        }
    });

    importPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                startActivityForResult(new Intent(Intent.ACTION_OPEN_DOCUMENT)
                        .setType("text/comma-separated-values").addCategory(Intent.CATEGORY_OPENABLE),
                        IMPORT_REQUEST_CODE);
            }

            return true;
        }
    });

    getLoaderManager().initLoader(0, null, new LoaderManager.LoaderCallbacks<DatabaseStatistic>() {
        @Override
        public Loader<DatabaseStatistic> onCreateLoader(int i, Bundle bundle) {
            return new DatabaseStatisticLoader(getActivity());
        }

        @Override
        public void onLoadFinished(Loader<DatabaseStatistic> loader, DatabaseStatistic databaseStatistic) {
            setRecords(databaseStatistic.accessPointCount());
            setChangedStat(databaseStatistic.accessPointChangeCount());
        }

        @Override
        public void onLoaderReset(Loader<DatabaseStatistic> loader) {
            setRecords(0);
            setChangedStat(0);
        }
    });

    checkPermission();
}

From source file:com.github.chenxiaolong.dualbootpatcher.FileUtils.java

@TargetApi(Build.VERSION_CODES.KITKAT)
private static Intent buildSafCreateDocumentIntent(String mimeType, String defaultName) {
    Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
    setCommonNativeSafOptions(intent);/* w w w .j ava2s .c  om*/
    setCommonSaveOptions(intent, mimeType, defaultName);
    return intent;
}

From source file:com.uphyca.kitkat.storage.ui.MainFragment.java

/**
 * ??//w  w w.j a va  2 s . co  m
 */
@OnClick(R.id.button_mkdir)
void onMkdirButtonClick() {
    String fileName = String.format("folder-%d", new SecureRandom().nextInt());
    Intent intent = new Intent().setAction(Intent.ACTION_CREATE_DOCUMENT).addCategory(Intent.CATEGORY_OPENABLE)
            .setType(DocumentsContract.Document.MIME_TYPE_DIR).putExtra(Intent.EXTRA_TITLE, fileName);
    startActivityForResult(intent, REQUEST_MKDIR);
}

From source file:com.uphyca.kitkat.storage.ui.MainFragment.java

/**
 * ??/*from  w  w  w. j a va 2 s .com*/
 */
@OnClick(R.id.button_create)
void onCreateButtonClick() {
    String fileName = String.format("document-%d.txt", new SecureRandom().nextInt());
    Intent intent = new Intent().setAction(Intent.ACTION_CREATE_DOCUMENT).addCategory(Intent.CATEGORY_OPENABLE)
            .setType("text/plain").putExtra(Intent.EXTRA_TITLE, fileName);
    startActivityForResult(intent, REQUEST_CREATE);
}

From source file:com.avalond.ad_blocak.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    switch (item.getItemId()) {
    case R.id.action_restore:
        config = FileHelper.loadPreviousSettings(this);
        FileHelper.writeSettings(this, MainActivity.config);
        reload();//from w w w.  j a  va 2s  .  co m
        break;
    case R.id.action_refresh:
        refresh();
        break;
    case R.id.action_load_defaults:
        config = FileHelper.loadDefaultSettings(this);
        reload();
        FileHelper.writeSettings(this, MainActivity.config);
        break;
    case R.id.action_import:
        Intent intent = new Intent().setType("*/*").setAction(Intent.ACTION_OPEN_DOCUMENT)
                .addCategory(Intent.CATEGORY_OPENABLE);

        startActivityForResult(intent, REQUEST_FILE_OPEN);
        break;
    case R.id.action_export:
        Intent exportIntent = new Intent(Intent.ACTION_CREATE_DOCUMENT).addCategory(Intent.CATEGORY_OPENABLE)
                .setType("*/*").putExtra(Intent.EXTRA_TITLE, "dns66.json");

        startActivityForResult(exportIntent, REQUEST_FILE_STORE);
        break;
    case R.id.action_about:
        Intent infoIntent = new Intent(this, InfoActivity.class);
        startActivity(infoIntent);
        break;
    }

    return super.onOptionsItemSelected(item);
}

From source file:org.jak_linux.dns66.MainActivity.java

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    switch (item.getItemId()) {
    case R.id.action_restore:
        config = FileHelper.loadPreviousSettings(this);
        FileHelper.writeSettings(this, MainActivity.config);
        reload();//from  w ww  . ja  v a  2 s .  c o m
        break;
    case R.id.action_refresh:
        refresh();
        break;
    case R.id.action_load_defaults:
        config = FileHelper.loadDefaultSettings(this);
        reload();
        FileHelper.writeSettings(this, MainActivity.config);
        break;
    case R.id.action_import:
        Intent intent = new Intent().setType("*/*").setAction(Intent.ACTION_OPEN_DOCUMENT)
                .addCategory(Intent.CATEGORY_OPENABLE);

        startActivityForResult(intent, REQUEST_FILE_OPEN);
        break;
    case R.id.action_export:
        Intent exportIntent = new Intent(Intent.ACTION_CREATE_DOCUMENT).addCategory(Intent.CATEGORY_OPENABLE)
                .setType("*/*").putExtra(Intent.EXTRA_TITLE, "dns66.json");

        startActivityForResult(exportIntent, REQUEST_FILE_STORE);
        break;
    case R.id.setting_show_notification:
        // If we are enabling notifications, we do not need to show a dialog.
        if (!item.isChecked()) {
            item.setChecked(!item.isChecked());
            MainActivity.config.showNotification = item.isChecked();
            FileHelper.writeSettings(MainActivity.this, MainActivity.config);
            break;
        }
        new AlertDialog.Builder(this).setIcon(R.drawable.ic_warning)
                .setTitle(R.string.disable_notification_title).setMessage(R.string.disable_notification_message)
                .setPositiveButton(R.string.disable_notification_ack, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        item.setChecked(!item.isChecked());
                        MainActivity.config.showNotification = item.isChecked();
                        FileHelper.writeSettings(MainActivity.this, MainActivity.config);
                    }
                }).setNegativeButton(R.string.disable_notification_nak, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {

                    }
                }).show();
        break;
    case R.id.action_about:
        Intent infoIntent = new Intent(this, InfoActivity.class);
        startActivity(infoIntent);
        break;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.commonsware.android.tte.MainActivity.java

private void createDocument() {
    Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT).addCategory(Intent.CATEGORY_OPENABLE)
            .setType("text/plain");

    startActivityForResult(intent, REQUEST_CREATE);
}

From source file:com.activiti.android.platform.provider.transfer.ContentTransferManager.java

public static final void requestCreateLocalContent(Fragment fr, String filename, String mimetype, File file) {

    if (AndroidVersion.isKitKatOrAbove()) {
        Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType(mimetype);//from   ww w. j a va 2  s. c  om
        intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
        intent.putExtra(Intent.EXTRA_TITLE, filename);
        fr.startActivityForResult(intent, CREATE_REQUEST_CODE);
    } else {
        // Good question ? Send Intent ? File Picker ?
    }
}