Example usage for android.content Intent createChooser

List of usage examples for android.content Intent createChooser

Introduction

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

Prototype

public static Intent createChooser(Intent target, CharSequence title) 

Source Link

Document

Convenience function for creating a #ACTION_CHOOSER Intent.

Usage

From source file:com.amaze.filemanager.utils.files.FileUtils.java

/**
 * Open a file not supported by Amaze/*  ww w. ja  va  2 s  . com*/
 *
 * @param f the file
 * @param forcechooser force the chooser to show up even when set default by user
 */
public static void openunknown(File f, Context c, boolean forcechooser, boolean useNewStack) {
    Intent chooserIntent = new Intent();
    chooserIntent.setAction(Intent.ACTION_VIEW);

    String type = MimeTypes.getMimeType(f.getPath(), f.isDirectory());
    if (type != null && type.trim().length() != 0 && !type.equals("*/*")) {
        Uri uri = fileToContentUri(c, f);
        if (uri == null)
            uri = Uri.fromFile(f);
        chooserIntent.setDataAndType(uri, type);

        Intent activityIntent;
        if (forcechooser) {
            if (useNewStack)
                applyNewDocFlag(chooserIntent);
            activityIntent = Intent.createChooser(chooserIntent, c.getString(R.string.openwith));
        } else {
            activityIntent = chooserIntent;
            if (useNewStack)
                applyNewDocFlag(activityIntent);
        }

        try {
            c.startActivity(activityIntent);
        } catch (ActivityNotFoundException e) {
            e.printStackTrace();
            Toast.makeText(c, R.string.noappfound, Toast.LENGTH_SHORT).show();
            openWith(f, c, useNewStack);
        }
    } else {
        // failed to load mime type
        openWith(f, c, useNewStack);
    }
}

