Example usage for android.content Intent ACTION_GET_CONTENT

List of usage examples for android.content Intent ACTION_GET_CONTENT

Introduction

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

Prototype

String ACTION_GET_CONTENT

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

Click Source Link

Document

Activity Action: Allow the user to select a particular kind of data and return it.

Usage

From source file:com.color.kid.kidpaint.activity.OptionsActivity.java

private void startLoadImageIntent() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    startActivityForResult(intent, REQUEST_CODE_LOAD_PICTURE);
}

From source file:com.chess.genesis.activity.GameListLocalFrag.java

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
    case R.id.new_game:
        new NewLocalGameDialog(act, handle).show();
        break;//from   w w  w  . ja v  a2  s .  c o  m
    case R.id.import_game:
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent = intent.addCategory(Intent.CATEGORY_OPENABLE).setType("text/*");
        intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
        try {
            startActivityForResult(intent, Enums.IMPORT_GAME);
        } catch (final ActivityNotFoundException e) {
            Toast.makeText(act, "No File Manager Installed", Toast.LENGTH_LONG).show();
        }
        break;
    default:
        return super.onOptionsItemSelected(item);
    }
    return true;
}

From source file:mobisocial.musubi.ui.fragments.ChooseImageDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    return new AlertDialog.Builder(getActivity()).setTitle("Choose an Image...")
            .setItems(new String[] { "From Camera", "From Gallery" }, new DialogInterface.OnClickListener() {
                @SuppressWarnings("deprecation")
                @Override//from w  w  w . j a v  a  2s .  c  o  m
                public void onClick(DialogInterface dialog, int which) {
                    switch (which) {
                    case 0:
                        final Activity activity = getActivity();
                        Toast.makeText(activity, "Loading camera...", Toast.LENGTH_SHORT).show();
                        ((InstrumentedActivity) activity)
                                .doActivityForResult(new PhotoTaker(activity, new PhotoTaker.ResultHandler() {
                                    @Override
                                    public void onResult(Uri imageUri) {
                                        Log.d(getClass().getSimpleName(), "Updating thumbnail...");

                                        try {
                                            UriImage image = new UriImage(activity, imageUri);
                                            byte[] data = image.getResizedImageData(512, 512,
                                                    PictureObj.MAX_IMAGE_SIZE / 2);
                                            // profile
                                            Bitmap sourceBitmap = BitmapFactory.decodeByteArray(data, 0,
                                                    data.length);
                                            int width = sourceBitmap.getWidth();
                                            int height = sourceBitmap.getHeight();
                                            int cropSize = Math.min(width, height);
                                            Bitmap cropped = Bitmap.createBitmap(sourceBitmap, 0, 0, cropSize,
                                                    cropSize);
                                            ByteArrayOutputStream baos = new ByteArrayOutputStream();
                                            cropped.compress(Bitmap.CompressFormat.JPEG, 90, baos);
                                            cropped.recycle();
                                            sourceBitmap.recycle();

                                            Bundle bundle = new Bundle();
                                            bundle.putByteArray(EXTRA_THUMBNAIL, baos.toByteArray());
                                            Intent res = new Intent();
                                            res.putExtras(bundle);
                                            getTargetFragment().onActivityResult(REQUEST_PROFILE_PICTURE,
                                                    Activity.RESULT_OK, res);
                                        } catch (Throwable t) {
                                            Log.e("ViewProfile", "failed to generate thumbnail of profile", t);
                                            Toast.makeText(activity,
                                                    "Profile picture capture failed.  Try again.",
                                                    Toast.LENGTH_SHORT).show();
                                        }
                                    }
                                }, 200, false));
                        break;
                    case 1:
                        Intent gallery = new Intent(Intent.ACTION_GET_CONTENT);
                        gallery.setType("image/*");
                        // god damn fragments.
                        getTargetFragment().startActivityForResult(Intent.createChooser(gallery, null),
                                REQUEST_GALLERY_THUMBNAIL);
                        break;
                    }
                }
            }).create();
}

