diff options
author | tedchoc@chromium.org <tedchoc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-24 03:33:56 +0000 |
---|---|---|
committer | tedchoc@chromium.org <tedchoc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-24 03:33:56 +0000 |
commit | fd2594460c467d550522c48b6ec013b498bf683d (patch) | |
tree | bf2e1fcccd2eafcbd477a6999c801a2217135491 /chrome/android | |
parent | 0c1d59230ff24e20b8f0cb715b9196465c38a51d (diff) | |
download | chromium_src-fd2594460c467d550522c48b6ec013b498bf683d.zip chromium_src-fd2594460c467d550522c48b6ec013b498bf683d.tar.gz chromium_src-fd2594460c467d550522c48b6ec013b498bf683d.tar.bz2 |
Remove promo send email from tab android.
Move the functionality into helper that we can use for issuing android
intents.
BUG=136785
TEST=run 'make browser'
Review URL: https://chromiumcodereview.appspot.com/10809061
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148036 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/android')
-rw-r--r-- | chrome/android/java/src/org/chromium/chrome/browser/IntentHelper.java | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/IntentHelper.java b/chrome/android/java/src/org/chromium/chrome/browser/IntentHelper.java new file mode 100644 index 0000000..89975c6 --- /dev/null +++ b/chrome/android/java/src/org/chromium/chrome/browser/IntentHelper.java @@ -0,0 +1,69 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.chrome.browser; + +import android.accounts.Account; +import android.accounts.AccountManager; +import android.content.Context; +import android.content.Intent; +import android.text.Html; +import android.text.TextUtils; +import android.util.Patterns; + +import org.chromium.base.CalledByNative; + +import java.util.HashSet; +import java.util.Set; +import java.util.regex.Pattern; + +/** + * Helper for issuing intents to the android framework. + */ +public abstract class IntentHelper { + + private IntentHelper() {} + + /** + * Triggers a send email intent. If no application has registered to receive these intents, + * this will fail silently. + * + * @param context The context for issuing the intent. + * @param email The email address to send to. + * @param subject The subject of the email. + * @param body The body of the email. + * @param chooserTitle The title of the activity chooser. + */ + @CalledByNative + static void sendEmail( + Context context, String email, String subject, String body, String chooserTitle) { + Set<String> possibleEmails = new HashSet<String>(); + + if (!TextUtils.isEmpty(email)) { + possibleEmails.add(email); + } else { + Pattern emailPattern = Patterns.EMAIL_ADDRESS; + Account[] accounts = AccountManager.get(context).getAccounts(); + for (Account account : accounts) { + if (emailPattern.matcher(account.name).matches()) { + possibleEmails.add(account.name); + } + } + } + + Intent send = new Intent(Intent.ACTION_SEND); + send.setType("message/rfc822"); + if (possibleEmails.size() != 0) { + send.putExtra(Intent.EXTRA_EMAIL, + possibleEmails.toArray(new String[possibleEmails.size()])); + } + send.putExtra(Intent.EXTRA_SUBJECT, subject); + send.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body)); + try { + context.startActivity(Intent.createChooser(send, chooserTitle)); + } catch (android.content.ActivityNotFoundException ex) { + // If no app handles it, do nothing. + } + } +} |