From source file:com.chummy.jezebel.material.dark.activities.Main.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    context = this;
    mPrefs = new Preferences(Main.this);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from  ww  w .  j a  va 2  s  . c  o m
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    thaApp = getResources().getString(R.string.app_name);
    thaHome = getResources().getString(R.string.section_one);
    thaPreviews = getResources().getString(R.string.section_two);
    thaApply = getResources().getString(R.string.section_three);
    thaWalls = getResources().getString(R.string.section_four);
    thaRequest = getResources().getString(R.string.section_five);
    thaCredits = getResources().getString(R.string.section_seven);
    thaTesters = getResources().getString(R.string.section_eight);
    thaWhatIsThemed = getResources().getString(R.string.section_nine);
    thaContactUs = getResources().getString(R.string.section_ten);
    thaLogcat = getResources().getString(R.string.section_eleven);
    thaFAQ = getResources().getString(R.string.section_twelve);
    thaHelp = getResources().getString(R.string.section_thirteen);
    thaAbout = getResources().getString(R.string.section_fourteen);
    thaIconPack = getResources().getString(R.string.section_fifteen);
    thaFullChangelog = getResources().getString(R.string.section_sixteen);
    thaRebuild = getResources().getString(R.string.section_seventeen);

    drawerVersion = getResources().getString(R.string.version_code);

    currentItem = 1;

    headerResult = new AccountHeader().withActivity(this).withHeaderBackground(R.drawable.header)
            .withSelectionFirstLine(getResources().getString(R.string.app_name))
            .withSelectionSecondLine(drawerVersion).withSavedInstance(savedInstanceState).withHeightDp(120)
            .build();

    enable_features = mPrefs.isFeaturesEnabled();
    firstrun = mPrefs.isFirstRun();

    result = new Drawer().withActivity(this).withToolbar(toolbar).withAccountHeader(headerResult)
            .withHeaderDivider(false).withDrawerWidthDp(400)
            .addDrawerItems(new SectionDrawerItem().withName("Main"),
                    new PrimaryDrawerItem().withName(thaHome).withIcon(GoogleMaterial.Icon.gmd_home)
                            .withIdentifier(1),
                    new PrimaryDrawerItem().withName(thaIconPack)
                            .withIcon(GoogleMaterial.Icon.gmd_picture_in_picture)
                            .withDescription("This applies icon pack 'Whicons'.").withCheckable(false)
                            .withIdentifier(11),
                    new PrimaryDrawerItem().withName(thaFullChangelog)
                            .withIcon(GoogleMaterial.Icon.gmd_wrap_text)
                            .withDescription("Complete changelog of Dark Material.").withCheckable(false)
                            .withIdentifier(12),
                    new DividerDrawerItem(), new SectionDrawerItem().withName("Information"),
                    new PrimaryDrawerItem().withName(thaAbout).withIcon(GoogleMaterial.Icon.gmd_info_outline)
                            .withDescription("Basic information on the theme.").withIdentifier(10),
                    new PrimaryDrawerItem().withName(thaWhatIsThemed).withIcon(GoogleMaterial.Icon.gmd_warning)
                            .withDescription("List of overlaid applications.").withIdentifier(3),
                    new PrimaryDrawerItem().withName(thaFAQ).withIcon(GoogleMaterial.Icon.gmd_question_answer)
                            .withDescription("Common questions with answers.").withIdentifier(8),
                    new DividerDrawerItem(), new SectionDrawerItem().withName("Tools & Utilities"),
                    new PrimaryDrawerItem().withName(thaRebuild).withIcon(GoogleMaterial.Icon.gmd_sync)
                            .withDescription("A rebuild a day keeps the RRs away!").withCheckable(false)
                            .withBadge("ROOT ").withIdentifier(13),
                    new PrimaryDrawerItem().withName(thaLogcat).withIcon(GoogleMaterial.Icon.gmd_bug_report)
                            .withDescription("System level log recording.").withCheckable(false)
                            .withBadge("ROOT ").withIdentifier(7),
                    new DividerDrawerItem(), new SectionDrawerItem().withName("The Developers"),
                    new PrimaryDrawerItem().withName(thaCredits).withIcon(GoogleMaterial.Icon.gmd_people)
                            .withDescription("chummy development team").withIdentifier(5),
                    new PrimaryDrawerItem().withName(thaTesters).withIcon(GoogleMaterial.Icon.gmd_star)
                            .withDescription("The people who keep the team updated.").withIdentifier(4),
                    new DividerDrawerItem(), new SectionDrawerItem().withName("Contact"),
                    new SecondaryDrawerItem().withName(thaContactUs).withIcon(GoogleMaterial.Icon.gmd_mail)
                            .withCheckable(false).withIdentifier(6),
                    new SecondaryDrawerItem().withName(thaHelp).withIcon(GoogleMaterial.Icon.gmd_help)
                            .withCheckable(true).withIdentifier(9))
            .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id,
                        IDrawerItem drawerItem) {

                    if (drawerItem != null) {

                        switch (drawerItem.getIdentifier()) {
                        case 1:
                            switchFragment(1, thaApp, "Home");
                            break;
                        case 2:
                            ConnectivityManager cm = (ConnectivityManager) context
                                    .getSystemService(Context.CONNECTIVITY_SERVICE);
                            NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
                            boolean isConnected = activeNetwork != null
                                    && activeNetwork.isConnectedOrConnecting();

                            if (isConnected) {
                                switchFragment(2, thaWalls, "Wallpapers");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 3:
                            switchFragment(3, thaWhatIsThemed, "WhatIsThemed");
                            break;
                        case 4:
                            switchFragment(4, thaTesters, "Testers");
                            break;
                        case 5:
                            switchFragment(5, thaCredits, "Credits");
                            break;
                        case 6:
                            StringBuilder emailBuilder = new StringBuilder();
                            Intent intent = new Intent(Intent.ACTION_VIEW,
                                    Uri.parse("mailto:" + getResources().getString(R.string.email_id)));
                            if (!isAppInstalled("org.cyanogenmod.theme.chooser")) {
                                if (!isAppInstalled("com.cyngn.theme.chooser")) {
                                    if (!isAppInstalled("com.lovejoy777.rroandlayersmanager")) {
                                        intent.putExtra(Intent.EXTRA_SUBJECT,
                                                getResources().getString(R.string.email_subject));
                                    } else {
                                        intent.putExtra(Intent.EXTRA_SUBJECT,
                                                getResources().getString(R.string.email_subject_rro));
                                    }
                                } else {
                                    intent.putExtra(Intent.EXTRA_SUBJECT,
                                            getResources().getString(R.string.email_subject_cos));
                                }
                            } else {
                                intent.putExtra(Intent.EXTRA_SUBJECT,
                                        getResources().getString(R.string.email_subject_cm));
                            }
                            emailBuilder.append("\n \n \nOS Version: " + System.getProperty("os.version") + "("
                                    + Build.VERSION.INCREMENTAL + ")");
                            emailBuilder.append("\nOS API Level: " + Build.VERSION.SDK_INT + " ("
                                    + Build.VERSION.RELEASE + ") " + "[" + Build.ID + "]");
                            emailBuilder.append("\nDevice: " + Build.DEVICE);
                            emailBuilder.append("\nManufacturer: " + Build.MANUFACTURER);
                            emailBuilder.append(
                                    "\nModel (and Product): " + Build.MODEL + " (" + Build.PRODUCT + ")");
                            if (!isAppInstalled("org.cyanogenmod.theme.chooser")) {
                                if (!isAppInstalled("com.cyngn.theme.chooser")) {
                                    if (!isAppInstalled("com.lovejoy777.rroandlayersmanager")) {
                                        emailBuilder.append("\nTheme Engine: Not Available");
                                    } else {
                                        emailBuilder.append("\nTheme Engine: Layers Manager (RRO)");
                                    }
                                } else {
                                    emailBuilder.append("\nTheme Engine: Cyanogen OS Theme Engine");
                                }
                            } else {
                                emailBuilder.append("\nTheme Engine: CyanogenMod Theme Engine");
                            }
                            PackageInfo appInfo = null;
                            try {
                                appInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
                            } catch (PackageManager.NameNotFoundException e) {
                                e.printStackTrace();
                            }
                            emailBuilder.append("\nApp Version Name: " + appInfo.versionName);
                            emailBuilder.append("\nApp Version Code: " + appInfo.versionCode);

                            intent.putExtra(Intent.EXTRA_TEXT, emailBuilder.toString());
                            startActivity(Intent.createChooser(intent,
                                    (getResources().getString(R.string.send_title))));
                            break;
                        case 7:
                            if (Shell.SU.available()) {
                                if (!isAppInstalled("com.tooleap.logcat")) {
                                    if (!isAppInstalled("com.nolanlawson.logcat")) {
                                        Intent logcat = new Intent(Intent.ACTION_VIEW, Uri.parse(
                                                getResources().getString(R.string.play_store_link_logcat)));
                                        startActivity(logcat);
                                    } else {
                                        Intent intent_logcat = getPackageManager()
                                                .getLaunchIntentForPackage("com.nolanlawson.logcat");
                                        Toast toast = Toast.makeText(getApplicationContext(),
                                                getResources().getString(R.string.logcat_toast),
                                                Toast.LENGTH_LONG);
                                        toast.show();
                                        startActivity(intent_logcat);
                                    }
                                } else {
                                    Intent intent_tooleap = getPackageManager()
                                            .getLaunchIntentForPackage("com.tooleap.logcat");
                                    Toast toast = Toast.makeText(getApplicationContext(),
                                            getResources().getString(R.string.logcat_toast), Toast.LENGTH_LONG);
                                    toast.show();
                                    startActivity(intent_tooleap);
                                }
                            } else {
                                Toast toast = Toast.makeText(getApplicationContext(),
                                        "Unfortunately, this feature is only available for root users.",
                                        Toast.LENGTH_LONG);
                                toast.show();
                            }
                            break;
                        case 8:
                            switchFragment(8, thaFAQ, "FAQ");
                            break;
                        case 9:
                            switchFragment(9, thaHelp, "Help");
                            break;
                        case 10:
                            switchFragment(10, thaAbout, "About");
                            break;
                        case 11:
                            Intent launch_whicons = new Intent("android.intent.action.MAIN");
                            launch_whicons.setComponent(new ComponentName("org.cyanogenmod.theme.chooser",
                                    "org.cyanogenmod.theme.chooser.ChooserActivity"));
                            launch_whicons.putExtra("pkgName", "com.whicons.iconpack");
                            Intent launch_whicons_cos = new Intent("android.intent.action.MAIN");
                            launch_whicons_cos.setComponent(new ComponentName("com.cyngn.theme.chooser",
                                    "com.cyngn.theme.chooser.ChooserActivity"));
                            launch_whicons_cos.putExtra("pkgName", "com.whicons.iconpack");
                            Intent devPlay = new Intent(Intent.ACTION_VIEW,
                                    Uri.parse(getResources().getString(R.string.play_store_whicons)));
                            Intent intent_whicons = getPackageManager()
                                    .getLaunchIntentForPackage("com.whicons.iconpack");
                            if (intent_whicons == null) {
                                startActivity(devPlay);
                            } else {
                                if (isAppInstalled("org.cyanogenmod.theme.chooser")) {
                                    startActivity(launch_whicons);
                                } else {
                                    if (isAppInstalled("com.cyngn.theme.chooser")) {
                                        Toast toast = Toast.makeText(getApplicationContext(),
                                                "Select Dark Material, click Customize and locate Default Icons. Then select Whicons and click Apply.",
                                                Toast.LENGTH_LONG);
                                        toast.show();
                                        startActivity(launch_whicons_cos);
                                    } else {
                                        startActivity(intent_whicons);
                                    }
                                }
                            }
                            break;
                        case 12:
                            fullchangelog();
                            break;
                        case 13:
                            if (Shell.SU.available()) {
                                rebuildThemeCache();
                            } else {
                                Toast toast = Toast.makeText(getApplicationContext(),
                                        "Unfortunately, this feature is only available for root users.",
                                        Toast.LENGTH_LONG);
                                toast.show();
                            }
                            break;
                        }
                    }
                }
            }).withSavedInstance(savedInstanceState).build();

    result.getListView().setVerticalScrollBarEnabled(false);

    // Check for permissions first so that we don't have any issues down the road
    int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(),
            android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
    if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
        // permission already granted, allow the program to continue running
        runLicenseChecker();
    } else {
        // permission not granted, request it from the user
        ActivityCompat.requestPermissions(this,
                new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE },
                PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
    }

    if (savedInstanceState == null) {
        result.setSelectionByIdentifier(1);
    }

}

