Example usage for android.content Intent ACTION_SEND

List of usage examples for android.content Intent ACTION_SEND

Introduction

In this page you can find the example usage for android.content Intent ACTION_SEND.

Prototype

String ACTION_SEND

To view the source code for android.content Intent ACTION_SEND.

Click Source Link

Document

Activity Action: Deliver some data to someone else.

Usage

From source file:com.dycody.android.idealnote.DetailFragment.java

/**
 * Performs an action when long-click option is selected
 *
 * @param attachmentPosition/* w  w w  .j a  v a 2  s. com*/
 * @param i                  item index
 */
private void performAttachmentAction(int attachmentPosition, int i) {
    switch (getResources().getStringArray(R.array.attachments_actions_values)[i]) {
    case "share":
        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        Attachment attachment = mAttachmentAdapter.getItem(attachmentPosition);
        shareIntent.setType(StorageHelper.getMimeType(IdealNote.getAppContext(), attachment.getUri()));
        shareIntent.putExtra(Intent.EXTRA_STREAM, attachment.getUri());
        if (IntentChecker.isAvailable(IdealNote.getAppContext(), shareIntent, null)) {
            startActivity(shareIntent);
        } else {
            Toast.makeText(getActivity(), R.string.feature_not_available_on_this_device, Toast.LENGTH_SHORT)
                    .show();
            //mainActivity.showMessage(R.string.feature_not_available_on_this_device, ONStyle.WARN);
        }
        break;
    case "delete":
        removeAttachment(attachmentPosition);
        mAttachmentAdapter.notifyDataSetChanged();
        mGridView.autoresize();
        break;
    case "delete all":
        new MaterialDialog.Builder(mainActivity).title(R.string.delete_all_attachments)
                .positiveText(R.string.confirm)
                .onPositive((materialDialog, dialogAction) -> removeAllAttachments()).build().show();
        break;
    case "edit":
        takeSketch(mAttachmentAdapter.getItem(attachmentPosition));
        break;
    default:
        Log.w(Constants.TAG, "No action available");
    }
}

From source file:com.if3games.chessonline.DroidFish.java

/**
 * Return PGN/FEN data or filename from the Intent. Both can not be non-null.
 * @return Pair of PGN/FEN data and filename.
 *///from   w  w  w.jav  a2 s  .  com
private final Pair<String, String> getPgnOrFenIntent() {
    String pgnOrFen = null;
    String filename = null;
    try {
        Intent intent = getIntent();
        Uri data = intent.getData();
        if (data == null) {
            Bundle b = intent.getExtras();
            if (b != null) {
                Object strm = b.get(Intent.EXTRA_STREAM);
                if (strm instanceof Uri) {
                    data = (Uri) strm;
                    if ("file".equals(data.getScheme())) {
                        filename = data.getEncodedPath();
                        if (filename != null)
                            filename = Uri.decode(filename);
                    }
                }
            }
        }
        if (data == null) {
            if ((Intent.ACTION_SEND.equals(intent.getAction()) || Intent.ACTION_VIEW.equals(intent.getAction()))
                    && ("application/x-chess-pgn".equals(intent.getType())
                            || "application/x-chess-fen".equals(intent.getType())))
                pgnOrFen = intent.getStringExtra(Intent.EXTRA_TEXT);
        } else {
            String scheme = intent.getScheme();
            if ("file".equals(scheme)) {
                filename = data.getEncodedPath();
                if (filename != null)
                    filename = Uri.decode(filename);
            }
            if ((filename == null) && ("content".equals(scheme) || "file".equals(scheme))) {
                ContentResolver resolver = getContentResolver();
                InputStream in = resolver.openInputStream(intent.getData());
                StringBuilder sb = new StringBuilder();
                while (true) {
                    byte[] buffer = new byte[16384];
                    int len = in.read(buffer);
                    if (len <= 0)
                        break;
                    sb.append(new String(buffer, 0, len));
                }
                pgnOrFen = sb.toString();
            }
        }
    } catch (IOException e) {
        Toast.makeText(getApplicationContext(), R.string.failed_to_read_pgn_data, Toast.LENGTH_SHORT).show();
    }
    return new Pair<String, String>(pgnOrFen, filename);
}

From source file:android_network.hetnet.vpn_service.Util.java