From source file:com.stephenmcgruer.threethingstoday.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.mi_export_database:
        new DatabaseExportTask(this, mThreeThingsDatabase).execute();
        return true;
    case R.id.mi_import_database:
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("*/*");
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        try {//w  w w. j  a  va2 s  .  c  o m
            startActivityForResult(Intent.createChooser(intent, "Select a file to open"), DATABASE_IMPORT_CODE);
        } catch (ActivityNotFoundException e) {
            Toast.makeText(getApplicationContext(), "Please install a File Manager", Toast.LENGTH_LONG).show();
        }
        return true;
    case R.id.mi_sign_in_sign_out:
        if (FirebaseAuth.getInstance().getCurrentUser() == null) {
            Intent signInIntent = AuthUI.getInstance().createSignInIntentBuilder()
                    .setProviders(Arrays.asList(new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build()))
                    .build();
            startActivityForResult(signInIntent, FIREBASE_SIGN_IN_CODE);
        } else {
            FirebaseAuth.getInstance().signOut();
            Toast.makeText(this, "Signed out", Toast.LENGTH_SHORT).show();
        }
        return true;
    case R.id.mi_test_notification:
        Intent notificationIntent = new Intent(this, NotificationIntentService.class);
        startService(notificationIntent);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:cc.metapro.openct.allclasses.ExcelDialog.java

private void showFilerChooser() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("*/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    try {//from   ww w  . java  2s.c  o  m
        startActivityForResult(Intent.createChooser(intent, getString(R.string.select_schedule_file)),
                FILE_SELECT_CODE);
    } catch (ActivityNotFoundException ex) {
        Toast.makeText(getActivity(), R.string.fail_file_chooser, Toast.LENGTH_LONG).show();
    }
}

From source file:ca.psiphon.ploggy.FragmentComposeMessage.java

private void selectPicture() {
    Intent intent;//  ww  w .j  a  v  a2s .  c o m
    if (Build.VERSION.SDK_INT < 19) {
        intent = new Intent(Intent.ACTION_GET_CONTENT);
    } else {
        // TODO: properly support the new Storage Access Framework invoked for
        // Intent.ACTION_GET_CONTENT on KitKat:
        // https://developer.android.com/guide/topics/providers/document-provider.html
        // This includes getting results from cloud providers such as
        // Drive -- which are only available as streams, not files.
        // For now, forcing the equivilent of pre-KitKat gallery selection...
        intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    }
    intent.setType("image/*");
    // Note: assumes nested fragment
    getParentFragment().startActivityForResult(
            Intent.createChooser(intent, getText(R.string.prompt_compose_message_select_picture)),
            REQUEST_CODE_SELECT_IMAGE);
}

From source file:itkach.aard2.SettingsListAdapter.java

private View getUserStylesView(View convertView, final ViewGroup parent) {
    View view;/*from  www.ja  v  a2  s  .c o  m*/
    LayoutInflater inflater = (LayoutInflater) parent.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    if (convertView != null) {
        view = convertView;
    } else {
        this.userStyleData = userStylePrefs.getAll();
        this.userStyleNames = new ArrayList<String>(this.userStyleData.keySet());
        Collections.sort(this.userStyleNames);

        view = inflater.inflate(R.layout.settings_user_styles_item, parent, false);
        ImageView btnAdd = (ImageView) view.findViewById(R.id.setting_btn_add_user_style);
        btnAdd.setImageDrawable(FontIconDrawable.inflate(context, R.xml.ic_list_add));
        btnAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_GET_CONTENT);
                intent.setType("text/*");
                Intent chooser = Intent.createChooser(intent, "Select CSS file");
                try {
                    fragment.startActivityForResult(chooser, CSS_SELECT_REQUEST);
                } catch (ActivityNotFoundException e) {
                    Log.d(TAG, "Not activity to get content", e);
                    Toast.makeText(context, R.string.msg_no_activity_to_get_content, Toast.LENGTH_LONG).show();
                }
            }
        });
    }
    ;

    View emptyView = view.findViewById(R.id.setting_user_styles_empty);
    emptyView.setVisibility(userStyleNames.size() == 0 ? View.VISIBLE : View.GONE);

    LinearLayout userStyleListLayout = (LinearLayout) view.findViewById(R.id.setting_user_styles_list);
    userStyleListLayout.removeAllViews();
    for (int i = 0; i < userStyleNames.size(); i++) {
        View styleItemView = inflater.inflate(R.layout.user_styles_list_item, parent, false);
        ImageView btnDelete = (ImageView) styleItemView.findViewById(R.id.user_styles_list_btn_delete);
        btnDelete.setImageDrawable(FontIconDrawable.inflate(context, R.xml.ic_list_trash));
        btnDelete.setOnClickListener(onDeleteUserStyle);

        String name = userStyleNames.get(i);

        btnDelete.setTag(name);

        TextView nameView = (TextView) styleItemView.findViewById(R.id.user_styles_list_name);
        nameView.setText(name);

        userStyleListLayout.addView(styleItemView);
    }

    return view;
}

From source file:com.microsoft.projectoxford.visionsample.helper.SelectImageActivity.java

