List of usage examples for android.content Intent ACTION_SEND
String ACTION_SEND
To view the source code for android.content Intent ACTION_SEND.
Click Source Link
From source file:com.phonegap.cordova.FileOpener.java
private void openFile(String url, String type) throws IOException { // Create URI Uri uri = Uri.parse(url);/* w w w .j av a2 s. c o m*/ Intent intent = null; Log.v("FileOpener", "Type: " + type); if (type.equals("pdfshare")) { intent = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:")); // intent.setDataAndType(uri, "application/pdf"); intent.setType("application/pdf"); intent.putExtra(Intent.EXTRA_SUBJECT, "AMR Report"); intent.putExtra(Intent.EXTRA_TEXT, ""); intent.putExtra(Intent.EXTRA_STREAM, uri); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } else if (url.contains(".pdf")) { // PDF file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "application/pdf"); } else if (url.contains(".ppt") || url.contains(".pptx")) { // Powerpoint file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "application/vnd.ms-powerpoint"); } else if (url.contains(".xls") || url.contains(".xlsx")) { // Excel file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "application/vnd.ms-excel"); } else if (url.contains(".rtf")) { // RTF file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "application/rtf"); } else if (url.contains(".wav")) { // WAV audio file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "audio/x-wav"); } else if (url.contains(".gif")) { // GIF file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "image/gif"); } else if (url.contains(".jpg") || url.contains(".jpeg")) { // JPG file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "image/jpeg"); } else if (url.contains(".png")) { // PNG file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "image/png"); } else if (url.contains(".txt")) { // Text file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "text/plain"); } else if (url.contains(".mpg") || url.contains(".mpeg") || url.contains(".mpe") || url.contains(".mp4") || url.contains(".avi")) { // Video files intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "video/*"); } else if (url.contains(".doc") || url.contains(".docx")) { // Word document intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "application/msword"); } //if you want you can also define the intent type for any other file //additionally use else clause below, to manage other unknown extensions //in this case, Android will show all applications installed on the device //so you can choose which application to use else if (type.equals("none") || type.equals("*/*")) { intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "*/*"); } else { intent = new Intent(Intent.ACTION_VIEW); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(uri, type); } //TRY Catch error try { this.cordova.getActivity().startActivity(intent); } catch (ActivityNotFoundException e) { intent.setData(uri); this.cordova.getActivity().startActivity(intent); } }
From source file:com.krayzk9s.imgurholo.services.DownloadService.java
@Override protected void onHandleIntent(Intent intent) { final NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); ids = intent.getParcelableArrayListExtra("ids"); albumName = "/"; downloaded = 0;//from w ww .j ava 2 s . c o m if (ids.size() > 0) { albumName += intent.getStringExtra("albumName") + "/"; File myDirectory = new File( android.os.Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), albumName); if (!myDirectory.exists()) { myDirectory.mkdirs(); } } for (int i = 0; i < ids.size(); i++) { try { final String type = ids.get(i).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TYPE) .split("/")[1]; final String id = ids.get(i).getJSONObject().getString("id"); final String link = ids.get(i).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK); Log.d("data", ids.get(i).getJSONObject().toString()); Log.d(ImgurHoloActivity.IMAGE_DATA_TYPE, ids.get(0).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TYPE).split("/")[1]); Log.d("id", ids.get(i).getJSONObject().getString("id")); Log.d(ImgurHoloActivity.IMAGE_DATA_LINK, ids.get(0).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK)); final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder.setContentTitle(getString(R.string.picture_download)) .setContentText(getString(R.string.download_in_progress)) .setSmallIcon(R.drawable.icon_desaturated); Ion.with(getApplicationContext(), link).progress(new ProgressCallback() { @Override public void onProgress(int i, int i2) { notificationBuilder.setProgress(i2, i, false); } }).write(new File( android.os.Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + albumName + id + "." + type)) .setCallback(new FutureCallback<File>() { @Override public void onCompleted(Exception e, File file) { if (file == null) return; downloaded += 1; if (downloaded == ids.size()) { NotificationCompat.Builder notificationComplete = new NotificationCompat.Builder( getApplicationContext()); if (ids.size() == 1) { Intent viewImageIntent = new Intent(Intent.ACTION_VIEW); viewImageIntent.setDataAndType(Uri.fromFile(file), "image/*"); Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); shareIntent.setType("image/*"); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); PendingIntent viewImagePendingIntent = PendingIntent.getActivity( getApplicationContext(), (int) System.currentTimeMillis(), viewImageIntent, 0); PendingIntent sharePendingIntent = PendingIntent.getActivity( getApplicationContext(), (int) System.currentTimeMillis(), shareIntent, 0); notificationComplete.setContentTitle(getString(R.string.download_complete)) .setSmallIcon(R.drawable.icon_desaturated) .setContentText(String.format(getString(R.string.download_progress), downloaded)) .setContentIntent(viewImagePendingIntent) .addAction(R.drawable.dark_social_share, getString(R.string.share), sharePendingIntent); } else { Intent i = new Intent(Intent.ACTION_PICK); i.setDataAndType( Uri.fromFile(new File( android.os.Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES) + albumName)), "image/*"); PendingIntent viewImagePendingIntent = PendingIntent.getActivity( getApplicationContext(), (int) System.currentTimeMillis(), i, 0); notificationComplete.setContentTitle(getString(R.string.download_complete)) .setSmallIcon(R.drawable.icon_desaturated).setContentText(String .format(getString(R.string.download_progress), downloaded)) .setContentIntent(viewImagePendingIntent); } notificationManager.cancel(0); notificationManager.cancel(1); notificationManager.notify(1, notificationComplete.build()); } MediaScannerConnection.scanFile(getApplicationContext(), new String[] { android.os.Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES) + albumName + id + "." + type }, null, new MediaScannerConnection.OnScanCompletedListener() { @Override public void onScanCompleted(final String path, final Uri uri) { Log.i("Scanning", String.format("Scanned path %s -> URI = %s", path, uri.toString())); } }); } }); notificationManager.notify(0, notificationBuilder.build()); } catch (JSONException e) { Log.e("Error!", e.toString()); } } }
From source file:edu.mit.mobile.android.demomode.Preferences.java
private void shareConfig() { startActivity(Intent.createChooser(// w w w.j a va 2 s.co m new Intent(Intent.ACTION_SEND).setType("text/plain").putExtra(Intent.EXTRA_TEXT, toConfigString()) .putExtra(Intent.EXTRA_SUBJECT, getText(R.string.app_name) + " Config"), getText(R.string.share_config))); }
From source file:com.liato.bankdroid.banking.banks.Coop.java
@Override public Urllib login() throws LoginException, BankException { try {/*w ww . j a v a 2 s.co m*/ LoginPackage lp = preLogin(); response = urlopen.open(lp.getLoginTarget(), lp.getPostData()); if (response.contains("forfarande logga in med ditt personnummer")) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (prefs.getBoolean("debug_mode", false) && prefs.getBoolean("debug_coop_sendmail", false)) { Intent i = new Intent(android.content.Intent.ACTION_SEND); i.setType("plain/text"); i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "android@nullbyte.eu" }); i.putExtra(android.content.Intent.EXTRA_SUBJECT, "Bankdroid - Coop Error"); i.putExtra(android.content.Intent.EXTRA_TEXT, response); context.startActivity(i); } throw new LoginException(res.getText(R.string.invalid_username_password).toString()); } } catch (ClientProtocolException e) { throw new BankException(e.getMessage()); } catch (IOException e) { throw new BankException(e.getMessage()); } return urlopen; }
From source file:in.animeshpathak.nextbus.NextBusMain.java
/** Called when the activity is first started. */ @Override/*from w ww.java 2s . c o m*/ public void onCreate(Bundle bundle) { Log.d(LOG_TAG, "entering onCreate()"); SettingsActivity.setTheme(this); super.onCreate(bundle); setContentView(R.layout.main); try { busNet = BusNetwork.getInstance(this); } catch (Exception e) { Log.e(LOG_TAG, e.getMessage(), e); return; } // get the button // set handler to launch a processing dialog ImageButton updateButton = (ImageButton) findViewById(R.id.update_button); updateButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { BusLine selectedLine = lineAdapter.getItem(lineSpinner.getSelectedItemPosition()); BusStop selectedStop = stopAdapter.getItem(stopSpinner.getSelectedItemPosition()); getBusTimings(selectedLine, selectedStop); } }); ImageButton feedbackButton = (ImageButton) findViewById(R.id.feedback_button); feedbackButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(Intent.ACTION_SEND); i.setType("message/rfc822"); // use from live device i.putExtra(Intent.EXTRA_EMAIL, new String[] { Constants.FEEDBACK_EMAIL_ADDRESS }); i.putExtra(Intent.EXTRA_SUBJECT, Constants.FEEDBACK_EMAIL_SUBJECT); i.putExtra(Intent.EXTRA_TEXT, getString(R.string.email_hello)); startActivity(Intent.createChooser(i, getString(R.string.select_email_app))); } }); ImageButton phebusinfoButton = (ImageButton) findViewById(R.id.phebusinfo_button); phebusinfoButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { AlertDialog alertDialog = new AlertDialog.Builder(NextBusMain.this).create(); WebView wv = new WebView(NextBusMain.this); new PhebusNewsLoader(wv, NextBusMain.this).execute(); alertDialog.setView(wv); alertDialog.show(); } }); lineSpinner = (Spinner) findViewById(R.id.line_spinner); lineAdapter = new ArrayAdapter<BusLine>(this, android.R.layout.simple_spinner_item, busNet.getLines()); lineAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); lineSpinner.setAdapter(lineAdapter); stopSpinner = (Spinner) findViewById(R.id.stop_spinner); stopAdapter = new ArrayAdapter<BusStop>(this, android.R.layout.simple_spinner_item); stopAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); stopSpinner.setAdapter(stopAdapter); ImageButton favoriteButton = (ImageButton) findViewById(R.id.favorites_button); favoriteButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { new FavoriteDialog(NextBusMain.this, new OnFavoriteSelectedListener() { @Override public void favoriteSelected(Favorite fav) { BusLine bl = busNet.getLineByName(fav.getLine()); BusStop bs = bl.getFirstStopWithSimilarName(fav.getStop()); if (bl == null || bs == null) { Log.e(LOG_TAG, "Favorite not found!"); return; } updateSpinners(bl, bs); getBusTimings(bl, bs); } }, lineSpinner.getSelectedItem().toString(), stopSpinner.getSelectedItem().toString()); } }); }
From source file:me.kartikarora.transfersh.adapters.FileGridAdapter.java
@Override public void bindView(View view, final Context context, Cursor cursor) { FileItemViewHolder holder = (FileItemViewHolder) view.getTag(); int nameCol = cursor.getColumnIndex(FilesContract.FilesEntry.COLUMN_NAME); int typeCol = cursor.getColumnIndex(FilesContract.FilesEntry.COLUMN_TYPE); int sizeCol = cursor.getColumnIndex(FilesContract.FilesEntry.COLUMN_SIZE); int urlCol = cursor.getColumnIndex(FilesContract.FilesEntry.COLUMN_URL); final String name = cursor.getString(nameCol); final String type = cursor.getString(typeCol); final String size = cursor.getString(sizeCol); final String url = cursor.getString(urlCol); holder.fileNameTextView.setText(name); String ext = FilenameUtils.getExtension(name); int identifier = context.getResources().getIdentifier("t" + ext, "drawable", context.getPackageName()); try {//from w w w . ja va 2s. c o m holder.fileTypeImageView .setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), identifier, null)); } catch (Resources.NotFoundException e) { e.printStackTrace(); holder.fileTypeImageView .setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), R.drawable.tblank, null)); } holder.fileInfoImageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String message = "Name: " + name + "\n" + "File type: " + type + "\n" + "URL: " + url; new AlertDialog.Builder(activity).setMessage(message).setPositiveButton(android.R.string.ok, null) .create().show(); } }); holder.fileShareImageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { tracker.send( new HitBuilders.EventBuilder().setCategory("Action").setAction("Share : " + url).build()); context.startActivity(new Intent().setAction(Intent.ACTION_SEND).putExtra(Intent.EXTRA_TEXT, url) .setType("text/plain").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } }); holder.fileDownloadImageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { checkForDownload(name, type, url, view); } }); }
From source file:com.autburst.picture.FinishedUploadActivity.java
private void sendLink() { String url = createVideoUrl(); if (url == null) { return;/* w ww.j a v a 2 s . c om*/ } Intent i = new Intent(Intent.ACTION_SEND); i.setType("text/plain"); Resources res = getResources(); i.putExtra(Intent.EXTRA_SUBJECT, res.getString(R.string.downloadlink)); i.putExtra(Intent.EXTRA_TEXT, url); startActivity(Intent.createChooser(i, res.getString(R.string.sendlink))); }
From source file:com.richtodd.android.quiltdesign.app.QuiltEditActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int itemId = item.getItemId(); switch (itemId) { case android.R.id.home: { NavUtils.navigateUpFromSameTask(this); return true; }/*w w w.ja v a2s . com*/ case R.id.menu_quiltOptions: { Quilt quilt = getQuiltEditFragment().getQuilt(); QuiltOptionsDialogFragment dialog = QuiltOptionsDialogFragment.create(quilt.getRowCount(), quilt.getColumnCount(), (int) quilt.getWidth()); dialog.show(getFragmentManager(), null); return true; } case R.id.menu_shareQuilt: { ShareOptionsDialogFragment dialog = ShareOptionsDialogFragment.create(Intent.ACTION_SEND); dialog.show(getFragmentManager(), null); return true; } case R.id.menu_viewQuilt: { ShareOptionsDialogFragment dialog = ShareOptionsDialogFragment.create(Intent.ACTION_VIEW); dialog.show(getFragmentManager(), null); return true; } case R.id.menu_renameQuilt: { showEditNameDialog(); return true; } case R.id.menu_deleteQuilt: { AlertDialogFragment dialog = AlertDialogFragment.create(KEY_CONFIRM_DELETE, getString(R.string.alert_message_confirmQuiltDelete), getString(R.string.alert_button_yes), getString(R.string.alert_button_no)); dialog.show(getFragmentManager(), null); return true; } case R.id.menu_cancelChanges: { getQuiltEditFragment().setSaveSuppressed(true); finish(); return true; } case R.id.menu_settings: { Intent intent = new Intent(this, QuiltPreferenceActivity.class); startActivity(intent); return true; } } return super.onOptionsItemSelected(item); }
From source file:com.callrecorder.android.RecordingsAdapter.java
private void sendMail(String fileName) { DocumentFile file = FileHelper.getStorageFile(context).findFile(fileName); Uri uri = FileHelper.getContentUri(context, file.getUri()); Intent sendIntent = new Intent(Intent.ACTION_SEND) .putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.mail_subject)) .putExtra(Intent.EXTRA_TEXT, context.getString(R.string.mail_body)) .putExtra(Intent.EXTRA_STREAM, uri).setData(uri).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) .setType("audio/3gpp"); context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.send_mail))); }
From source file:co.taqat.call.AboutFragment.java
private void sendLogs(Context context, String info) { final String appName = context.getString(R.string.app_name); Intent i = new Intent(Intent.ACTION_SEND); i.putExtra(Intent.EXTRA_EMAIL, new String[] { context.getString(R.string.about_bugreport_email) }); i.putExtra(Intent.EXTRA_SUBJECT, appName + " Logs"); i.putExtra(Intent.EXTRA_TEXT, info); i.setType("application/zip"); try {/*from www . j ava 2s .c om*/ startActivity(Intent.createChooser(i, "Send mail...")); } catch (android.content.ActivityNotFoundException ex) { Log.e(ex); } }