Java Code Examples for android.content.Intent#ACTION_OPEN_DOCUMENT

The following examples show how to use android.content.Intent#ACTION_OPEN_DOCUMENT . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 */
private boolean importThemes( Context context )
{
    if (context != null)
    {
        if (isImporting || isExporting) {
            Log.e("importThemes","Busy! Already importing/exporting.. ignoring request");
            return false;

        } else {
            Intent intent = new Intent((Build.VERSION.SDK_INT >= 19 ? Intent.ACTION_OPEN_DOCUMENT : Intent.ACTION_GET_CONTENT));
            intent.setType("text/*");
            startActivityForResult(intent, IMPORT_REQUEST);
            return true;
        }
    }
    return false;
}
 
Example 2
Source Project: GetApk   File: MainActivity.java    License: MIT License 7 votes vote down vote up
@Override
public boolean onMenuItemClick(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.apk:
            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.setType("application/vnd.android.package-archive");
            startActivityForResult(intent, REQUEST_READ_APK);
            break;
        case R.id.sort:
            mIsSortByTime = !mIsSortByTime;
            item.setIcon(mIsSortByTime ? R.drawable.ic_a_white_24dp : R.drawable.ic_timer_white_24dp);
            mRefreshView.setRefreshing(true);
            mToolbar.getMenu().getItem(1).setEnabled(false);
            mDisposables.add(mPresenter.getAndSort(this, mIsSortByTime));
            break;
    }

    return true;
}
 
Example 3
@Override
public void onClick(View v) {
	switch (v.getId()) {
		case R.id.reset_icon:
			File customIconFile = MyCache.getCustomIconFile(this, component);
			customIconFile.delete();
			Toast.makeText(ChangeIconActivity.this, "The custom icon was deleted", Toast.LENGTH_LONG).show();
			((Button)findViewById(R.id.reset_icon)).setEnabled(false);
			break;
		case R.id.choose_icon_from_memory:
			if (Build.VERSION.SDK_INT >= 19) {
				Intent customIconIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
				customIconIntent.addCategory(Intent.CATEGORY_OPENABLE);
				customIconIntent.setType("image/png");
				startActivityForResult(customIconIntent, 0);
			} else {
				Intent intent = new Intent(this, FileActivity.class);
				startActivityForResult(intent, FileActivity.GET_IMAGE);
			}
			break;
	}
}
 
Example 4
public void folderImageButtonClick() {
    if (Pref.getString(PREF_numberwall_background, null) == null) {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
            if (SdcardImportExport.checkPermissions(activity, true, ASK_FILE_PERMISSION)) {
                final Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
                intent.addCategory(Intent.CATEGORY_OPENABLE);
                intent.setType("image/*");
                startActivityForResult(intent, LOAD_IMAGE_RESULTS);
            } else {
                if (JoH.ratelimit("need-file-permission",10)) {
                    //JoH.static_toast_short("Need file permission");
                }
            }
        }
    } else {
        binding.getSprefs().put(PREF_numberwall_background, null);
        refreshBitmap();
    }
}
 
Example 5
Source Project: SimpleCropView   File: RxFragment.java    License: MIT License 5 votes vote down vote up
public void pickImage() {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
    startActivityForResult(new Intent(Intent.ACTION_GET_CONTENT).setType("image/*"),
        REQUEST_PICK_IMAGE);
  } else {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("image/*");
    startActivityForResult(intent, REQUEST_SAF_PICK_IMAGE);
  }
}
 
Example 6
public void openDocument() {
	Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
	intent.addCategory(Intent.CATEGORY_OPENABLE);
	intent.setType(MIME_TYPE);
	intent.putExtra(EXTRA_SHOW_ADVANCED, true);

	this.getActionHandler().callStartActivityForResult(intent, new TGSafOpenHandler(this));
}
 
Example 7
Source Project: AndroidBase   File: GetPhotoUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 4.4以上版本使用
 * @see "http://blog.csdn.net/tempersitu/article/details/20557383"
 * 
 * @param activity
 * @param requestCode
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
public static void choicePicFromAlbum_kitkat(Activity activity, int requestCode) {
    // 来自相册
    Intent albumIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    albumIntent.addCategory(Intent.CATEGORY_OPENABLE);
    albumIntent.setType("image/*");
    activity.startActivityForResult(albumIntent, requestCode);
}
 
Example 8
Source Project: DevUtils   File: IntentUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 获取存储访问框架的意图
 * @param type 跳转类型
 * @return 存储访问框架的意图
 */
public static Intent getOpenDocumentIntent(final String type) {
    try {
        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType(type);
        return intent;
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "getOpenDocumentIntent");
    }
    return null;
}
 
Example 9
Source Project: SimpleCropView   File: BasicFragment.java    License: MIT License 5 votes vote down vote up
@NeedsPermission(Manifest.permission.READ_EXTERNAL_STORAGE) public void pickImage() {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
    startActivityForResult(new Intent(Intent.ACTION_GET_CONTENT).setType("image/*"),
        REQUEST_PICK_IMAGE);
  } else {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("image/*");
    startActivityForResult(intent, REQUEST_SAF_PICK_IMAGE);
  }
}
 
Example 10
/**
 * Get the Intent for selecting content to be used in an Intent Chooser.
 *
 * @return The intent for opening a file with Intent.createChooser()
 * @author paulburke
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
private static Intent createGetMultipleContentIntent(String mimeType) {
    // Implicitly allow the user to select a particular kind of data
    final Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    // The MIME data type filter
    intent.setType(mimeType);
    // EXTRA_ALLOW_MULTIPLE: added in API level 18
    intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
    // Only return URIs that can be opened with ContentResolver
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    return intent;
}
 
Example 11
Source Project: NonViewUtils   File: GetPhotoUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 4.4以上版本使用
 * @see "http://blog.csdn.net/tempersitu/article/details/20557383"
 * 
 * @param activity
 * @param requestCode
 */
