Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(639)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/IntentHelper.java

Issue 10809061: Remove promo send email from tab android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Resolve review comments. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/android/intent_helper.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/IntentHelper.java
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 0000000000000000000000000000000000000000..89975c68a6bfed4cbaed81f127b5597822f55718
--- /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.
+ }
+ }
+}
« no previous file with comments | « no previous file | chrome/browser/android/intent_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698