List of usage examples for android.content Intent ACTION_OPEN_DOCUMENT
String ACTION_OPEN_DOCUMENT
To view the source code for android.content Intent ACTION_OPEN_DOCUMENT.
Click Source Link
From source file:cn.edu.wyu.documentviewer.DocumentsActivity.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); mRoots = DocumentsApplication.getRootsCache(this); virtualIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT); virtualIntent.addCategory(Intent.CATEGORY_OPENABLE); virtualIntent.setType("*/*"); virtualIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); setResult(Activity.RESULT_CANCELED); setContentView(R.layout.activity);/* ww w.ja v a 2s . co m*/ final Resources res = getResources(); mShowAsDialog = res.getBoolean(R.bool.show_as_dialog); if (mShowAsDialog) { // backgroundDimAmount from theme isn't applied; do it manually final WindowManager.LayoutParams a = getWindow().getAttributes(); a.dimAmount = 0.6f; getWindow().setAttributes(a); getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); getWindow().setFlags(~0, WindowManager.LayoutParams.FLAG_DIM_BEHIND); // Inset ourselves to look like a dialog final Point size = new Point(); getWindowManager().getDefaultDisplay().getSize(size); final int width = (int) res.getFraction(R.dimen.dialog_width, size.x, size.x); final int height = (int) res.getFraction(R.dimen.dialog_height, size.y, size.y); final int insetX = (size.x - width) / 2; final int insetY = (size.y - height) / 2; final Drawable before = getWindow().getDecorView().getBackground(); final Drawable after = new InsetDrawable(before, insetX, insetY, insetX, insetY); getWindow().getDecorView().setBackground(after); // Dismiss when touch down in the dimmed inset area getWindow().getDecorView().setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { final float x = event.getX(); final float y = event.getY(); if (x < insetX || x > v.getWidth() - insetX || y < insetY || y > v.getHeight() - insetY) { finish(); return true; } } return false; } }); } else { // Non-dialog means we have a drawer mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer_glyph, R.string.drawer_open, R.string.drawer_close); mDrawerLayout.setDrawerListener(mDrawerListener); mDrawerLayout.setDrawerShadow(R.drawable.ic_drawer_shadow, GravityCompat.START); mRootsContainer = findViewById(R.id.container_roots); } mDirectoryContainer = (DirectoryContainerView) findViewById(R.id.container_directory); if (icicle != null) { mState = icicle.getParcelable(EXTRA_STATE); } else { if (DEBUG) { Log.i(TAG, "mState"); } buildDefaultState(); } // Hide roots when we're managing a specific root if (mState.action == ACTION_MANAGE) { if (mShowAsDialog) { findViewById(R.id.dialog_roots).setVisibility(View.GONE); } else { mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); } } if (mState.action == ACTION_CREATE) { final String mimeType = virtualIntent.getType(); final String title = virtualIntent.getStringExtra(Intent.EXTRA_TITLE); SaveFragment.show(getFragmentManager(), mimeType, title); } if (mState.action == ACTION_GET_CONTENT) { final Intent moreApps = new Intent(virtualIntent); moreApps.setComponent(null); moreApps.setPackage(null); RootsFragment.show(getFragmentManager(), moreApps); } else if (mState.action == ACTION_OPEN || mState.action == ACTION_CREATE) { RootsFragment.show(getFragmentManager(), null); } if (!mState.restored) { if (mState.action == ACTION_MANAGE) { final Uri rootUri = virtualIntent.getData(); new RestoreRootTask(rootUri).executeOnExecutor(getCurrentExecutor()); } else { new RestoreStackTask().execute(); } } else { onCurrentDirectoryChanged(ANIM_NONE); } }
From source file:org.odk.collect.android.widgets.ArbitraryFileWidget.java
private void performFileSearch() { Intent intent = new Intent(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT ? Intent.ACTION_OPEN_DOCUMENT : Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("*/*"); // all file types ((FormEntryActivity) getContext()).startActivityForResult(intent, ApplicationConstants.RequestCodes.ARBITRARY_FILE_CHOOSER); }
From source file:org.sufficientlysecure.keychain.util.FileHelper.java
/** * Does the device actually have a ACTION_OPEN_DOCUMENT Intent? Looks like some Android * distributions are missing the ACTION_OPEN_DOCUMENT Intent even on Android 4.4, * see https://github.com/open-keychain/open-keychain/issues/1625 * * @return True, if the device supports ACTION_OPEN_DOCUMENT. False, otherwise. *//*from www.j a va 2s .c om*/ @TargetApi(VERSION_CODES.KITKAT) private static boolean hasOpenDocumentIntent(Context context) { if (hasOpenDocumentIntent == null) { PackageManager packageManager = context.getPackageManager(); List<ResolveInfo> resolveInfoList = packageManager .queryIntentActivities(new Intent(Intent.ACTION_OPEN_DOCUMENT), 0); hasOpenDocumentIntent = !resolveInfoList.isEmpty(); } return hasOpenDocumentIntent; }
From source file:com.uphyca.kitkat.storage.ui.MainFragment.java
/** * ?/*from w w w . j a v a 2s .co m*/ */ @OnClick(R.id.button_delete) void onDeleteButtonClick() { Intent intent = new Intent().setAction(Intent.ACTION_OPEN_DOCUMENT).addCategory(Intent.CATEGORY_OPENABLE) .setType("text/plain"); startActivityForResult(intent, REQUEST_DELETE); }
From source file:com.farmerbb.notepad.fragment.WelcomeFragment.java
@TargetApi(Build.VERSION_CODES.KITKAT) @Override//from w w w . j a v a 2 s. c o m public boolean onOptionsItemSelected(MenuItem item) { // Handle presses on the action bar items switch (item.getItemId()) { 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, 42); } 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); } }
From source file:com.activiti.android.platform.provider.transfer.ContentTransferManager.java
public static final void requestGetContentFromProvider(Fragment fr) { String tmpMimetype = "*/*"; if (AndroidVersion.isKitKatOrAbove()) { isMediaProviderSupported(fr.getActivity()); Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType(tmpMimetype);//w w w.java2 s. co m fr.startActivityForResult(intent, PICKER_REQUEST_CODE); } }
From source file:com.amaze.filemanager.ui.views.drawer.Drawer.java
public Drawer(MainActivity mainActivity) { this.mainActivity = mainActivity; resources = mainActivity.getResources(); dataUtils = DataUtils.getInstance(); drawerHeaderLayout = mainActivity.getLayoutInflater().inflate(R.layout.drawerheader, null); drawerHeaderParent = drawerHeaderLayout.findViewById(R.id.drawer_header_parent); drawerHeaderView = drawerHeaderLayout.findViewById(R.id.drawer_header); drawerHeaderView.setOnLongClickListener(v -> { Intent intent1;/*from ww w.ja v a 2 s. co m*/ if (SDK_INT < Build.VERSION_CODES.KITKAT) { intent1 = new Intent(); intent1.setAction(Intent.ACTION_GET_CONTENT); } else { intent1 = new Intent(Intent.ACTION_OPEN_DOCUMENT); } intent1.addCategory(Intent.CATEGORY_OPENABLE); intent1.setType("image/*"); mainActivity.startActivityForResult(intent1, image_selector_request_code); return false; }); mImageLoader = AppConfig.getInstance().getImageLoader(); navView = mainActivity.findViewById(R.id.navigation); //set width of drawer in portrait to follow material guidelines /*if(!Utils.isDeviceInLandScape(mainActivity)){ setNavViewDimension(navView); }*/ navView.setNavigationItemSelectedListener(this); int accentColor = mainActivity.getAccent(), idleColor; if (mainActivity.getAppTheme().equals(AppTheme.LIGHT)) { idleColor = mainActivity.getResources().getColor(R.color.item_light_theme); } else { idleColor = Color.WHITE; } actionViewStateManager = new ActionViewStateManager(navView, idleColor, accentColor); ColorStateList drawerColors = new ColorStateList( new int[][] { new int[] { android.R.attr.state_checked }, new int[] { android.R.attr.state_enabled }, new int[] { android.R.attr.state_pressed }, new int[] { android.R.attr.state_focused }, new int[] { android.R.attr.state_pressed } }, new int[] { accentColor, idleColor, idleColor, idleColor, idleColor }); navView.setItemTextColor(drawerColors); navView.setItemIconTintList(drawerColors); if (mainActivity.getAppTheme().equals(AppTheme.DARK)) { navView.setBackgroundColor(Utils.getColor(mainActivity, R.color.holo_dark_background)); } else if (mainActivity.getAppTheme().equals(AppTheme.BLACK)) { navView.setBackgroundColor(Utils.getColor(mainActivity, android.R.color.black)); } else { navView.setBackgroundColor(Color.WHITE); } mDrawerLayout = mainActivity.findViewById(R.id.drawer_layout); //mDrawerLayout.setStatusBarBackgroundColor(Color.parseColor((currentTab==1 ? skinTwo : skin))); drawerHeaderView.setBackgroundResource(R.drawable.amaze_header); //drawerHeaderParent.setBackgroundColor(Color.parseColor((currentTab==1 ? skinTwo : skin))); if (mainActivity.findViewById(R.id.tab_frame) != null) { lock(DrawerLayout.LOCK_MODE_LOCKED_OPEN); open(); mDrawerLayout.setScrimColor(Color.TRANSPARENT); mDrawerLayout.post(this::open); } else if (mainActivity.findViewById(R.id.tab_frame) == null) { unlock(); close(); mDrawerLayout.post(this::close); } navView.addHeaderView(drawerHeaderLayout); if (!isDrawerLocked) { mDrawerToggle = new ActionBarDrawerToggle(mainActivity, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer_l, /* nav drawer image to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { Drawer.this.onDrawerClosed(); } public void onDrawerOpened(View drawerView) { //title.setText("Amaze File Manager"); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.setDrawerListener(mDrawerToggle); mainActivity.getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_drawer_l); mainActivity.getSupportActionBar().setDisplayHomeAsUpEnabled(true); mainActivity.getSupportActionBar().setHomeButtonEnabled(true); mDrawerToggle.syncState(); } }
From source file:com.google.firebase.quickstart.firebasestorage.java.MainActivity.java
private void launchCamera() { Log.d(TAG, "launchCamera"); // Pick an image from storage Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.setType("image/*"); startActivityForResult(intent, RC_TAKE_PICTURE); }
From source file:org.fedorahosted.freeotp.MainActivity.java
/** * Fires an intent to spin up the "file chooser" UI and select an image. */// w ww .ja va 2 s. c o m public void performFileSearch() { // ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's file // browser. Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); // 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); // Filter to show only images, using the image MIME data type. // If one wanted to search for ogg vorbis files, the type would be "audio/ogg". // To search for all documents available via installed storage providers, // it would be "*/*". intent.setType("application/json"); startActivityForResult(intent, READ_REQUEST_CODE); }