public static void choicePicFromAlbum_kitkat(Activity activity, int requestCode) {
    // 来自相册
    Intent albumIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    albumIntent.addCategory(Intent.CATEGORY_OPENABLE);
    albumIntent.setType("image/*");
    activity.startActivityForResult(albumIntent, requestCode);
}
 
Example 12
public static Intent pickFile(boolean onlyImages) {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    if (onlyImages) {
        intent.setType("image/*");
    } else {
        intent.setType("*/*");
    }
    intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    return Intent.createChooser(intent, "Select file");
}
 
Example 13
Source Project: Notepad   File: NoteListFragment.java    License: Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle presses on the action bar items
    switch(item.getItemId()) {
        case R.id.action_start_selection:
            listener.startMultiSelect();
            return true;
        case R.id.action_settings:
            Intent intentSettings = new Intent(getActivity(), SettingsActivity.class);
            startActivity(intentSettings);
            return true;
        case R.id.action_import:
            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
            intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] {"text/plain", "text/html", "text/x-markdown"});
            intent.setType("*/*");

            try {
                getActivity().startActivityForResult(intent, MainActivity.IMPORT);
            } catch (ActivityNotFoundException e) {
                showToast(R.string.error_importing_notes);
            }
            return true;
        case R.id.action_about:
            DialogFragment aboutFragment = new AboutDialogFragment();
            aboutFragment.show(getFragmentManager(), "about");
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example 14
/**
 * 获取导入规则列表的 SAF (Storage Access Framework) 的 Intent
 */
public static Intent getImportRuleListSAFIntent() {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType(BACKUP_MIME_TYPE);
    intent.putExtra(Intent.EXTRA_TITLE, getDefaultBackupFilename());

    return intent;
}
 
Example 15
Source Project: slide   File: StorageController.java    License: MIT License 4 votes vote down vote up
private void pickImage(Activity a) {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("image/*");
    a.startActivityForResult(intent, PICK_IMAGE_REQUEST_CODE);
}
 
Example 16
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.main_menu_freeze_all:
            // This is the same as clicking on the batch freeze shortcut
            // so we just forward the request to DummyActivity
            Intent intent = new Intent(DummyActivity.PUBLIC_FREEZE_ALL);
            intent.setComponent(new ComponentName(this, DummyActivity.class));
            startActivity(intent);
            return true;
        case R.id.main_menu_settings:
            Intent settingsIntent = new Intent(this, SettingsActivity.class);
            Bundle extras = new Bundle();
            extras.putBinder("profile_service", mServiceWork.asBinder());
            settingsIntent.putExtra("extras", extras);
            startActivity(settingsIntent);
            return true;
        case R.id.main_menu_create_freeze_all_shortcut:
            Intent launchIntent = new Intent(DummyActivity.PUBLIC_FREEZE_ALL);
            launchIntent.setComponent(new ComponentName(this, DummyActivity.class));
            launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            Utility.createLauncherShortcut(this, launchIntent,
                    Icon.createWithResource(this, R.mipmap.ic_freeze),
                    "shelter-freeze-all", getString(R.string.freeze_all_shortcut));
            return true;
        case R.id.main_menu_install_app_to_profile:
            Intent openApkIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
            openApkIntent.addCategory(Intent.CATEGORY_OPENABLE);
            openApkIntent.setType("application/vnd.android.package-archive");
            startActivityForResult(openApkIntent, REQUEST_DOCUMENTS_CHOOSE_APK);
            return true;
        case R.id.main_menu_show_all:
            Runnable update = () -> {
                mShowAll = !item.isChecked();
                item.setChecked(mShowAll);
                LocalBroadcastManager.getInstance(this)
                        .sendBroadcast(new Intent(AppListFragment.BROADCAST_REFRESH));
            };

            if (!item.isChecked()) {
                new AlertDialog.Builder(this)
                        .setMessage(R.string.show_all_warning)
                        .setPositiveButton(R.string.first_run_alert_continue,
                                (dialog, which) -> update.run())
                        .setNegativeButton(R.string.first_run_alert_cancel, null)
                        .show();
            } else {
                update.run();
            }
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 17
Source Project: openalpr-android   File: MainActivity.java    License: Apache License 2.0 4 votes vote down vote up
public void loadPicture() {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("image/*");
    startActivityForResult(intent, REQUEST_FILE);
}
 
Example 18
private void importNotebook(){
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);

    intent.addCategory(Intent.CATEGORY_OPENABLE);

    intent.setType("application/zip");

    startActivityForResult(intent, Utils.READ_REQUEST_CODE);
}
 
Example 19
@Override
public void onClick(View v) {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);

    intent.addCategory(Intent.CATEGORY_OPENABLE);

    intent.setType("*/*");

    startActivityForResult(intent, Utils.READ_REQUEST_CODE);
}
 
Example 20
Source Project: libcommon   File: SAFSingleFileUtils.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * ファイル読み込み用のUriを要求するヘルパーメソッド
 * KITKAT以降で個別のファイル毎にパーミッション要求する場合
 * @param mime
 * @return
 */
private static Intent prepareOpenDocumentIntent(@NonNull final String mime) {
	final Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
	intent.setType(mime);
	return intent;
}