Example usage for android.content Intent EXTRA_SUBJECT

List of usage examples for android.content Intent EXTRA_SUBJECT

Introduction

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

Prototype

String EXTRA_SUBJECT

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

Click Source Link

Document

A constant string holding the desired subject line of a message.

Usage

From source file:com.rsltc.profiledata.main.MainActivity.java

private void exportFile(List<JSONObject> jsonObjects, String dataset_name) {
    final String date = new SimpleDateFormat("yyyyMMdd-HHmmss", Locale.getDefault()).format(new Date());
    final String filename = String.format("%s_%s.txt", dataset_name, date);

    final String directory = Environment.getExternalStorageDirectory().getAbsolutePath() + "/AndroidTesting/";

    final File logfile = new File(directory, filename);
    final File logPath = logfile.getParentFile();

    if (!logPath.isDirectory() && !logPath.mkdirs()) {
        Log.e("SensorDashbaord", "Could not create directory for log files");
    }/* w ww .  ja va  2s .  c  o  m*/

    try {
        FileWriter filewriter = new FileWriter(logfile);
        BufferedWriter bw = new BufferedWriter(filewriter);

        //            for (JSONObject object : jsonObjects) {
        bw.write(jsonObjects.toString());
        //            }
        bw.flush();
        bw.close();

        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.setType("*/*");

        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, dataset_name + ".csv");
        emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(logfile));
        startActivity(Intent.createChooser(emailIntent, "Send mail..."));

        Log.i(TAG, "export finished!");
    } catch (IOException ioe) {
        Log.e(TAG, "IOException while writing Logfile");
        Log.e("Enias", ioe.getMessage());
    }
}

From source file:com.matthewmitchell.peercoin_android_wallet.ui.WalletActivity.java

private void archiveWalletBackup(@Nonnull final File file) {
    final Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.export_keys_dialog_mail_subject));
    intent.putExtra(Intent.EXTRA_TEXT, makeEmailText(getString(R.string.export_keys_dialog_mail_text)));
    intent.setType(Constants.MIMETYPE_WALLET_BACKUP);
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));

    try {/*  w w  w.  j a va2s .  co  m*/
        startActivity(Intent.createChooser(intent, getString(R.string.export_keys_dialog_mail_intent_chooser)));
        log.info("invoked chooser for archiving wallet backup");
    } catch (final Exception x) {
        longToast(R.string.export_keys_dialog_mail_intent_failed);
        log.error("archiving wallet backup failed", x);
    }
}

From source file:com.apps.gator.DisplayTranslationActivity.java

/**
 * Sends an email with a subject of Feedback.
 *//*from w  ww  .j  a  va  2 s  .  co  m*/
private void openFeedback() {
    final Intent email = new Intent(Intent.ACTION_SEND);
    email.setType("text/email");
    email.putExtra(Intent.EXTRA_EMAIL, new String[] { "sudhirayrota@gmail.com" });
    email.putExtra(Intent.EXTRA_SUBJECT, "Feedback:Gator Translator:");
    email.putExtra(Intent.EXTRA_TEXT, "Dear Gator-Translator Development Team," + "");
    startActivity(Intent.createChooser(email, "Send Feedback:"));

}

