Intent i = new Intent(Intent.ACTION_SEND); i.setType("message/rfc822"); i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient@example.com"}); i.putExtra(Intent.EXTRA_SUBJECT, "subject of email"); i.putExtra(Intent.EXTRA_TEXT , "body of email"); try { startActivity(Intent.createChooser(i, "Send mail...")); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show(); }
public static void addToPocket(Context context, String url, String tweetStatusId) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setPackage(PACKAGE); intent.setType(MIME_TYPE); intent.putExtra(Intent.EXTRA_TEXT, url); if (tweetStatusId != null && tweetStatusId.length() > 0) { intent.putExtra(EXTRA_TWEET_STATUS_ID, tweetStatusId); } intent.putExtra(EXTRA_SOURCE_PACKAGE, context.getPackageName()); context.startActivity(intent); }
List<Intent> intents = new ArrayList<>(); Intent galleryIntent = action == Intent.ACTION_GET_CONTENT ? new Intent(action) : new Intent(action, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); galleryIntent.setType("image/*"); List<ResolveInfo> listGallery = packageManager.queryIntentActivities(galleryIntent, 0); for (ResolveInfo res : listGallery) { Intent intent = new Intent(galleryIntent); intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name)); intent.setPackage(res.activityInfo.packageName); intents.add(intent);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE); intent.putExtra(ContactsContract.Intents.Insert.NAME, person.name); intent.putExtra(ContactsContract.Intents.Insert.PHONE, person.mobile); intent.putExtra(ContactsContract.Intents.Insert.EMAIL, person.email); String email = person.email; ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
Intent picMessageIntent = new Intent(android.content.Intent.ACTION_SEND); picMessageIntent.setType("image/jpeg"); File downloadedPic = new File( Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_DOWNLOADS), "q.jpeg"); picMessageIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(downloadedPic));
public void onClickWhatsApp(View view) { PackageManager pm=getPackageManager(); try { Intent waIntent = new Intent(Intent.ACTION_SEND); waIntent.setType("text/plain"); String text = "YOUR TEXT HERE"; PackageInfo info=pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA); //Check if package exists or not. If not then code //in catch block will be called waIntent.setPackage("com.whatsapp"); waIntent.putExtra(Intent.EXTRA_TEXT, text); startActivity(Intent.createChooser(waIntent, "Share with")); } catch (NameNotFoundException e) { Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT) .show(); } }
public Intent findTwitterClient() { final String[] twitterApps = { // package // name - nb installs (thousands) "com.twitter.android", // official - 10 000 "com.twidroid", // twidroid - 5 000 "com.handmark.tweetcaster", // Tweecaster - 5 000 "com.thedeck.android" }; // TweetDeck - 5 000 }; Intent tweetIntent = new Intent(); tweetIntent.setType("text/plain"); final PackageManager packageManager = getPackageManager(); List<ResolveInfo> list = packageManager.queryIntentActivities( tweetIntent, PackageManager.MATCH_DEFAULT_ONLY); for (int i = 0; i < twitterApps.length; i++) { for (ResolveInfo resolveInfo : list) { String p = resolveInfo.activityInfo.packageName; if (p != null && p.startsWith(twitterApps[i])) { tweetIntent.setPackage(p); return tweetIntent; } } } return null; }
Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("image/*"); Uri fileUri = FileProvider.getUriForFile(mContext, "com.myfileprovider", new File(mFilename)); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); shareIntent.putExtra(Intent.EXTRA_STREAM, fileUri); mContext.startActivity(Intent.createChooser(shareIntent, mChooserTitle));
public static void shareTrack(final Context context, long id) { try { Intent share = new Intent(Intent.ACTION_SEND); share.setType("audio/*"); share.putExtra(Intent.EXTRA_STREAM, getSongUri(context, id)); context.startActivity(Intent.createChooser(share, "Share")); } catch (Exception e) { e.printStackTrace(); } }
@Test public void startActivityForResultAndReceiveResult_shouldSendResponsesBackToActivity() throws Exception { TranscriptActivity activity = Robolectric.setupActivity(TranscriptActivity.class); activity.startActivityForResult(new Intent().setType("audio/*"), 123); activity.startActivityForResult(new Intent().setType("image/*"), 456); shadowOf(activity).receiveResult(new Intent().setType("image/*"), Activity.RESULT_OK, new Intent().setData(Uri.parse("content:foo"))); assertThat(activity.transcript) .containsExactly( "onActivityResult called with requestCode 456, resultCode -1, intent data content:foo"); }
Intent whatsappIntent = new Intent(Intent.ACTION_SEND); whatsappIntent.setType("text/plain"); whatsappIntent.setPackage("com.whatsapp"); whatsappIntent.putExtra(Intent.EXTRA_TEXT, "The text you wanted to share"); try { activity.startActivity(whatsappIntent); } catch (android.content.ActivityNotFoundException ex) { ToastHelper.MakeShortText("Whatsapp have not been installed."); }
Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT); getIntent.setType("image/*"); Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); pickIntent.setType("image/*"); Intent chooserIntent = Intent.createChooser(getIntent, "Select Image"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {pickIntent}); startActivityForResult(chooserIntent, PICK_IMAGE);
try { exportRealmFile = new File(getActivity().getExternalCacheDir(), "export.realm"); intent.setType("plain/text"); intent.putExtra(Intent.EXTRA_EMAIL, "YOUR MAIL"); intent.putExtra(Intent.EXTRA_SUBJECT, "YOUR SUBJECT"); intent.putExtra(Intent.EXTRA_TEXT, "YOUR TEXT"); Uri u = Uri.fromFile(exportRealmFile); intent.putExtra(Intent.EXTRA_STREAM, u);
private void shareUrl(String subject, String url) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, subject); intent.putExtra(Intent.EXTRA_TEXT, url); startActivity(Intent.createChooser(intent, getString(R.string.share_dialog_title))); }