Example usage for android.content Intent setType

List of usage examples for android.content Intent setType

Introduction

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

Prototype

public @NonNull Intent setType(@Nullable String type) 

Source Link

Document

Set an explicit MIME data type.

Usage

From source file:com.digitalarx.android.files.FileOperationsHelper.java

private Intent createShareWithLinkIntent(String link) {
    Intent intentToShareLink = new Intent(Intent.ACTION_SEND);
    intentToShareLink.putExtra(Intent.EXTRA_TEXT, link);
    intentToShareLink.setType(HTTP.PLAIN_TEXT_TYPE);
    return intentToShareLink;
}

From source file:de.awisus.refugeeaidleipzig.views.profile.FragmentEditOffer.java

private void startChooser() {
    Intent intentGalerie;
    intentGalerie = new Intent(Intent.ACTION_PICK);
    intentGalerie.setType("image/*");

    Intent chooser = new Intent(Intent.ACTION_CHOOSER);
    chooser.putExtra(Intent.EXTRA_INTENT, intentGalerie);
    chooser.putExtra(Intent.EXTRA_TITLE, R.string.titel_select_image);

    Intent[] intentArray = { new Intent(MediaStore.ACTION_IMAGE_CAPTURE) };
    chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);

    startActivityForResult(chooser, WAEHLE_BILD);
}

From source file:com.wodify.cordova.plugin.filepicker.FilePicker.java

/**
 * Pick file from device.//from  ww  w .j  ava 2s . co  m
 */
public void pickFile() {
    Intent intent = new Intent();

    // Any type of file may be picked
    intent.setType("*/*");

    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    if (this.cordova != null) {
        this.cordova.startActivityForResult((CordovaPlugin) this, Intent.createChooser(intent, "Pick File"), 0);
    }
}

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    try {//  w  ww.j  a  va  2  s . co  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;
}

From source file:es.uja.photofirma.android.LoginActivity.java

/**
 * Accin ejecutada si el usuario pulsa sobre la opcin que indica que no recuerda su contrasea,
 * abre una instancia de la aplicacin de email del dispositivo para contactar con el administrador
 * //from w  ww.  j  a va 2s.c o  m
 */
public void onForgotPassword(View view) {
    Intent it = new Intent(Intent.ACTION_SEND);
    it.putExtra(Intent.EXTRA_EMAIL, new String[] { getString(R.string.developer_email) });
    it.putExtra(Intent.EXTRA_SUBJECT, "Olvid mi contrasea...");
    it.setType("message/rfc822");
    startActivity(Intent.createChooser(it, null));
}

From source file:net.eledge.android.europeana.gui.activity.RecordActivity.java

private Intent createShareIntent() {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, recordController.getPortalUrl());
    shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Check out this item on Europeana.eu!");
    return shareIntent;
}

From source file:sjizl.com.FileUploadTest2.java

public void openGallery(int req_code) {

    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent, "Select file to upload "), req_code);
}

From source file:com.pureexe.calinoius.environment.camera.fragment.MainFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    dataManager = new DataManager(getActivity());

    try {/*from   w  ww .jav  a  2s .c  o m*/
        // Use Try catch Exception to avoid force close with CM's Privacy Guard
        Cursor c = getActivity().getApplication().getContentResolver()
                .query(ContactsContract.Profile.CONTENT_URI, null, null, null, null);
        c.moveToFirst();
        dataManager.setString("Researcher", c.getString(c.getColumnIndex("display_name")));
    } catch (Exception e) {
        dataManager.setString("Researcher", "Unknown");
    }
    GridView gridview = (GridView) rootView.findViewById(R.id.gridView1);
    gridview.setAdapter(new HomePageAdapter(getActivity()));
    gridview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            if (position == 0) {
                Intent beepActivity = new Intent(getActivity(), FragmentDisplayActivity.class);
                beepActivity.setAction(Intent.ACTION_SEND);
                beepActivity.putExtra(Intent.EXTRA_TEXT, "UserFragment");
                beepActivity.setType("beepActivity");
                startActivity(beepActivity);
            }
            if (position == 1) {
                Intent intent = new Intent(getActivity(), EnvironmentCameraActivity.class);
                startActivity(intent);
            }
            if (position == 2) {
                Intent beepActivity = new Intent(getActivity(), FragmentDisplayActivity.class);
                beepActivity.setAction(Intent.ACTION_SEND);
                beepActivity.putExtra(Intent.EXTRA_TEXT, "EXIFreadFragment");
                beepActivity.setType("beepActivity");
                startActivity(beepActivity);
            }
            if (position == 3) {
                Intent beepActivity = new Intent(getActivity(), FragmentDisplayActivity.class);
                beepActivity.setAction(Intent.ACTION_SEND);
                beepActivity.putExtra(Intent.EXTRA_TEXT, "SettingPreferenceFragment");
                beepActivity.setType("beepActivity");
                startActivity(beepActivity);
            }
            if (position == 4) {
                Intent beepActivity = new Intent(getActivity(), FragmentDisplayActivity.class);
                beepActivity.setAction(Intent.ACTION_SEND);
                beepActivity.putExtra(Intent.EXTRA_TEXT, "HelpFragment");
                beepActivity.setType("beepActivity");
                startActivity(beepActivity);
            }
            if (position == 5) {
                Intent beepActivity = new Intent(getActivity(), FragmentDisplayActivity.class);
                beepActivity.setAction(Intent.ACTION_SEND);
                beepActivity.putExtra(Intent.EXTRA_TEXT, "AboutFragment");
                beepActivity.setType("beepActivity");
                startActivity(beepActivity);
            }
        }
    });

    return rootView;
}

From source file:com.vuze.android.remote.AndroidUtils.java

public static void openFileChooser(Activity activity, String mimeType, int requestCode) {

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType(mimeType);
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    // special intent for Samsung file manager
    Intent sIntent = new Intent("com.sec.android.app.myfiles.PICK_DATA");

    sIntent.putExtra("CONTENT_TYPE", mimeType);
    sIntent.addCategory(Intent.CATEGORY_DEFAULT);

    Intent chooserIntent;/*from w  w  w . j av a 2s . c om*/
    if (activity.getPackageManager().resolveActivity(sIntent, 0) != null) {
        chooserIntent = Intent.createChooser(sIntent, "Open file");
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { intent });
    } else {
        chooserIntent = Intent.createChooser(intent, "Open file");
    }

    if (chooserIntent != null) {
        try {
            activity.startActivityForResult(chooserIntent, requestCode);
            return;
        } catch (android.content.ActivityNotFoundException ex) {
        }
    }
    Toast.makeText(activity.getApplicationContext(),
            activity.getResources().getString(R.string.no_file_chooser), Toast.LENGTH_SHORT).show();
}