From source file:com.hughes.android.dictionary.DictionaryActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    AdapterContextMenuInfo adapterContextMenuInfo = (AdapterContextMenuInfo) menuInfo;
    final RowBase row = (RowBase) getListAdapter().getItem(adapterContextMenuInfo.position);

    final android.view.MenuItem addToWordlist = menu.add(getString(R.string.addToWordList, wordList.getName()));
    addToWordlist.setOnMenuItemClickListener(new android.view.MenuItem.OnMenuItemClickListener() {
        public boolean onMenuItemClick(android.view.MenuItem item) {
            onAppendToWordList(row);//from  ww  w  .j av  a2s  .c om
            return false;
        }
    });

    final android.view.MenuItem share = menu.add("Share");
    share.setOnMenuItemClickListener(new android.view.MenuItem.OnMenuItemClickListener() {
        public boolean onMenuItemClick(android.view.MenuItem item) {
            Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
            shareIntent.setType("text/plain");
            shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, row.getTokenRow(true).getToken());
            shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, row.getRawText(saveOnlyFirstSubentry));
            startActivity(shareIntent);
            return false;
        }
    });

    final android.view.MenuItem copy = menu.add(android.R.string.copy);
    copy.setOnMenuItemClickListener(new android.view.MenuItem.OnMenuItemClickListener() {
        public boolean onMenuItemClick(android.view.MenuItem item) {
            onCopy(row);
            return false;
        }
    });

    if (selectedSpannableText != null) {
        final String selectedText = selectedSpannableText;
        final android.view.MenuItem searchForSelection = menu
                .add(getString(R.string.searchForSelection, selectedSpannableText));
        searchForSelection.setOnMenuItemClickListener(new android.view.MenuItem.OnMenuItemClickListener() {
            public boolean onMenuItemClick(android.view.MenuItem item) {
                jumpToTextFromHyperLink(selectedText, selectedSpannableIndex);
                return false;
            }
        });
        // Rats, this won't be shown:
        //searchForSelection.setIcon(R.drawable.abs__ic_search);
    }

    if ((row instanceof TokenRow || selectedSpannableText != null) && ttsReady) {
        final android.view.MenuItem speak = menu.add(R.string.speak);
        final String textToSpeak = row instanceof TokenRow ? ((TokenRow) row).getToken()
                : selectedSpannableText;
        updateTTSLanguage(row instanceof TokenRow ? indexIndex : selectedSpannableIndex);
        speak.setOnMenuItemClickListener(new android.view.MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(android.view.MenuItem item) {
                textToSpeech.speak(textToSpeak, TextToSpeech.QUEUE_FLUSH, new HashMap<String, String>());
                return false;
            }
        });
    }
}

From source file:com.apps.gator.DisplayTranslationActivity.java

/**
 * Sends an email with a subject of Report Error.
 *///from   w  w  w. j  av  a2s.  co  m
private void openReportError() {
    final Intent email = new Intent(Intent.ACTION_SEND);
    email.setType("text/email");
    email.putExtra(Intent.EXTRA_EMAIL, new String[] { "sudhirayrota@gmail.com" });
    email.putExtra(Intent.EXTRA_SUBJECT, "Report Error:Gator Translator:");
    email.putExtra(Intent.EXTRA_TEXT, "Dear Gator-Translator Development Team," + "");
    startActivity(Intent.createChooser(email, "Report Error:"));
}

From source file:com.odoo.core.orm.OModel.java

