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.groksolutions.grok.mobile.GrokActivity.java

/**
 * Send user feedback via email with pre-populated email address, screen capture and optional
 * upload identifier//from  w w  w. ja  v a 2  s .c o  m
 * <p/>
 *
 * @param uploadId the identifier of the uploaded information; null if none
 */
protected void emailFeedback(final CharSequence uploadId) {
    Intent feedbackIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    feedbackIntent.putExtra(Intent.EXTRA_EMAIL,
            new String[] { getResources().getText(R.string.feedback_email_address).toString() });
    String subject = getResources().getText(R.string.feedback_email_subject).toString();

    feedbackIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    feedbackIntent.setType("message/rfc822");
    ArrayList<Uri> uris = new ArrayList<Uri>();
    uris.add(takeScreenCapture(true));
    if (uploadId != null) {
        uris.add(writeTextFileToSend(uploadId.toString()));
    }
    feedbackIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);

    startActivity(Intent.createChooser(feedbackIntent, getResources().getText(R.string.title_feedback)));
}

From source file:com.example.android.recyclingbanks.MainActivity.java

/**
 * composes an email, strictly for email apps.  This version takes no attachments
 *///from  w ww.jav  a2  s . co m
public void composeEmail(String[] addresses, String subject) {
    Intent intent = new Intent(Intent.ACTION_SENDTO);
    intent.setData(Uri.parse("mailto:")); // only email apps should handle this
    intent.putExtra(Intent.EXTRA_EMAIL, "sam.stratford@gmail.com");//addresses);
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
}

From source file:com.xorcode.andtweet.TweetListActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    super.onContextItemSelected(item);
    AdapterView.AdapterContextMenuInfo info;
    try {//from  ww w  . j  av a2 s . co  m
        info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    } catch (ClassCastException e) {
        Log.e(TAG, "bad menuInfo", e);
        return false;
    }

    mCurrentId = info.id;

    Uri uri;
    Cursor c;

    switch (item.getItemId()) {
    case CONTEXT_MENU_ITEM_REPLY:
        uri = ContentUris.withAppendedId(Tweets.CONTENT_URI, info.id);
        c = getContentResolver().query(uri, new String[] { Tweets._ID, Tweets.AUTHOR_ID }, null, null, null);
        try {
            c.moveToFirst();
            String reply = "@" + c.getString(c.getColumnIndex(Tweets.AUTHOR_ID)) + " ";
            long replyId = c.getLong(c.getColumnIndex(Tweets._ID));
            mTweetEditor.startEditing(reply, replyId);
        } catch (Exception e) {
            Log.e(TAG, "onContextItemSelected: " + e.toString());
            return false;
        } finally {
            if (c != null && !c.isClosed())
                c.close();
        }
        return true;

    case CONTEXT_MENU_ITEM_RETWEET:
        uri = ContentUris.withAppendedId(Tweets.CONTENT_URI, info.id);
        c = getContentResolver().query(uri, new String[] { Tweets._ID, Tweets.AUTHOR_ID, Tweets.MESSAGE }, null,
                null, null);
        try {
            c.moveToFirst();

            StringBuilder message = new StringBuilder();
            String reply = "RT @" + c.getString(c.getColumnIndex(Tweets.AUTHOR_ID)) + " ";
            message.append(reply);
            CharSequence text = c.getString(c.getColumnIndex(Tweets.MESSAGE));
            int len = 140 - reply.length() - 3;
            if (text.length() < len) {
                len = text.length();
            }
            message.append(text, 0, len);
            if (message.length() == 137) {
                message.append("...");
            }
            mTweetEditor.startEditing(message.toString(), 0);
        } catch (Exception e) {
            Log.e(TAG, "onContextItemSelected: " + e.toString());
            return false;
        } finally {
            if (c != null && !c.isClosed())
                c.close();
        }
        return true;

    case CONTEXT_MENU_ITEM_DESTROY_STATUS:
        sendCommand(new CommandData(CommandEnum.DESTROY_STATUS, mCurrentId));
        return true;

    case CONTEXT_MENU_ITEM_FAVORITE:
        sendCommand(new CommandData(CommandEnum.CREATE_FAVORITE, mCurrentId));
        return true;

    case CONTEXT_MENU_ITEM_DESTROY_FAVORITE:
        sendCommand(new CommandData(CommandEnum.DESTROY_FAVORITE, mCurrentId));
        return true;

    case CONTEXT_MENU_ITEM_SHARE:
        uri = ContentUris.withAppendedId(Tweets.CONTENT_URI, info.id);
        c = getContentResolver().query(uri, new String[] { Tweets._ID, Tweets.AUTHOR_ID, Tweets.MESSAGE }, null,
                null, null);
        try {
            c.moveToFirst();

            StringBuilder subject = new StringBuilder();
            StringBuilder text = new StringBuilder();
            String message = c.getString(c.getColumnIndex(Tweets.MESSAGE));

            subject.append(getText(R.string.button_create_tweet));
            subject.append(" - " + message);
            int maxlength = 80;
            if (subject.length() > maxlength) {
                subject.setLength(maxlength);
                // Truncate at the last space
                subject.setLength(subject.lastIndexOf(" "));
                subject.append("...");
            }

            text.append(message);
            text.append("\n-- \n" + c.getString(c.getColumnIndex(Tweets.AUTHOR_ID)));
            text.append("\n URL: " + "http://twitter.com/" + c.getString(c.getColumnIndex(Tweets.AUTHOR_ID))
                    + "/status/" + c.getString(c.getColumnIndex(Tweets._ID)));

            Intent share = new Intent(android.content.Intent.ACTION_SEND);
            share.setType("text/plain");
            share.putExtra(Intent.EXTRA_SUBJECT, subject.toString());
            share.putExtra(Intent.EXTRA_TEXT, text.toString());
            startActivity(Intent.createChooser(share, getText(R.string.menu_item_share)));

        } catch (Exception e) {
            Log.e(TAG, "onContextItemSelected: " + e.toString());
            return false;
        } finally {
            if (c != null && !c.isClosed())
                c.close();
        }
        return true;

    case CONTEXT_MENU_ITEM_UNFOLLOW:
    case CONTEXT_MENU_ITEM_BLOCK:
    case CONTEXT_MENU_ITEM_DIRECT_MESSAGE:
    case CONTEXT_MENU_ITEM_PROFILE:
        Toast.makeText(this, R.string.unimplemented, Toast.LENGTH_SHORT).show();
        return true;
    }
    return false;
}

