final void addContact( String[] names, String[] phoneNumbers, String[] emails, String note, String address, String org, String title) { // Only use the first name in the array, if present. Intent intent = new Intent(Contacts.Intents.Insert.ACTION, Contacts.People.CONTENT_URI); putExtra(intent, Contacts.Intents.Insert.NAME, names != null ? names[0] : null); int phoneCount = Math.min((phoneNumbers != null) ? phoneNumbers.length : 0, Contents.PHONE_KEYS.length); for (int x = 0; x < phoneCount; x++) { putExtra(intent, Contents.PHONE_KEYS[x], phoneNumbers[x]); } int emailCount = Math.min((emails != null) ? emails.length : 0, Contents.EMAIL_KEYS.length); for (int x = 0; x < emailCount; x++) { putExtra(intent, Contents.EMAIL_KEYS[x], emails[x]); } putExtra(intent, Contacts.Intents.Insert.NOTES, note); putExtra(intent, Contacts.Intents.Insert.POSTAL, address); putExtra(intent, Contacts.Intents.Insert.COMPANY, org); putExtra(intent, Contacts.Intents.Insert.JOB_TITLE, title); launchIntent(intent); }
/** * Do a geo search using the address as the query. * * @param address The address to find * @param title An optional title, e.g. the name of the business at this address */ final void searchMap(String address, CharSequence title) { String query = address; if (title != null && title.length() > 0) { query += " (" + title + ')'; } launchIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=" + Uri.encode(query)))); }
final void sendSMSFromUri(String uri, String body) { Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri)); putExtra(intent, "sms_body", body); // Exit the app once the SMS is sent intent.putExtra("compose_mode", true); launchIntent(intent); }
@Override public void onClick(DialogInterface dialogInterface, int which) { launchIntent( new Intent( Intent.ACTION_VIEW, Uri.parse(MARKET_URI_PREFIX + GOOGLE_SHOPPER_PACKAGE + MARKET_REFERRER_SUFFIX))); }
final void wifiConnect(WifiParsedResult wifiResult) { Intent intent = new Intent(Intents.WifiConnect.ACTION); intent.setClassName(activity, WifiActivity.class.getName()); putExtra(intent, Intents.WifiConnect.SSID, wifiResult.getSsid()); putExtra(intent, Intents.WifiConnect.TYPE, wifiResult.getNetworkEncryption()); putExtra(intent, Intents.WifiConnect.PASSWORD, wifiResult.getPassword()); launchIntent(intent); }
final void openBookSearch(String isbn) { Uri uri = Uri.parse( "http://books.google." + LocaleManager.getBookSearchCountryTLD(activity) + "/books?vid=isbn" + isbn); launchIntent(new Intent(Intent.ACTION_VIEW, uri)); }
// Uses the mobile-specific version of Product Search, which is formatted for small screens. final void openProductSearch(String upc) { Uri uri = Uri.parse( "http://www.google." + LocaleManager.getProductSearchCountryTLD(activity) + "/m/products?q=" + upc + "&source=zxing"); launchIntent(new Intent(Intent.ACTION_VIEW, uri)); }
// Use public Intent fields rather than private GMail app fields to specify subject and body. final void sendEmailFromUri(String uri, String email, String subject, String body) { Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse(uri)); if (email != null) { intent.putExtra(Intent.EXTRA_EMAIL, new String[] {email}); } putExtra(intent, Intent.EXTRA_SUBJECT, subject); putExtra(intent, Intent.EXTRA_TEXT, body); intent.setType("text/plain"); launchIntent(intent); }
final void getDirections(double latitude, double longitude) { launchIntent( new Intent( Intent.ACTION_VIEW, Uri.parse( "http://maps.google." + LocaleManager.getCountryTLD(activity) + "/maps?f=d&daddr=" + latitude + ',' + longitude))); }
final void sendMMSFromUri(String uri, String subject, String body) { Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri)); // The Messaging app needs to see a valid subject or else it will treat this an an SMS. if (subject == null || subject.isEmpty()) { putExtra(intent, "subject", activity.getString(R.string.msg_default_mms_subject)); } else { putExtra(intent, "subject", subject); } putExtra(intent, "sms_body", body); intent.putExtra("compose_mode", true); launchIntent(intent); }
final void openURL(String url) { // Strangely, some Android browsers don't seem to register to handle HTTP:// or HTTPS://. // Lower-case these as it should always be OK to lower-case these schemes. if (url.startsWith("HTTP://")) { url = "http" + url.substring(4); } else if (url.startsWith("HTTPS://")) { url = "https" + url.substring(5); } Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); try { launchIntent(intent); } catch (ActivityNotFoundException ignored) { Log.w(TAG, "Nothing available to handle " + intent); } }
final void sendEmail(String[] to, String[] cc, String[] bcc, String subject, String body) { Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:")); if (to != null && to.length != 0) { intent.putExtra(Intent.EXTRA_EMAIL, to); } if (cc != null && cc.length != 0) { intent.putExtra(Intent.EXTRA_CC, cc); } if (bcc != null && bcc.length != 0) { intent.putExtra(Intent.EXTRA_BCC, bcc); } putExtra(intent, Intent.EXTRA_SUBJECT, subject); putExtra(intent, Intent.EXTRA_TEXT, body); intent.setType("text/plain"); launchIntent(intent); }
/** * Sends an intent to create a new calendar event by prepopulating the Add Event UI. Older * versions of the system have a bug where the event title will not be filled out. * * @param summary A description of the event * @param start The start time as yyyyMMdd or yyyyMMdd'T'HHmmss or yyyyMMdd'T'HHmmss'Z' * @param end The end time as yyyyMMdd or yyyyMMdd'T'HHmmss or yyyyMMdd'T'HHmmss'Z' * @param location a text description of the event location * @param description a text description of the event itself */ final void addCalendarEvent( String summary, String start, String end, String location, String description) { Intent intent = new Intent(Intent.ACTION_EDIT); intent.setType("vnd.android.cursor.item/event"); intent.putExtra("beginTime", calculateMilliseconds(start)); if (start.length() == 8) { intent.putExtra("allDay", true); } if (end == null) { end = start; } intent.putExtra("endTime", calculateMilliseconds(end)); intent.putExtra("title", summary); intent.putExtra("eventLocation", location); intent.putExtra("description", description); launchIntent(intent); }
final void openURL(String url) { launchIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); }
final void webSearch(String query) { Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra("query", query); launchIntent(intent); }
final void addContact( String[] names, String pronunciation, String[] phoneNumbers, String[] phoneTypes, String[] emails, String[] emailTypes, String note, String instantMessenger, String address, String addressType, String org, String title, String url, String birthday) { // Only use the first name in the array, if present. Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT, ContactsContract.Contacts.CONTENT_URI); intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE); putExtra(intent, ContactsContract.Intents.Insert.NAME, names != null ? names[0] : null); putExtra(intent, ContactsContract.Intents.Insert.PHONETIC_NAME, pronunciation); int phoneCount = Math.min(phoneNumbers != null ? phoneNumbers.length : 0, Contents.PHONE_KEYS.length); for (int x = 0; x < phoneCount; x++) { putExtra(intent, Contents.PHONE_KEYS[x], phoneNumbers[x]); if (phoneTypes != null && x < phoneTypes.length) { int type = toPhoneContractType(phoneTypes[x]); if (type >= 0) { intent.putExtra(Contents.PHONE_TYPE_KEYS[x], type); } } } int emailCount = Math.min(emails != null ? emails.length : 0, Contents.EMAIL_KEYS.length); for (int x = 0; x < emailCount; x++) { putExtra(intent, Contents.EMAIL_KEYS[x], emails[x]); if (emailTypes != null && x < emailTypes.length) { int type = toEmailContractType(emailTypes[x]); if (type >= 0) { intent.putExtra(Contents.EMAIL_TYPE_KEYS[x], type); } } } // No field for URL, birthday; use notes StringBuilder aggregatedNotes = new StringBuilder(); for (String aNote : new String[] {url, birthday, note}) { if (aNote != null) { if (aggregatedNotes.length() > 0) { aggregatedNotes.append('\n'); } aggregatedNotes.append(aNote); } } if (aggregatedNotes.length() > 0) { putExtra(intent, ContactsContract.Intents.Insert.NOTES, aggregatedNotes.toString()); } putExtra(intent, ContactsContract.Intents.Insert.IM_HANDLE, instantMessenger); putExtra(intent, ContactsContract.Intents.Insert.POSTAL, address); if (addressType != null) { int type = toAddressContractType(addressType); if (type >= 0) { intent.putExtra(ContactsContract.Intents.Insert.POSTAL_TYPE, type); } } putExtra(intent, ContactsContract.Intents.Insert.COMPANY, org); putExtra(intent, ContactsContract.Intents.Insert.JOB_TITLE, title); launchIntent(intent); }
final void searchBookContents(String isbnOrUrl) { Intent intent = new Intent(Intents.SearchBookContents.ACTION); intent.setClassName(activity, SearchBookContentsActivity.class.getName()); putExtra(intent, Intents.SearchBookContents.ISBN, isbnOrUrl); launchIntent(intent); }
final void addContact( String[] names, String[] nicknames, String pronunciation, String[] phoneNumbers, String[] phoneTypes, String[] emails, String[] emailTypes, String note, String instantMessenger, String address, String addressType, String org, String title, String[] urls, String birthday, String[] geo) { // Only use the first name in the array, if present. Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT, ContactsContract.Contacts.CONTENT_URI); intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE); putExtra(intent, ContactsContract.Intents.Insert.NAME, names != null ? names[0] : null); putExtra(intent, ContactsContract.Intents.Insert.PHONETIC_NAME, pronunciation); int phoneCount = Math.min(phoneNumbers != null ? phoneNumbers.length : 0, Contents.PHONE_KEYS.length); for (int x = 0; x < phoneCount; x++) { putExtra(intent, Contents.PHONE_KEYS[x], phoneNumbers[x]); if (phoneTypes != null && x < phoneTypes.length) { int type = toPhoneContractType(phoneTypes[x]); if (type >= 0) { intent.putExtra(Contents.PHONE_TYPE_KEYS[x], type); } } } int emailCount = Math.min(emails != null ? emails.length : 0, Contents.EMAIL_KEYS.length); for (int x = 0; x < emailCount; x++) { putExtra(intent, Contents.EMAIL_KEYS[x], emails[x]); if (emailTypes != null && x < emailTypes.length) { int type = toEmailContractType(emailTypes[x]); if (type >= 0) { intent.putExtra(Contents.EMAIL_TYPE_KEYS[x], type); } } } ArrayList<ContentValues> data = new ArrayList<ContentValues>(); if (urls != null) { for (String url : urls) { if (url != null && !url.isEmpty()) { ContentValues row = new ContentValues(2); row.put( ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE); row.put(ContactsContract.CommonDataKinds.Website.URL, url); data.add(row); break; } } } if (birthday != null) { ContentValues row = new ContentValues(3); row.put( ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE); row.put( ContactsContract.CommonDataKinds.Event.TYPE, ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY); row.put(ContactsContract.CommonDataKinds.Event.START_DATE, birthday); data.add(row); } if (nicknames != null) { for (String nickname : nicknames) { if (nickname != null && !nickname.isEmpty()) { ContentValues row = new ContentValues(3); row.put( ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE); row.put( ContactsContract.CommonDataKinds.Nickname.TYPE, ContactsContract.CommonDataKinds.Nickname.TYPE_DEFAULT); row.put(ContactsContract.CommonDataKinds.Nickname.NAME, nickname); data.add(row); break; } } } if (!data.isEmpty()) { intent.putParcelableArrayListExtra(ContactsContract.Intents.Insert.DATA, data); } StringBuilder aggregatedNotes = new StringBuilder(); if (note != null) { aggregatedNotes.append('\n').append(note); } if (geo != null) { aggregatedNotes.append('\n').append(geo[0]).append(',').append(geo[1]); } if (aggregatedNotes.length() > 0) { // Remove extra leading '\n' putExtra(intent, ContactsContract.Intents.Insert.NOTES, aggregatedNotes.substring(1)); } putExtra(intent, ContactsContract.Intents.Insert.IM_HANDLE, instantMessenger); putExtra(intent, ContactsContract.Intents.Insert.POSTAL, address); if (addressType != null) { int type = toAddressContractType(addressType); if (type >= 0) { intent.putExtra(ContactsContract.Intents.Insert.POSTAL_TYPE, type); } } putExtra(intent, ContactsContract.Intents.Insert.COMPANY, org); putExtra(intent, ContactsContract.Intents.Insert.JOB_TITLE, title); launchIntent(intent); }
final void dialPhone(String phoneNumber) { launchIntent(new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phoneNumber))); }
/** * Do a geo search using the address as the query. * * @param address The address to find */ final void searchMap(String address) { launchIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=" + Uri.encode(address)))); }
final void openMap(String geoURI) { launchIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(geoURI))); }
final void dialPhoneFromUri(String uri) { launchIntent(new Intent(Intent.ACTION_DIAL, Uri.parse(uri))); }