public void exportDB() {
    FileChannel source;//from  ww w  . ja v  a 2s . c  o m
    FileChannel destination;
    String currentDBPath = getDatabaseLocalPath();
    String backupDBPath = OStorageUtils.getDirectoryPath("file") + "/" + getDatabaseName();
    File currentDB = new File(currentDBPath);
    File backupDB = new File(backupDBPath);
    try {
        source = new FileInputStream(currentDB).getChannel();
        destination = new FileOutputStream(backupDB).getChannel();
        destination.transferFrom(source, 0, source.size());
        source.close();
        destination.close();
        String subject = "Database Export: " + getDatabaseName();
        Uri uri = Uri.fromFile(backupDB);
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.putExtra(Intent.EXTRA_STREAM, uri);
        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
        intent.setType("message/rfc822");
        mContext.startActivity(intent);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.crearo.gpslogger.GpsMainActivity.java

/**
 * Allows user to send a GPX/KML file along with location, or location only
 * using a provider. 'Provider' means any application that can accept such
 * an intent (Facebook, SMS, Twitter, Email, K-9, Bluetooth)
 *//*from   w w w.  j  av a  2s.c  om*/
private void share() {

    try {

        final String locationOnly = getString(R.string.sharing_location_only);
        final File gpxFolder = new File(preferenceHelper.getGpsLoggerFolder());
        if (gpxFolder.exists()) {

            File[] enumeratedFiles = Files.fromFolder(gpxFolder);

            Arrays.sort(enumeratedFiles, new Comparator<File>() {
                public int compare(File f1, File f2) {
                    return -1 * Long.valueOf(f1.lastModified()).compareTo(f2.lastModified());
                }
            });

            List<String> fileList = new ArrayList<>(enumeratedFiles.length);

            for (File f : enumeratedFiles) {
                fileList.add(f.getName());
            }

            fileList.add(0, locationOnly);
            final String[] files = fileList.toArray(new String[fileList.size()]);

            new MaterialDialog.Builder(this).title(R.string.osm_pick_file).items(files)
                    .positiveText(R.string.ok)
                    .itemsCallbackMultiChoice(null, new MaterialDialog.ListCallbackMultiChoice() {
                        @Override
                        public boolean onSelection(MaterialDialog materialDialog, Integer[] integers,
                                CharSequence[] charSequences) {
                            List<Integer> selectedItems = Arrays.asList(integers);

                            final Intent intent = new Intent(Intent.ACTION_SEND);
                            intent.setType("*/*");

                            if (selectedItems.size() <= 0) {
                                return false;
                            }

                            if (selectedItems.contains(0)) {

                                intent.setType("text/plain");

                                intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.sharing_mylocation));
                                if (Session.hasValidLocation()) {
                                    String bodyText = getString(R.string.sharing_googlemaps_link,
                                            String.valueOf(Session.getCurrentLatitude()),
                                            String.valueOf(Session.getCurrentLongitude()));
                                    intent.putExtra(Intent.EXTRA_TEXT, bodyText);
                                    intent.putExtra("sms_body", bodyText);
                                    startActivity(
                                            Intent.createChooser(intent, getString(R.string.sharing_via)));
                                }
                            } else {

                                intent.setAction(Intent.ACTION_SEND_MULTIPLE);
                                intent.putExtra(Intent.EXTRA_SUBJECT, "Here are some files.");
                                intent.setType("*/*");

                                ArrayList<Uri> chosenFiles = new ArrayList<>();

                                for (Object path : selectedItems) {
                                    File file = new File(gpxFolder, files[Integer.valueOf(path.toString())]);
                                    Uri uri = Uri.fromFile(file);
                                    chosenFiles.add(uri);
                                }

                                intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, chosenFiles);
                                startActivity(Intent.createChooser(intent, getString(R.string.sharing_via)));
                            }
                            return true;
                        }
                    }).show();

        } else {
            Dialogs.alert(getString(R.string.sorry), getString(R.string.no_files_found), this);
        }
    } catch (Exception ex) {
        LOG.error("Sharing problem", ex);
    }
}

From source file:com.dvdprime.mobile.android.ui.DocumentViewActivity.java

private Response.Listener<JSONObject> createShortenerReqSuccessListener() {
    return new Response.Listener<JSONObject>() {
        public void onResponse(JSONObject result) {
            try {
                Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setType("text/plain");
                intent.putExtra(Intent.EXTRA_SUBJECT, getSupportActionBar().getSubtitle());
                Object[] data = new Object[2];
                data[0] = getSupportActionBar().getSubtitle();
                data[1] = result.getString("id");
                intent.putExtra(Intent.EXTRA_TEXT, StringUtil.format("[DP]{0} - {1}", data));
                startActivity(Intent.createChooser(intent, getString(R.string.action_bar_share_with)));
                return;
            } catch (JSONException localJSONException) {
                LOGD(TAG, "Parse error");
            }//from ww  w . j  a v  a2s. co  m
        }
    };
}

From source file:com.mibr.android.intelligentreminder.INeedToo.java