From source file:com.nxp.nfc_demo.activities.MainActivity.java

public void sendFeedback() {
    Intent intent = new Intent(Intent.ACTION_SENDTO);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_SUBJECT, this.getString(R.string.email_titel_feedback));
    intent.putExtra(Intent.EXTRA_TEXT,/*from w  w  w .j  a  v  a2 s. c  o  m*/
            "Android Version: " + android.os.Build.VERSION.RELEASE + "\nManufacurer: "
                    + android.os.Build.MANUFACTURER + "\nModel: " + android.os.Build.MODEL + "\nBrand: "
                    + android.os.Build.BRAND + "\nDisplay: " + android.os.Build.DISPLAY + "\nProduct: "
                    + android.os.Build.PRODUCT + "\nIncremental: " + android.os.Build.VERSION.INCREMENTAL);
    intent.setData(Uri.parse(this.getString(R.string.support_email)));
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    this.startActivity(intent);
}

From source file:com.example.android.pharmacyinventory.EditorActivity.java

@Override
public void onLoadFinished(Loader<Cursor> loader, final Cursor cursor) {
    // Bail early if the cursor is null or there is less than 1 row in the cursor
    if (cursor == null || cursor.getCount() < 1) {
        return;/*from w w  w .j  av  a2  s  .c  o m*/
    }

    // Proceed with moving to the first row of the cursor and reading data from it
    // (This should be the only row in the cursor)
    if (cursor.moveToFirst()) {
        // Find the columns of drug attributes that we're interested in
        int nameColumnIndex = cursor.getColumnIndex(DrugContract.DrugEntry.COLUMN_DRUG_NAME);
        int quantityColumnIndex = cursor.getColumnIndex(DrugContract.DrugEntry.COLUMN_DRUG_QUANTITY);
        int priceColumnIndex = cursor.getColumnIndex(DrugContract.DrugEntry.COLUMN_DRUG_PRICE);
        int imageColumnIndex = cursor.getColumnIndex(DrugContract.DrugEntry.COLUMN_DRUG_IMAGE);

        // Extract out the value from the Cursor for the given column index
        String name = cursor.getString(nameColumnIndex);
        int quantity = cursor.getInt(quantityColumnIndex);
        Double price = cursor.getDouble(priceColumnIndex);
        String picture = cursor.getString(imageColumnIndex);

        // Update the views on the screen with the values from the database
        mNameEditText.setText(name);
        mQuantityText.setText(Integer.toString(quantity));
        mPriceEditText.setText(Double.toString(price));
        mDrugImage.setImageURI(Uri.parse(picture));
    }

    orderButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Get the Uri for the current drug
            int IdColumnIndex = cursor.getColumnIndex(DrugContract.DrugEntry._ID);
            final long itemId = cursor.getLong(IdColumnIndex);
            Uri mCurrentDrugUri = ContentUris.withAppendedId(DrugContract.DrugEntry.CONTENT_URI, itemId);

            // Find the columns of drug attributes that we're interested in
            int nameColumnIndex = cursor.getColumnIndex(DrugContract.DrugEntry.COLUMN_DRUG_NAME);

            // Read the Drug attributes from the Cursor for the current drug
            String name = cursor.getString(nameColumnIndex);

            // Read the drug name to use in subject line
            String subjectLine = "Need to order: " + name;

            Intent intent = new Intent(Intent.ACTION_SENDTO);
            intent.setData(Uri.parse("mailto:")); // only email apps should handle this
            intent.putExtra(Intent.EXTRA_EMAIL, "orders@gmail.com");
            intent.putExtra(Intent.EXTRA_SUBJECT, subjectLine);
            if (intent.resolveActivity(getPackageManager()) != null) {
                startActivity(intent);
            }
        }
    });

}

