Example usage for android.content Intent ACTION_OPEN_DOCUMENT

List of usage examples for android.content Intent ACTION_OPEN_DOCUMENT

Introduction

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

Prototype

String ACTION_OPEN_DOCUMENT

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

Click Source Link

Document

Activity Action: Allow the user to select and return one or more existing documents.

Usage

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

@TargetApi(Build.VERSION_CODES.KITKAT)
private static Intent buildSafOpenDocumentIntent(String mimeType) {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    setCommonNativeSafOptions(intent);//from w  w w.j a va2 s.  c  o m
    setCommonOpenOptions(intent, mimeType);
    return intent;
}

From source file:com.commonsware.android.documents.consumer.ConsumerFragment.java

@TargetApi(Build.VERSION_CODES.KITKAT)
private void open() {
    Intent i = new Intent().setType("*/*").setAction(Intent.ACTION_OPEN_DOCUMENT)
            .addCategory(Intent.CATEGORY_OPENABLE);

    startActivityForResult(i, REQUEST_OPEN);
}

From source file:me.kartikarora.transfersh.activities.TransferActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_transfer);
    mNoFilesTextView = (TextView) findViewById(R.id.no_files_text_view);
    mFileItemsGridView = (GridView) findViewById(R.id.file_grid_view);
    FloatingActionButton uploadFileButton = (FloatingActionButton) findViewById(R.id.upload_file_fab);
    mCoordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinator_layout);
    mAdView = (AdView) findViewById(R.id.banner_ad_view);

    if (uploadFileButton != null) {
        uploadFileButton.setOnClickListener(new View.OnClickListener() {
            @Override/*from   w  w  w.  j a v  a 2 s  .c  om*/
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
                intent.setType("*/*");
                startActivityForResult(intent, FILE_RESULT_CODE);
            }
        });
    }

    getSupportLoaderManager().initLoader(BuildConfig.VERSION_CODE, null, this);
    TransferApplication application = (TransferApplication) getApplication();
    mTracker = application.getDefaultTracker();

    mTracker.send(new HitBuilders.EventBuilder().setCategory("Activity : " + this.getClass().getSimpleName())
            .setAction("Launched").build());
}

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

/**
 * ?/* ww w. j av  a  2s  .co  m*/
 */
@OnClick(R.id.button_open)
void onOpenButtonClick() {
    Intent intent = new Intent().setAction(Intent.ACTION_OPEN_DOCUMENT).addCategory(Intent.CATEGORY_OPENABLE)
            .setType("text/*");
    startActivityForResult(intent, REQUEST_OPEN);
}

From source file:com.ultramegasoft.flavordex2.util.PhotoUtils.java

/**
 * Get an Intent to select a photo from the gallery.
 *
 * @return Get content Intent/*  www  . ja v a  2  s .c  o m*/
 */
@NonNull
public static Intent getSelectPhotoIntent() {
    final Intent intent;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
    } else {
        intent = new Intent(Intent.ACTION_GET_CONTENT);
    }
    intent.setType("image/*");
    return intent;
}

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

/** Opens the storage browser on Android 4.4 or later for opening a file */
@TargetApi(Build.VERSION_CODES.KITKAT)//from   ww w .  j  av a2 s .c  o m
private static void openDocumentKitKat(Fragment fragment, String mimeType, boolean multiple, int requestCode) {
    Intent intent = new Intent(Intent.ACTION_OPEN_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_ALLOW_MULTIPLE, multiple);

    fragment.startActivityForResult(intent, requestCode);
}

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();/* ww w  .j  ava  2  s  .c  om*/
        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  w w. j a v a  2  s .  c  om*/
        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: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//from  www .  j a v  a2s  . c o  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.uphyca.kitkat.storage.ui.MainFragment.java

/**
 * ?//from w  ww  . j  a v a 2s  .com
 */
@OnClick(R.id.button_edit)
void onEditButtonClick() {
    Intent intent = new Intent().setAction(Intent.ACTION_OPEN_DOCUMENT).addCategory(Intent.CATEGORY_OPENABLE)
            .setType("text/plain");
    startActivityForResult(intent, REQUEST_EDIT);
}