From source file:com.cleanwiz.applock.ui.activity.LockMainActivity.java

public void shareMsg(String activityTitle, String msgTitle, String msgText, String imgPath) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    if (imgPath == null || imgPath.equals("")) {
        intent.setType("text/plain");
    } else {/*from  ww  w .  ja v a2  s.  c o m*/
        File f = new File(imgPath);
        if (f.exists() && f.isFile()) {
            intent.setType("image/jpg");
            Uri uri = Uri.fromFile(f);
            intent.putExtra(Intent.EXTRA_STREAM, uri);
        }
    }
    intent.putExtra(Intent.EXTRA_SUBJECT, msgTitle);
    intent.putExtra(Intent.EXTRA_TEXT, msgText);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(Intent.createChooser(intent, activityTitle));
}

From source file:com.cordova.photo.CameraLauncher.java

/**
 * Get image from photo library.//from ww  w .  java  2  s  .c om
 *
 * @param quality           Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
 * @param srcType           The album to get image from.
 * @param returnType        Set the type of image to return.
 * @param encodingType 
 */
// TODO: Images selected from SDCARD don't display correctly, but from CAMERA ALBUM do!
// TODO: Images from kitkat filechooser not going into crop function
public void getImage(int srcType, int returnType, int encodingType) {
    Intent intent = new Intent();
    String title = GET_PICTURE;
    croppedUri = null;
    if (this.mediaType == PICTURE) {
        intent.setType("image/*");
        if (this.allowEdit) {
            intent.setAction(Intent.ACTION_PICK);
            intent.putExtra("crop", "true");
            if (targetWidth > 0) {
                intent.putExtra("outputX", targetWidth);
            }
            if (targetHeight > 0) {
                intent.putExtra("outputY", targetHeight);
            }
            if (targetHeight > 0 && targetWidth > 0 && targetWidth == targetHeight) {
                intent.putExtra("aspectX", 1);
                intent.putExtra("aspectY", 1);
            }
            File photo = createCaptureFile(encodingType);
            croppedUri = Uri.fromFile(photo);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, croppedUri);
        } else {
            intent.setAction(Intent.ACTION_GET_CONTENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
        }
    } else if (this.mediaType == VIDEO) {
        intent.setType("video/*");
        title = GET_VIDEO;
        intent.setAction(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
    } else if (this.mediaType == ALLMEDIA) {
        // I wanted to make the type 'image/*, video/*' but this does not work on all versions
        // of android so I had to go with the wildcard search.
        intent.setType("*/*");
        title = GET_All;
        intent.setAction(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
    }
    if (this.activity != null) {
        this.activity.startActivityForResult(Intent.createChooser(intent, new String(title)),
                (srcType + 1) * 16 + returnType + 1);
    }
}

From source file:com.gelakinetic.mtgfam.fragments.TradeFragment.java

/**
 * Build a plaintext trade and share it.
 *//*w  ww .j a  v a 2s. c o  m*/
private void shareTrade() {

    StringBuilder sb = new StringBuilder();

    /* Add all the cards to the StringBuilder from the left, tallying the price */
    float totalPrice = 0;
    for (MtgCard card : mListLeft) {
        totalPrice += (card.toTradeShareString(sb, getString(R.string.wishlist_foil)) / 100.0f);
    }
    sb.append(String.format(Locale.US, PRICE_FORMAT + "%n", totalPrice));

    /* Simple divider */
    sb.append("--------\n");

    /* Add all the cards to the StringBuilder from the right, tallying the price */
    totalPrice = 0;
    for (MtgCard card : mListRight) {
        totalPrice += (card.toTradeShareString(sb, getString(R.string.wishlist_foil)) / 100.0f);
    }
    sb.append(String.format(Locale.US, PRICE_FORMAT, totalPrice));

    /* Send the Intent on it's merry way */
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, R.string.trade_share_title);
    sendIntent.putExtra(Intent.EXTRA_TEXT, sb.toString());
    sendIntent.setType("text/plain");

    try {
        startActivity(Intent.createChooser(sendIntent, getString(R.string.trader_share)));
    } catch (android.content.ActivityNotFoundException ex) {
        ToastWrapper.makeAndShowText(getActivity(), R.string.error_no_email_client, ToastWrapper.LENGTH_SHORT);
    }
}

From source file:dk.dr.radio.data.DRData.java

public void kundividi(Activity akt) {
      Intent sendIntent = new Intent();
      sendIntent.setAction(Intent.ACTION_SEND);
      sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Esperanto-radio por Androjd");
      sendIntent.putExtra(Intent.EXTRA_TEXT,
              "Saluton!\n\n" + "Mi rekomendas ke vi elprovas tiun i programon per via Androjda telefono:\n"
                      + "La Esperanto-radio de Muzaiko\n"
                      + "https://market.android.com/details?id=dk.nordfalk.esperanto.radio\n" + "\n"
                      + "Muzaiko estas Esperanto-radio kiu konstante elsendas.\n"
                      + "Eblas anka askulti la lastatempajn elsendojn de deko da aliaj radistacioj." //         +"\n\n(kaj... ne forgesu meti 5 stelojn :-)"
      );/*from   w ww .jav a2  s .c o  m*/
      sendIntent.setType("text/plain");
      akt.startActivity(Intent.createChooser(sendIntent, "Sendi al"));
  }

From source file:it.mb.whatshare.MainActivity.java

private void onTellFriendsSelected() {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/html");
    intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.email_subject));
    intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(getResources().getString(R.string.email_body)));
    startActivity(Intent.createChooser(intent, getResources().getString(R.string.email_intent_msg)));
}