From source file:com.digipom.manteresting.android.fragment.NailFragment.java

private boolean handleMenuItemSelected(int listItemPosition, int itemId) {
    listItemPosition -= listView.getHeaderViewsCount();

    if (listItemPosition >= 0 && listItemPosition < nailAdapter.getCount()) {
        switch (itemId) {
        case R.id.share:
            try {
                final Cursor cursor = (Cursor) nailAdapter.getItem(listItemPosition);

                if (cursor != null && !cursor.isClosed()) {
                    final int nailId = cursor.getInt(cursor.getColumnIndex(Nails.NAIL_ID));
                    final JSONObject nailJson = new JSONObject(
                            cursor.getString(cursor.getColumnIndex(Nails.NAIL_JSON)));

                    final Uri uri = MANTERESTING_SERVER.buildUpon().appendPath("nail")
                            .appendPath(String.valueOf(nailId)).build();
                    String description = nailJson.getString("description");

                    if (description.length() > 100) {
                        description = description.substring(0, 97) + '';
                    }/*from   w  ww.  ja  va 2  s . c  o m*/

                    final String user = nailJson.getJSONObject("user").getString("username");
                    final String category = nailJson.getJSONObject("workbench").getJSONObject("category")
                            .getString("title");

                    final Intent shareIntent = new Intent(Intent.ACTION_SEND);
                    shareIntent.setType("text/plain");
                    shareIntent.putExtra(Intent.EXTRA_TEXT, description + ' ' + uri.toString());
                    shareIntent.putExtra(Intent.EXTRA_SUBJECT,
                            String.format(getResources().getString(R.string.shareSubject), user, category));
                    try {
                        startActivity(Intent.createChooser(shareIntent, getText(R.string.share)));
                    } catch (ActivityNotFoundException e) {
                        new AlertDialog.Builder(getActivity()).setMessage(R.string.noShareApp).show();
                    }
                }
            } catch (Exception e) {
                if (LoggerConfig.canLog(Log.WARN)) {
                    Log.w(TAG, "Could not share nail at position " + listItemPosition + " with id " + itemId);
                }
            }

            return true;
        default:
            return false;
        }
    } else {
        return false;
    }
}

From source file:com.linkbubble.MainApplication.java