public void TrialIsEndingWarningOrLicensingFailed(String verbiage, Boolean wereDealingWithLicensingHere) {
    final Boolean wdwlh = wereDealingWithLicensingHere;
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(verbiage).setCancelable(false)
            .setNeutralButton(R.string.msg_cus, new DialogInterface.OnClickListener() {
                @Override//www .jav a  2s  .  c  o m
                public void onClick(DialogInterface dialog, int id) {
                    String[] mailto = { "diamondsoftware222@gmail.com", "" };
                    Intent sendIntent = new Intent(Intent.ACTION_SEND);
                    sendIntent.putExtra(Intent.EXTRA_EMAIL, mailto);
                    sendIntent.putExtra(Intent.EXTRA_SUBJECT, "".toString());
                    sendIntent.putExtra(Intent.EXTRA_TEXT, "".toString());
                    sendIntent.setType("text/plain");
                    startActivity(Intent.createChooser(sendIntent, "Send EMail..."));
                }
            }).setPositiveButton(R.string.msg_register, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    Intent i4 = new Intent(INeedToo.this, INeedToPay.class);
                    startActivity(i4);
                }
            }).setNegativeButton(R.string.msg_cancel, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (wdwlh) {
                        INeedToo.this.finish();
                    }
                }
            });
    AlertDialog alert = builder.create();
    try {
        alert.show();
    } catch (Exception ee33) {
        int bkhere = 3;
        int bkhere2 = bkhere;
    }
}

From source file:com.aimfire.gallery.GalleryActivity.java

/**
 * share only to certain apps. code based on "http://stackoverflow.com/questions/
 * 9730243/how-to-filter-specific-apps-for-action-send-intent-and-set-a-different-
 * text-for/18980872#18980872"/*from ww  w . j  av a2 s.  c  om*/
 * 
 * "copy link" inspired by http://cketti.de/2016/06/15/share-url-to-clipboard/
 * 
 * in general, "deep linking" is supported by the apps below. Facebook, Wechat,
 * Telegram are exceptions. click on the link would bring users to the landing
 * page. 
 * 
 * Facebook doesn't take our EXTRA_TEXT so user will have to "copy link" first 
 * then paste the link
 */