From source file:com.silentcircle.silenttext.util.DeviceUtils.java

public static Intent getShareDebugInformationIntent(Context context) {

    Intent intent = new Intent(Intent.ACTION_SENDTO,
            Uri.fromParts("mailto", context.getString(R.string.support_email_address), null));

    intent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.support_email_subject));
    intent.putExtra(Intent.EXTRA_TEXT, wrap(LABEL_DEBUG_INFO, getDebugInformation(context)));

    ResolveInfo info = context.getPackageManager().resolveActivity(intent, 0);

    if (info == null) {
        intent.setAction(Intent.ACTION_SEND);
        intent.setDataAndType(null, "text/plain");
    }//from  w  ww.  j av a  2  s . c om

    return Intent.createChooser(intent,
            context.getString(R.string.share_with, context.getString(R.string.feedback)));

}

From source file:net.gerosyab.dailylog.activity.MainActivity.java

private void exportCategory(final long id) {

    //?? ? ?? csv  
    //? ?? ?? /* ww w .  j  a v  a  2s  . co  m*/
    // ? ?  ? ? 
    Category category = categories.get((int) id);

    ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setTitle("Exporting data [" + category.getName() + "]");
    progressDialog.show();

    String filename = category.getName() + "" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())
            + ".data";
    FileOutputStream outputStream = null;
    File resultFilePath = null;
    File resultFile = null;
    CSVWriter cw = null;

    try {
        resultFile = new File(context.getCacheDir(), filename);

        outputStream = new FileOutputStream(resultFile.getAbsolutePath());
        //            cw = new CSVWriter(new OutputStreamWriter(outputStream, "UTF-8"),'\t', '"');
        cw = new CSVWriter(new OutputStreamWriter(outputStream, "UTF-8"), ',', '"');

        // Export Data
        String[] metaDataStr = { "Version:" + AppDatabase.VERSION, "Name:" + category.getName(),
                "Unit:" + category.getUnit(), "Type:" + category.getRecordType(),
                "DefaultValue:" + category.getDefaultValue(),
                "Columns:date(yyyy-MM-dd 24HH:mm:ss)/value(boolean|numeric|string)" };
        cw.writeNext(metaDataStr);

        List<Record> records = category.getRecordsOrderByDateAscending(realm);
        for (Record record : records) {
            String value = null;
            if (category.getRecordType() == StaticData.RECORD_TYPE_BOOLEAN) {
                value = "true";
            } else if (category.getRecordType() == StaticData.RECORD_TYPE_NUMBER) {
                value = "" + record.getNumber();
            } else if (category.getRecordType() == StaticData.RECORD_TYPE_MEMO) {
                value = record.getString();
            }
            String[] s = { record.getDateString(StaticData.fmtForBackup), value };
            cw.writeNext(s);
        }

        cw.close();
        outputStream.close();

        progressDialog.dismiss();

        Uri fileUri = FileProvider.getUriForFile(context, "net.gerosyab.dailylog.fileprovider", resultFile);

        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
        shareIntent.setType("text/plain");

        startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));

    } catch (UnsupportedEncodingException e) {
        Log.e("DailyLog", e.getMessage());
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        Log.e("DailyLog", e.getMessage());
        e.printStackTrace();
    } catch (Exception e) {
        Log.e("DailyLog", e.getMessage());
        e.printStackTrace();
    } finally {
        progressDialog.dismiss();
    }
}

From source file:com.agustinprats.myhrv.MainActivity.java

protected void sendFileByEmail(File file) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "eladfein@gmail.com" });
    intent.putExtra(Intent.EXTRA_SUBJECT, "Testing result of HRV bluetooth monitor");
    intent.putExtra(Intent.EXTRA_TEXT, "see files attached");
    Uri uri = Uri.fromFile(file);/*  w  w  w.  j  av  a  2 s. c  o  m*/

    intent.putExtra(Intent.EXTRA_STREAM, uri);

    startActivity(Intent.createChooser(intent, "Send email..."));

}