public static boolean handleBubbleAction(final Context context, BubbleAction action, final String urlAsString,
        long totalTrackedLoadTime) {
    Constant.ActionType actionType = Settings.get().getConsumeBubbleActionType(action);
    boolean result = false;
    if (actionType == Constant.ActionType.Share) {
        String consumePackageName = Settings.get().getConsumeBubblePackageName(action);
        CrashTracking.log("MainApplication.handleBubbleAction() action:" + action.toString()
                + ", consumePackageName:" + consumePackageName);
        String consumeName = Settings.get().getConsumeBubbleActivityClassName(action);

        if (consumePackageName.equals(BuildConfig.APPLICATION_ID)
                && consumeName.equals(Constant.SHARE_PICKER_NAME)) {
            AlertDialog alertDialog = ActionItem.getShareAlert(context, false,
                    new ActionItem.OnActionItemSelectedListener() {
                        @Override
                        public void onSelected(ActionItem actionItem) {
                            Intent intent = new Intent(Intent.ACTION_SEND);
                            intent.setType("text/plain");
                            intent.setClassName(actionItem.mPackageName, actionItem.mActivityClassName);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            intent.putExtra(Intent.EXTRA_TEXT, urlAsString);
                            String title = MainApplication.sTitleHashMap != null
                                    ? MainApplication.sTitleHashMap.get(urlAsString)
                                    : null;
                            if (title != null) {
                                intent.putExtra(Intent.EXTRA_SUBJECT, title);
                            }//from  www  .ja  v a2  s.  c  o m
                            context.startActivity(intent);
                        }
                    });
            Util.showThemedDialog(alertDialog);
            return true;
        }

        // TODO: Retrieve the class name below from the app in case Twitter ever change it.
        Intent intent = Util.getSendIntent(consumePackageName, consumeName, urlAsString);
        try {
            context.startActivity(intent);
            if (totalTrackedLoadTime > -1) {
                Settings.get().trackLinkLoadTime(totalTrackedLoadTime, Settings.LinkLoadType.ShareToOtherApp,
                        urlAsString);
            }
            result = true;
        } catch (ActivityNotFoundException ex) {
            Toast.makeText(context, R.string.consume_activity_not_found, Toast.LENGTH_LONG).show();
        } catch (SecurityException ex) {
            Toast.makeText(context, R.string.consume_activity_security_exception, Toast.LENGTH_SHORT).show();
        }
    } else if (actionType == Constant.ActionType.View) {
        String consumePackageName = Settings.get().getConsumeBubblePackageName(action);
        CrashTracking.log("MainApplication.handleBubbleAction() action:" + action.toString()
                + ", consumePackageName:" + consumePackageName);
        result = MainApplication.loadIntent(context, consumePackageName,
                Settings.get().getConsumeBubbleActivityClassName(action), urlAsString, -1, true);
    } else if (action == BubbleAction.Close || action == BubbleAction.BackButton) {
        CrashTracking.log("MainApplication.handleBubbleAction() action:" + action.toString());
        result = true;
    }

    if (result) {
        boolean hapticFeedbackEnabled = android.provider.Settings.System.getInt(context.getContentResolver(),
                android.provider.Settings.System.HAPTIC_FEEDBACK_ENABLED, 0) != 0;
        if (hapticFeedbackEnabled && action != BubbleAction.BackButton) {
            Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
            if (vibrator.hasVibrator()) {
                vibrator.vibrate(10);
            }
        }
    }

    return result;
}

From source file:com.nghianh.giaitriviet.activity.MainActivity.java