public static void sendLogcat(final Uri uri, final Context context) {
    AsyncTask task = new AsyncTask<Object, Object, Intent>() {
        @Override//from   ww  w  .  jav a2 s .com
        protected Intent doInBackground(Object... objects) {
            StringBuilder sb = new StringBuilder();
            sb.append(context.getString(R.string.msg_issue));
            sb.append("\r\n\r\n\r\n\r\n");

            // Get version info
            String version = getSelfVersionName(context);
            sb.append(String.format("NetGuard: %s/%d\r\n", version, getSelfVersionCode(context)));
            sb.append(String.format("Android: %s (SDK %d)\r\n", Build.VERSION.RELEASE, Build.VERSION.SDK_INT));
            sb.append("\r\n");

            // Get device info
            sb.append(String.format("Brand: %s\r\n", Build.BRAND));
            sb.append(String.format("Manufacturer: %s\r\n", Build.MANUFACTURER));
            sb.append(String.format("Model: %s\r\n", Build.MODEL));
            sb.append(String.format("Product: %s\r\n", Build.PRODUCT));
            sb.append(String.format("Device: %s\r\n", Build.DEVICE));
            sb.append(String.format("Host: %s\r\n", Build.HOST));
            sb.append(String.format("Display: %s\r\n", Build.DISPLAY));
            sb.append(String.format("Id: %s\r\n", Build.ID));
            sb.append(String.format("Fingerprint: %B\r\n", hasValidFingerprint(context)));

            String abi;
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
                abi = Build.CPU_ABI;
            else
                abi = (Build.SUPPORTED_ABIS.length > 0 ? Build.SUPPORTED_ABIS[0] : "?");
            sb.append(String.format("ABI: %s\r\n", abi));

            sb.append("\r\n");

            sb.append(String.format("VPN dialogs: %B\r\n",
                    isPackageInstalled("com.android.vpndialogs", context)));
            try {
                sb.append(String.format("Prepared: %B\r\n", VpnService.prepare(context) == null));
            } catch (Throwable ex) {
                sb.append("Prepared: ").append((ex.toString())).append("\r\n")
                        .append(Log.getStackTraceString(ex));
            }
            sb.append(String.format("Permission: %B\r\n", hasPhoneStatePermission(context)));
            sb.append("\r\n");

            sb.append(getGeneralInfo(context));
            sb.append("\r\n\r\n");
            sb.append(getNetworkInfo(context));
            sb.append("\r\n\r\n");
            sb.append(getSubscriptionInfo(context));
            sb.append("\r\n\r\n");

            // Get settings
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
            Map<String, ?> all = prefs.getAll();
            for (String key : all.keySet())
                sb.append("Setting: ").append(key).append('=').append(all.get(key)).append("\r\n");
            sb.append("\r\n");

            // Write logcat
            OutputStream out = null;
            try {
                Log.i(TAG, "Writing logcat URI=" + uri);
                out = context.getContentResolver().openOutputStream(uri);
                out.write(getLogcat().toString().getBytes());
                out.write(getTrafficLog(context).toString().getBytes());
            } catch (Throwable ex) {
                Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                sb.append(ex.toString()).append("\r\n").append(Log.getStackTraceString(ex)).append("\r\n");
            } finally {
                if (out != null)
                    try {
                        out.close();
                    } catch (IOException ignored) {
                    }
            }

            // Build intent
            Intent sendEmail = new Intent(Intent.ACTION_SEND);
            sendEmail.setType("message/rfc822");
            sendEmail.putExtra(Intent.EXTRA_EMAIL, new String[] { "marcel+netguard@faircode.eu" });
            sendEmail.putExtra(Intent.EXTRA_SUBJECT, "NetGuard " + version + " logcat");
            sendEmail.putExtra(Intent.EXTRA_TEXT, sb.toString());
            sendEmail.putExtra(Intent.EXTRA_STREAM, uri);
            return sendEmail;
        }

        @Override
        protected void onPostExecute(Intent sendEmail) {
            if (sendEmail != null)
                try {
                    context.startActivity(sendEmail);
                } catch (Throwable ex) {
                    Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                }
        }
    };
    task.execute();
}

From source file:aarddict.android.ArticleViewActivity.java

@Override
void onDictionaryServiceReady() {
    if (this.backItems.isEmpty()) {
        final Intent intent = getIntent();
        if (intent != null && intent.getAction() != null) {
            String action = intent.getAction();
            String _word = null;/*from   ww w.  ja v a2s  .  co m*/
            if (action.equals(Intent.ACTION_SEARCH)) {
                _word = intent.getStringExtra("query");
            } else if (action.equals(Intent.ACTION_SEND)) {
                _word = intent.getStringExtra(Intent.EXTRA_TEXT);
            }

            final String word = _word;

            if (word != null) {

                if (currentTask != null) {
                    currentTask.cancel();
                }

                currentTask = new TimerTask() {
                    @Override
                    public void run() {
                        setProgress(500);
                        String currentWord = word;
                        Log.d(TAG, "intent.getDataString(): " + intent.getDataString());
                        while (currentWord.length() > 0) {
                            Iterator<Entry> results = dictionaryService.lookup(currentWord);
                            Log.d(TAG, "Looked up " + word);
                            if (results.hasNext()) {
                                currentTask = null;
                                Entry entry = results.next();
                                showArticle(entry);
                                break;
                            } else {
                                currentWord = currentWord.substring(0, currentWord.length() - 1);
                            }
                        }
                        if (currentWord.length() == 0) {
                            onSearchRequested();
                        }
                    }
                };

                try {
                    timer.schedule(currentTask, 0);
                } catch (Exception e) {
                    Log.d(TAG, "Failed to schedule task", e);
                    showError(getString(R.string.msgErrorLoadingArticle, word));
                }
            }
        } else {
            String word = intent.getStringExtra("word");
            String section = intent.getStringExtra("section");
            String volumeId = intent.getStringExtra("volumeId");
            long articlePointer = intent.getLongExtra("articlePointer", -1);
            dictionaryService.setPreferred(volumeId);
            showArticle(volumeId, articlePointer, word, section);
        }
    } else {
        showCurrentArticle();
    }
}