private void shareMedia(Intent data) {
    /*
     * we log this as "share complete", but user can still cancel the share at this point,
     * and we wouldn't be able to know
     */
    mFirebaseAnalytics.logEvent(MainConsts.FIREBASE_CUSTOM_EVENT_SHARE_COMPLETE, null);

    Resources resources = getResources();

    /*
     * get the resource id for the shared file
     */
    String id = data.getStringExtra(MainConsts.EXTRA_ID_RESOURCE);

    /*
     * construct link
     */
    String link = "https://" + resources.getString(R.string.app_domain) + "/?id=" + id + "&name="
            + ((mPreviewName != null) ? mPreviewName : mMediaName);

    /*
     * message subject and text
     */
    String emailSubject, emailText, twitterText;

    if (MediaScanner.isPhoto(mMediaPath)) {
        emailSubject = resources.getString(R.string.emailSubjectPhoto);
        emailText = resources.getString(R.string.emailBodyPhotoPrefix) + link;
        twitterText = resources.getString(R.string.emailBodyPhotoPrefix) + link
                + resources.getString(R.string.twitterHashtagPhoto) + resources.getString(R.string.app_hashtag);
    } else if (MediaScanner.is3dMovie(mMediaPath)) {
        emailSubject = resources.getString(R.string.emailSubjectVideo);
        emailText = resources.getString(R.string.emailBodyVideoPrefix) + link;
        twitterText = resources.getString(R.string.emailBodyVideoPrefix) + link
                + resources.getString(R.string.twitterHashtagVideo) + resources.getString(R.string.app_hashtag);
    } else //if(MediaScanner.is2dMovie(mMediaPath))
    {
        emailSubject = resources.getString(R.string.emailSubjectVideo2d);
        emailText = resources.getString(R.string.emailBodyVideoPrefix2d) + link;
        twitterText = resources.getString(R.string.emailBodyVideoPrefix2d) + link
                + resources.getString(R.string.twitterHashtagVideo) + resources.getString(R.string.app_hashtag);
    }

    Intent emailIntent = new Intent();
    emailIntent.setAction(Intent.ACTION_SEND);
    // Native email client doesn't currently support HTML, but it doesn't hurt to try in case they fix it
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
    emailIntent.putExtra(Intent.EXTRA_TEXT, emailText);
    //emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(resources.getString(R.string.share_email_native)));
    emailIntent.setType("message/rfc822");

    PackageManager pm = getPackageManager();
    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType("text/plain");

    Intent openInChooser = Intent.createChooser(emailIntent, resources.getString(R.string.share_chooser_text));

    List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
    List<LabeledIntent> intentList = new ArrayList<LabeledIntent>();
    for (int i = 0; i < resInfo.size(); i++) {
        // Extract the label, append it, and repackage it in a LabeledIntent
        ResolveInfo ri = resInfo.get(i);
        String packageName = ri.activityInfo.packageName;
        if (packageName.contains("android.email")) {
            emailIntent.setPackage(packageName);
        } else if (packageName.contains("twitter") || packageName.contains("facebook")
                || packageName.contains("whatsapp") || packageName.contains("tencent.mm") || //wechat
                packageName.contains("line") || packageName.contains("skype") || packageName.contains("viber")
                || packageName.contains("kik") || packageName.contains("sgiggle") || //tango
                packageName.contains("kakao") || packageName.contains("telegram")
                || packageName.contains("nimbuzz") || packageName.contains("hike")
                || packageName.contains("imoim") || packageName.contains("bbm")
                || packageName.contains("threema") || packageName.contains("mms")
                || packageName.contains("android.apps.messaging") || //google messenger
                packageName.contains("android.talk") || //google hangouts
                packageName.contains("android.gm")) {
            Intent intent = new Intent();
            intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
            intent.setAction(Intent.ACTION_SEND);
            intent.setType("text/plain");
            if (packageName.contains("twitter")) {
                intent.putExtra(Intent.EXTRA_TEXT, twitterText);
            } else if (packageName.contains("facebook")) {
                /*
                 * the warning below is wrong! at least on GS5, Facebook client does take
                 * our text, however it seems it takes only the first hyperlink in the
                 * text.
                 * 
                 * Warning: Facebook IGNORES our text. They say "These fields are intended 
                 * for users to express themselves. Pre-filling these fields erodes the 
                 * authenticity of the user voice."
                 * One workaround is to use the Facebook SDK to post, but that doesn't 
                 * allow the user to choose how they want to share. We can also make a 
                 * custom landing page, and the link will show the <meta content ="..."> 
                 * text from that page with our link in Facebook.
                 */
                intent.putExtra(Intent.EXTRA_TEXT, link);
            } else if (packageName.contains("tencent.mm")) //wechat
            {
                /*
                 * wechat appears to do this similar to Facebook
                 */
                intent.putExtra(Intent.EXTRA_TEXT, link);
            } else if (packageName.contains("android.gm")) {
                // If Gmail shows up twice, try removing this else-if clause and the reference to "android.gm" above
                intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
                intent.putExtra(Intent.EXTRA_TEXT, emailText);
                //intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(resources.getString(R.string.share_email_gmail)));
                intent.setType("message/rfc822");
            } else if (packageName.contains("android.apps.docs")) {
                /*
                 * google drive - no reason to send link to it
                 */
                continue;
            } else {
                intent.putExtra(Intent.EXTRA_TEXT, emailText);
            }

            intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon));
        }
    }

    /*
     *  create "Copy Link To Clipboard" Intent
     */
    Intent clipboardIntent = new Intent(this, CopyToClipboardActivity.class);
    clipboardIntent.setData(Uri.parse(link));
    intentList.add(new LabeledIntent(clipboardIntent, getPackageName(),
            getResources().getString(R.string.clipboard_activity_name), R.drawable.ic_copy_link));

    // convert intentList to array
    LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]);

    openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
    startActivity(openInChooser);
}