Example usage for android.content Intent CATEGORY_OPENABLE

List of usage examples for android.content Intent CATEGORY_OPENABLE

Introduction

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

Prototype

String CATEGORY_OPENABLE

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

Click Source Link

Document

Used to indicate that an intent only wants URIs that can be opened with ContentResolver#openFileDescriptor(Uri,String) .

Usage

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/*  www  .  ja va 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.uphyca.kitkat.storage.ui.MainFragment.java

/**
 * ?//w  w  w . j  a v  a  2  s  . c  om
 */
@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.github.jokar.rxupload.MainActivity.java

public void selectFile(View view) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("*/*");//????
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    startActivityForResult(intent, RESULT_SELECT_FILE);
}

From source file:cx.ring.fragments.MediaPreferenceFragment.java

public void performFileSearch(int requestCodeToSet) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("audio/*");
    startActivityForResult(intent, requestCodeToSet);
}

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

/**
 * ??/*from ww w .j a  v  a 2s .  c o 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.ultramegasoft.flavordex2.util.PhotoUtils.java

/**
 * Get an Intent to select a photo from the gallery.
 *
 * @return Get content Intent/* w  w w  .j ava2  s  .co 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:com.narkii.security.info.LicenseInfoFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onActivityCreated(savedInstanceState);

    fileButton = (Button) view.findViewById(R.id.button_add_local);
    captureButton = (Button) view.findViewById(R.id.button_add_capture);
    uploadButton = (Button) view.findViewById(R.id.button_upload);
    previewImage = (ImageView) view.findViewById(R.id.image_preview);
    gridView = (GridView) view.findViewById(R.id.image_uploaded);
    fileName = (EditText) view.findViewById(R.id.text_file_name);

    gridViewAdapter = new GridViewAdapter(getActivity(), null, false);
    gridView.setAdapter(gridViewAdapter);

    captureButton.setOnClickListener(new OnClickListener() {

        @Override//  w  w w . ja  v  a  2 s  .  com
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            fileUri = MediaFileStorage.getOutputMediaFileUri(MediaFileStorage.MEDIA_TYPE_IMAGE);
            Log.d(TAG, fileUri.toString());
            Log.d(TAG, fileUri.getPath());
            i.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
            getParentFragment().startActivityForResult(i, Constants.CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
        }
    });

    fileButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent();
            intent.setType("*/*"); //("image/*")
            intent.setAction(Intent.ACTION_GET_CONTENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            //FragmentFragmentFragmentFragmentResultFragment
            getParentFragment().startActivityForResult(intent, Constants.CONTENT_GET_ACTIVITY_REQUEST_CODE);
        }
    });
    uploadButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if (preBitmap != null && !fileName.getText().toString().equals("")) {
                //
                new Thread(new Runnable() {

                    @Override
                    public void run() {
                        // TODO Auto-generated method stub
                        DbOperations operations = DbOperations.getInstance(getActivity());
                        ContentValues values = new ContentValues();
                        values.put(Permission.COLUMN_FK_ENTERPRISE_ID,
                                getArguments().getLong("enterpriseId", 0));
                        Log.d(TAG, "storage file:" + fileUri.toString());
                        Log.d(TAG, "storage file:" + fileUri.getPath());
                        values.put(Permission.COLUMN_URL, fileUri.toString());
                        values.put(Permission.COLUMN_CERTIFICATE_NAME, fileName.getText().toString());
                        if (isImage)
                            values.put(Permission.COLUMN_TYPE, 1);
                        else
                            values.put(Permission.COLUMN_TYPE, 2);
                        long result = operations.insert(Permission.TABLE_NAME, values);
                        if (result > 0) {
                            Message msg = new Message();
                            msg.what = Constants.INSERT_UPLOADED_OK_MSG;
                            handler.sendMessage(msg);
                        }
                    }
                }).start();
            } else {
                Toast.makeText(getActivity(), "please select file and input name", Toast.LENGTH_LONG).show();
            }
        }
    });

    long id = getArguments().getLong("enterpriseId", 0);
    Bundle bundle = new Bundle();
    bundle.putLong("id", id);
    getLoaderManager().initLoader(Constants.PERMISSION_IMAGE_ID, bundle, this);
}

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)//w  w w  .j  a v a 2s.  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.trigger_context.conf.Set_File_Select.java

private void showFileChooser() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("*/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    try {//from w ww  .  j a  v  a 2  s  .  c o m
        startActivityForResult(Intent.createChooser(intent, "Select a File to Upload"), FILE_SELECT_CODE);
    } catch (android.content.ActivityNotFoundException ex) {
        // Potentially direct the user to the Market with a Dialog
        Toast.makeText(this, "Please install a File Manager.", Toast.LENGTH_SHORT).show();
    }
}

From source file:java_lang_programming.com.android_media_demo.article94.java.ImageDecoderActivity.java

/**
 * start ExternalApps if the required READ_EXTERNAL_STORAGE permission has been granted.
 *//*from  w ww  .j av a 2  s .  c  om*/
private void startExternalAppSelectableImage() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);

    // 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);
    intent.setType("image/*");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        intent.putExtra(Intent.EXTRA_MIME_TYPES, types.toArray());
    }
    startActivityForResult(Intent.createChooser(intent, null), ImageSelectionDemoActivity.REQUEST_CODE_CHOOSER);
}