From source file:com.mitre.holdshort.MainActivity.java

private void contactMITRE(String subject) {

    final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.setType("plain/text");
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "ripple@mitre.org" });
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    emailIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}

From source file:com.android.dialer.voicemail.VoicemailPlaybackPresenter.java

private Intent getShareIntent(Uri voicemailFileUri) {
    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_STREAM, voicemailFileUri);
    shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    shareIntent.setType(mContext.getContentResolver().getType(voicemailFileUri));
    return shareIntent;
}

From source file:com.rsltc.profiledata.main.MainActivity.java

private void exportFile(List<JSONObject> jsonObjects, String dataset_name) {
    final String date = new SimpleDateFormat("yyyyMMdd-HHmmss", Locale.getDefault()).format(new Date());
    final String filename = String.format("%s_%s.txt", dataset_name, date);

    final String directory = Environment.getExternalStorageDirectory().getAbsolutePath() + "/AndroidTesting/";

    final File logfile = new File(directory, filename);
    final File logPath = logfile.getParentFile();

    if (!logPath.isDirectory() && !logPath.mkdirs()) {
        Log.e("SensorDashbaord", "Could not create directory for log files");
    }// w ww.  jav a2s  .co m

    try {
        FileWriter filewriter = new FileWriter(logfile);
        BufferedWriter bw = new BufferedWriter(filewriter);

        //            for (JSONObject object : jsonObjects) {
        bw.write(jsonObjects.toString());
        //            }
        bw.flush();
        bw.close();

        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.setType("*/*");

        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, dataset_name + ".csv");
        emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(logfile));
        startActivity(Intent.createChooser(emailIntent, "Send mail..."));

        Log.i(TAG, "export finished!");
    } catch (IOException ioe) {
        Log.e(TAG, "IOException while writing Logfile");
        Log.e("Enias", ioe.getMessage());
    }
}

From source file:edu.mum.ml.group7.guessasketch.android.EasyPaint.java

public void loadFromIntents() {
    Intent intent = getIntent();//w  w  w  .  java  2 s  .co m
    String action = intent.getAction();
    String type = intent.getType();
    System.out.println("Intentoso " + action + " type " + type);
    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if (type.startsWith("image/")) {
            setBackgroundUri((Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM));
        }

    }
}

From source file:com.matthewmitchell.peercoin_android_wallet.ui.WalletActivity.java

private void archiveWalletBackup(@Nonnull final File file) {
    final Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.export_keys_dialog_mail_subject));
    intent.putExtra(Intent.EXTRA_TEXT, makeEmailText(getString(R.string.export_keys_dialog_mail_text)));
    intent.setType(Constants.MIMETYPE_WALLET_BACKUP);
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));

    try {/*from  w ww  . j a  v  a2 s. co m*/
        startActivity(Intent.createChooser(intent, getString(R.string.export_keys_dialog_mail_intent_chooser)));
        log.info("invoked chooser for archiving wallet backup");
    } catch (final Exception x) {
        longToast(R.string.export_keys_dialog_mail_intent_failed);
        log.error("archiving wallet backup failed", x);
    }
}

From source file:edu.mit.viral.shen.DroidFish.java

private final Pair<String, String> getPgnOrFenIntent() {
    String pgnOrFen = null;//w w w. j  a v a2 s .  c o m
    String filename = null;
    try {
        Intent intent = getIntent();
        Uri data = intent.getData();
        if (data == null) {
            if ((Intent.ACTION_SEND.equals(intent.getAction()) || Intent.ACTION_VIEW.equals(intent.getAction()))
                    && ("application/x-chess-pgn".equals(intent.getType())
                            || "application/x-chess-fen".equals(intent.getType())))
                pgnOrFen = intent.getStringExtra(Intent.EXTRA_TEXT);
        } else {
            String scheme = intent.getScheme();
            if ("file".equals(scheme)) {
                filename = data.getEncodedPath();
                if (filename != null)
                    filename = Uri.decode(filename);
            }
            if ((filename == null) && ("content".equals(scheme) || "file".equals(scheme))) {
                ContentResolver resolver = getContentResolver();
                InputStream in = resolver.openInputStream(intent.getData());
                StringBuilder sb = new StringBuilder();
                while (true) {
                    byte[] buffer = new byte[16384];
                    int len = in.read(buffer);
                    if (len <= 0)
                        break;
                    sb.append(new String(buffer, 0, len));
                }
                pgnOrFen = sb.toString();
            }
        }
    } catch (IOException e) {
        Toast.makeText(getApplicationContext(), R.string.failed_to_read_pgn_data, Toast.LENGTH_SHORT).show();
    }
    return new Pair<String, String>(pgnOrFen, filename);
}