private void showInvite() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Please chose one method:").setCancelable(true)
            .setPositiveButton("Send message", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();//  www.  ja  v  a 2 s  .  c  om
                    try {
                        Intent i = new Intent(Intent.ACTION_SEND);
                        i.setType("text/plain");
                        i.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name));
                        String sAux = "\nLet me recommend you this application\n\n";
                        sAux = sAux
                                + "https://play.google.com/store/apps/details?id=com.nghianh.giaitriviet \n\n";
                        i.putExtra(Intent.EXTRA_TEXT, sAux);
                        startActivity(Intent.createChooser(i, "Please choose one"));
                    } catch (Exception e) {
                        //e.toString();
                    }
                }
            }).setNeutralButton("Send mail", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                    onInviteClicked();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:aerizostudios.com.cropshop.MainActivity.java

public void share_whatsapp(View v) {
    try {//from  ww w  .j  a  va  2s .c o  m
        Intent i = new Intent(Intent.ACTION_SEND);
        i.setType("text/plain");
        i.setPackage("com.whatsapp");
        i.putExtra(Intent.EXTRA_SUBJECT, "CROP SHOP");
        String sAux = "\nHey friends, Check out this COOL APP - CropShop - No Crop for Whatsapp and"
                + " Instagram. This app helps you post images on Whatsapp and Instagram without any need "
                + "of cropping them. It also adds Blur Effect to the Photos like Iphone and also"
                + " Instagram filters." + "This app allows you to share the photos"
                + " directly to Instagram,Facebook and Whatsapp from the App.\n"
                + "Download this app from the play store.\n";
        sAux = sAux + "https://play.google.com/store/apps/details?id=aerizostudios.com.cropshop \n\n";
        i.putExtra(Intent.EXTRA_TEXT, sAux);
        startActivity(i);
    } catch (Exception e) {
        Intent check = new Intent(Intent.ACTION_VIEW);
        check.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        check.setData(Uri.parse("market://details?id=" + "com.whatsapp"));
        startActivity(check);
    }
}

From source file:com.quarterfull.newsAndroid.NewsDetailActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    RssItem rssItem = rssItems.get(currentPosition);

    switch (item.getItemId()) {
    case android.R.id.home:
        onBackPressed();/*from   w  ww  .jav  a  2 s.c  o  m*/
        return true;

    case R.id.action_read:
        markItemAsReadUnread(rssItem, !menuItem_Read.isChecked());
        UpdateActionBarIcons();
        pDelayHandler.DelayTimer();
        break;

    case R.id.action_starred:
        Boolean curState = rssItem.getStarred_temp();
        rssItem.setStarred_temp(!curState);
        dbConn.updateRssItem(rssItem);

        UpdateActionBarIcons();

        pDelayHandler.DelayTimer();
        break;

    case R.id.action_openInBrowser:
        NewsDetailFragment newsDetailFragment = getNewsDetailFragmentAtPosition(currentPosition);
        String link = newsDetailFragment.mWebView.getUrl();

        if (link.equals("about:blank"))
            link = rssItem.getLink();

        if (link.length() > 0) {
            if (isChromeDefaultBrowser() && mCustomTabsSupported) {
                mCustomTabsSession = getSession();
                CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(mCustomTabsSession);
                builder.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimaryDarkTheme));
                builder.setShowTitle(true);
                builder.setStartAnimations(this, R.anim.slide_in_right, R.anim.slide_out_left);
                builder.setExitAnimations(this, R.anim.slide_in_left, R.anim.slide_out_right);
                builder.build().launchUrl(this, Uri.parse(link));
            } else {
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
                startActivity(browserIntent);
            }
        }
        break;

    /*
    case R.id.action_sendSourceCode:
    String description = "";
    if(cursor != null)
    {
       cursor.moveToFirst();
       description = cursor.getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_BODY));
       cursor.close();
    }
            
            
    Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("message/rfc822");
    i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"david-dev@live.de"});
    i.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.email_sourceCode));
    //i.putExtra(Intent.EXTRA_TEXT   , rssFiles.get(currentPosition).getDescription());
    i.putExtra(Intent.EXTRA_TEXT   , description);
    try {
        startActivity(Intent.createChooser(i, getString(R.string.email_sendMail)));
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(NewsDetailActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
    }
    break;
     */

    case R.id.action_playPodcast:
        openPodcast(rssItem);
        break;

    case R.id.action_tts:
        TTSItem ttsItem = new TTSItem(rssItem.getId(), rssItem.getTitle(),
                rssItem.getTitle() + "\n\n " + Html.fromHtml(rssItem.getBody()).toString(),
                rssItem.getFeed().getFaviconUrl());
        openMediaItem(ttsItem);
        break;

    case R.id.action_ShareItem:

        String title = rssItem.getTitle();
        String content = rssItem.getLink();

        NewsDetailFragment fragment = getNewsDetailFragmentAtPosition(currentPosition);
        if (fragment != null) { // could be null if not instantiated yet
            if (!fragment.mWebView.getUrl().equals("about:blank")
                    && !fragment.mWebView.getUrl().trim().equals("")) {
                content = fragment.mWebView.getUrl();
                title = fragment.mWebView.getTitle();
            }
        }

        Intent share = new Intent(Intent.ACTION_SEND);
        share.setType("text/plain");
        //share.putExtra(Intent.EXTRA_SUBJECT, rssFiles.get(currentPosition).getTitle());
        //share.putExtra(Intent.EXTRA_TEXT, rssFiles.get(currentPosition).getLink());
        share.putExtra(Intent.EXTRA_SUBJECT, title);
        share.putExtra(Intent.EXTRA_TEXT, content);

        startActivity(Intent.createChooser(share, "Share Item"));
        break;

    }

    return super.onOptionsItemSelected(item);
}