public void selectImageInAlbum(View view) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("mFilePhotoTaken/*");
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(intent, REQUEST_SELECT_IMAGE_IN_ALBUM);
    }//from  w w w.j a v  a 2 s.co  m
}

From source file:com.pacoapp.paco.ui.FindExperimentsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.debug("FindExperimentsActivity onCreate");
    mainLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.find_experiments, null);
    setContentView(mainLayout);/*w  w w . j a  va  2  s .c  o m*/

    ActionBar actionBar = getSupportActionBar();
    actionBar.setLogo(R.drawable.ic_launcher);
    actionBar.setDisplayUseLogoEnabled(true);
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setBackgroundDrawable(new ColorDrawable(0xff4A53B3));
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Set up the drawer.
    //    mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
    //    mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));

    Intent intent = getIntent();

    userPrefs = new UserPreferences(this);
    list = (ListView) findViewById(R.id.find_experiments_list);
    //    createListHeader();
    //    createRefreshHeader();

    experimentProviderUtil = new ExperimentProviderUtil(this);

    progressBar = (ProgressBar) findViewById(R.id.findExperimentsProgressBar);

    reloadAdapter();
    list.setItemsCanFocus(true);
    list.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> listview, View textview, int position, long id) {
            Experiment experiment = experiments.get(position);
            getIntent().putExtra(Experiment.EXPERIMENT_SERVER_ID_EXTRA_KEY, experiment.getServerId());

            String action = getIntent().getAction();
            if (Intent.ACTION_PICK.equals(action) || Intent.ACTION_GET_CONTENT.equals(action)) {
                // The caller is waiting for us to return an experiment selected by
                // the user. The have clicked on one, so return it now.
                Intent resultIntent = new Intent();
                resultIntent.putExtra(Experiment.EXPERIMENT_SERVER_ID_EXTRA_KEY, experiment.getServerId());
                setResult(RESULT_OK, resultIntent);
            } else {
                Intent experimentIntent = new Intent(FindExperimentsActivity.this,
                        ExperimentDetailActivity.class);
                experimentIntent.putExtra(Experiment.EXPERIMENT_SERVER_ID_EXTRA_KEY, experiment.getServerId());
                experimentIntent.putExtra(ExperimentDetailActivity.ID_FROM_MY_EXPERIMENTS_FILE, false);
                startActivityForResult(experimentIntent, JOIN_REQUEST_CODE);
            }
        }
    });
    registerForContextMenu(list);
}

From source file:com.codebutler.farebot.fragments.CardsFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    try {/*from   w  w  w . ja va2 s . c o m*/
        if (item.getItemId() == R.id.import_clipboard) {
            @SuppressWarnings("deprecation")
            ClipboardManager clipboard = (ClipboardManager) getActivity()
                    .getSystemService(Activity.CLIPBOARD_SERVICE);
            onCardsImported(ExportHelper.importCardsXml(getActivity(), clipboard.getText().toString()));
            return true;

        } else if (item.getItemId() == R.id.import_file) {
            Uri uri = Uri.fromFile(Environment.getExternalStorageDirectory());
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.putExtra(Intent.EXTRA_STREAM, uri);
            i.setType("application/xml");
            startActivityForResult(Intent.createChooser(i, "Select File"), REQUEST_SELECT_FILE);
            return true;

        } else if (item.getItemId() == R.id.import_sd) {
            String xml = FileUtils.readFileToString(new File(SD_EXPORT_PATH));
            onCardsImported(ExportHelper.importCardsXml(getActivity(), xml));
            return true;

        } else if (item.getItemId() == R.id.copy_xml) {
            @SuppressWarnings("deprecation")
            ClipboardManager clipboard = (ClipboardManager) getActivity()
                    .getSystemService(Activity.CLIPBOARD_SERVICE);
            clipboard.setText(ExportHelper.exportCardsXml(getActivity()));
            Toast.makeText(getActivity(), "Copied to clipboard.", 5).show();
            return true;

        } else if (item.getItemId() == R.id.share_xml) {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, ExportHelper.exportCardsXml(getActivity()));
            startActivity(intent);
            return true;

        } else if (item.getItemId() == R.id.save_xml) {
            String xml = ExportHelper.exportCardsXml(getActivity());
            File file = new File(SD_EXPORT_PATH);
            FileUtils.writeStringToFile(file, xml, "UTF-8");
            Toast.makeText(getActivity(), "Wrote FareBot-Export.xml to USB Storage.", 5).show();
            return true;
        }
    } catch (Exception ex) {
        Utils.showError(getActivity(), ex);
    }
    return false;
}