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:eu.thecoder4.gpl.pleftdroid.HandleLinksActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    TextView tv = new TextView(this);

    tv.setText("Verifying Link...");
    setContentView(tv);//from   ww w .  j  av a2  s .co  m

    Intent intent = getIntent();
    if (intent.getAction().equals("android.intent.action.VIEW")) {
        try {
            Uri uri = getIntent().getData();
            theurl = uri.toString();

        } catch (Exception e) {
            Toast.makeText(this, R.string.toast_couldnotopenurl, Toast.LENGTH_LONG).show();
        }
    } else if (Intent.ACTION_SEND.equals(intent.getAction())) {

        Bundle extras = intent.getExtras();
        theurl = extras.getCharSequence(Intent.EXTRA_TEXT).toString();
    } else {
        theurl = "";
    }
    //Toast.makeText(this, "The URL  =  "+theurl, Toast.LENGTH_LONG).show();

    // Parse the URL
    // VERIFICATION: verify?id=&u=&p=
    // INVITATION: a?id=&u=&p=
    if (theurl.indexOf("?") < 0 && theurl.indexOf("/verify?") < 0 && theurl.indexOf("/a?") < 0) {
        Toast.makeText(this, R.string.toast_linknotsupp, Toast.LENGTH_LONG).show();
        finish();
    } else {
        Map<String, String> arr = PleftBroker.getParamsFromURL(theurl);

        pserver = arr.get("pserver");
        if (arr.get("id") != null) {
            aid = Integer.parseInt(arr.get("id"));
        } else {
            aid = 0;
        }
        vcode = arr.get("p");
        user = arr.get("u");
        if (aid == 0 || vcode == null || user == null) {
            Toast.makeText(this, R.string.toast_shlinknotvalid, Toast.LENGTH_LONG).show();
            finish();
        } else { // we have a valid Link

            handleLnk = new Runnable() {
                @Override
                public void run() {
                    handleLink();
                }
            };
            Thread thread = new Thread(null, handleLnk, "Handlethrd");
            thread.start();
        } // End - if Link is Valid
    }
}

From source file:com.coinblesk.client.ui.dialogs.ReceiveDialogFragment.java

@Nullable
@Override// w  w w. j a va2  s  .c  om
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    final String bitcoinUriString = this.getArguments().getString(BITCOIN_URI_KEY);

    try {
        final BitcoinURI bitcoinURI = new BitcoinURI(bitcoinUriString);
        final View view = inflater.inflate(R.layout.fragment_receive_alertdialog, null);
        view.findViewById(R.id.receive_email_touch_area).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
                emailIntent.setType("text/html");
                emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                        String.format(getString(R.string.payment_request_html_subject)));
                emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
                        Html.fromHtml(String.format(getString(R.string.payment_request_html_content),
                                bitcoinUriString, bitcoinURI.getAmount().toFriendlyString(),
                                bitcoinURI.getAddress())));
                startActivity(Intent.createChooser(emailIntent, "Email:"));
            }
        });

        view.findViewById(R.id.receive_qrcode_touch_area).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                QrDialogFragment.newInstance(bitcoinURI).show(getFragmentManager(), "qr-fragment");
            }
        });

        view.findViewById(R.id.receive_contactless_touch_area).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent action = new Intent(Constants.START_SERVERS_ACTION);
                action.putExtra(BITCOIN_URI_KEY, bitcoinUriString);
                LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(action);
            }
        });

        return view;
    } catch (BitcoinURIParseException e) {
        Log.e(TAG, "Could not parse Bitcoin URI: ", e);
    }
    return null;
}

From source file:ca.mudar.snoozy.ui.activity.BaseActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    if (item.getItemId() == android.R.id.home) {
        // Respond to the action bar's Up/Home button
        NavUtils.navigateUpFromSameTask(this);
        return true;
    } else if (item.getItemId() == R.id.action_settings) {
        Intent intent = new Intent(this, SettingsActivity.class);
        startActivity(intent);//from   ww  w . ja va2s  .co  m
        return true;
    } else if (item.getItemId() == R.id.action_about) {
        Intent intent = new Intent(this, AboutActivity.class);
        startActivity(intent);
        return true;
    } else if (item.getItemId() == R.id.action_eula) {
        Intent intent = new Intent(this, EulaActivity.class);
        startActivity(intent);
        return true;
    } else if (item.getItemId() == R.id.action_share) {
        /*
         Native sharing
          */
        final Bundle extras = new Bundle();
        extras.putString(Intent.EXTRA_SUBJECT, getResources().getString(R.string.share_intent_title));
        extras.putString(Intent.EXTRA_TEXT, Const.URL_PLAYSTORE);

        final Intent sendIntent = new Intent();
        sendIntent.putExtras(extras);
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.setType(this.SEND_INTENT_TYPE);
        startActivity(sendIntent);
    } else if (item.getItemId() == R.id.action_rate) {
        /*
         Launch Playstore to rate app
          */
        final Intent viewIntent = new Intent(Intent.ACTION_VIEW);
        viewIntent.setData(Uri.parse(Const.URL_PLAYSTORE));
        startActivity(viewIntent);
    }

    return super.onOptionsItemSelected(item);
}

From source file:edu.stanford.mobisocial.dungbeetle.obj.action.ExportPhotoAction.java

@Override
public void onAct(Context context, DbEntryHandler objType, DbObj obj) {
    byte[] raw = obj.getRaw();
    if (raw == null) {
        String b64Bytes = obj.getJson().optString(PictureObj.DATA);
        raw = FastBase64.decode(b64Bytes);
    }//  w w  w. j a v  a  2  s.  c om
    OutputStream outStream = null;
    File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/temp_share.png");
    try {
        outStream = new FileOutputStream(file);

        BitmapManager mgr = new BitmapManager(1);
        Bitmap bitmap = mgr.getBitmap(raw.hashCode(), raw);

        bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
        outStream.flush();
        outStream.close();

        bitmap.recycle();
        bitmap = null;
        System.gc();
        Intent intent = new Intent(android.content.Intent.ACTION_SEND);
        intent.setType("image/png");
        Log.w("ResharePhotoAction",
                Environment.getExternalStorageDirectory().getAbsolutePath() + "/temp_share.png");
        intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
        context.startActivity(Intent.createChooser(intent, "Export image to"));

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:ee.ria.DigiDoc.activity.OpenExternalFileActivity.java

private void handleIntentAction() {
    Intent intent = getIntent();// www . j av  a 2 s. c om
    ContainerFacade container = null;
    Timber.d("Handling action: %s ", intent.getAction());
    switch (intent.getAction()) {
    case Intent.ACTION_VIEW:
        try {
            container = createContainer(intent.getData());
        } catch (Exception e) {
            Timber.e(e, "Error creating container from uri %s", intent.getData().toString());
        }
        break;
    case Intent.ACTION_SEND:
        Uri sendUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
        if (sendUri != null) {
            container = createContainer(sendUri);
        }
        break;
    case Intent.ACTION_SEND_MULTIPLE:
        ArrayList<Uri> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        if (uris != null) {
            container = createContainer(uris);
        }
        break;
    }

    if (container != null) {
        createContainerDetailsFragment(container);
    } else {
        createErrorFragment();
    }
}

From source file:com.galois.qrstream.lib.DecodeThread.java

private Intent buildIntent(Job message) throws IOException {
    Intent i = new Intent();
    i.setAction(Intent.ACTION_SEND);
    i.addCategory(Intent.CATEGORY_DEFAULT);
    String mimeType = message.getMimeType();
    i.setType(mimeType);/*from w  w w  . ja  v a 2 s .c  om*/

    if (mimeType.equals("text/plain")) {
        String msg = new String(message.getData());
        i.putExtra(Intent.EXTRA_TEXT, msg);
    } else {
        // content that is not text uses the filesystem to store the data
        // (when sharing with a new local app)
        File dataLoc = storeData(message);

        if (mimeType.startsWith("image/")) {
            String path = Images.Media.insertImage(context.getContentResolver(), dataLoc.getPath(),
                    message.getTitle(), null);
            Uri imageUri = Uri.parse(path);
            i.putExtra(Intent.EXTRA_STREAM, imageUri);

            // we can delete the temporary location in this case, since the file has been saved
            // to the media store.
            // In the other cases, the receiver has to handle the content of the temp file before
            // it can be deleted -- but we will never know if/when that happens.
            dataLoc.delete();
        } else if (mimeType.equals(Constants.MIME_TYPE_TEXT_NOTE)) {
            String json = new String(message.getData());
            try {
                JSONObject note = new JSONObject(json);
                i.putExtra(Intent.EXTRA_TEXT, note.getString(Intent.EXTRA_TEXT));
                i.putExtra(Intent.EXTRA_SUBJECT, note.getString(Intent.EXTRA_SUBJECT));
                i.setType("text/plain");
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } else {
            i.putExtra(Intent.EXTRA_STREAM, dataLoc.toURI());
        }
    }
    return i;
}

From source file:at.bitfire.davdroid.ui.DebugInfoActivity.java

public void onShare(MenuItem item) {
    if (!TextUtils.isEmpty(report)) {
        Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.setType("text/plain");
        sendIntent.putExtra(Intent.EXTRA_SUBJECT,
                getString(R.string.app_name) + " " + BuildConfig.VERSION_NAME + " debug info");

        // since Android 4.1, FileProvider permissions are handled in a useful way (using ClipData)
        boolean asAttachment = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;

        if (asAttachment)
            try {
                File debugInfoDir = new File(getCacheDir(), "debug-info");
                debugInfoDir.mkdir();//from   ww  w.  ja  v  a 2s  .c o  m

                reportFile = new File(debugInfoDir, "debug.txt");
                App.log.fine("Writing debug info to " + reportFile.getAbsolutePath());
                FileWriter writer = new FileWriter(reportFile);
                writer.write(report);
                writer.close();

                sendIntent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(this,
                        getString(R.string.authority_log_provider), reportFile));
                sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

            } catch (IOException e) {
                // creating an attachment failed, so send it inline
                asAttachment = false;

                StringBuilder builder = new StringBuilder();
                builder.append("Couldn't write debug info file:\n").append(ExceptionUtils.getStackTrace(e))
                        .append("\n\n").append(report);
                report = builder.toString();
            }

        if (!asAttachment)
            sendIntent.putExtra(Intent.EXTRA_TEXT, report);

        startActivity(Intent.createChooser(sendIntent, null));
    }
}

From source file:im.delight.android.baselib.Social.java

/**
 * Constructs an Intent for sharing/sending a file and starts Activity chooser for that Intent
 *
 * @param context Context reference to start the Activity chooser from
 * @param windowTitle the string to be used as the window title for the Activity chooser
 * @param file the File instance to be shared
 * @param mimeType the MIME type for the file to be shared (e.g. image/jpeg)
 * @param messageTitle the message title/subject that may be provided in addition to the file, if supported by the target app
 *//*from w w  w .j a v a2 s .  c om*/
public static void shareFile(Context context, String windowTitle, File file, final String mimeType,
        String messageTitle) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setType(mimeType);
    intent.putExtra(Intent.EXTRA_SUBJECT, messageTitle);
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
    context.startActivity(Intent.createChooser(intent, windowTitle));
}

From source file:com.bangalore.barcamp.activity.ShareActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.share_screen);
    mDrawerToggle = BCBFragmentUtils.setupActionBar(this, "Share");

    // BCBUtils.createActionBarOnActivity(this);
    // BCBUtils.addNavigationActions(this);
    ((EditText) findViewById(R.id.editText1)).addTextChangedListener(new TextWatcher() {

        @Override//from  w w  w  .  jav a 2 s  . c  o  m
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            ((TextView) findViewById(R.id.charsLeftTextView)).setText("Chars left: " + (140 - s.length() - 7));
        }
    });
    if (getIntent().hasExtra(SHARE_STRING)) {
        ((EditText) findViewById(R.id.editText1)).setText(getIntent().getStringExtra(SHARE_STRING));
    }
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    final PackageManager pm = getPackageManager();
    final Spinner spinner = (Spinner) findViewById(R.id.shareTypeSpinner);
    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    final List<ResolveInfo> matches = pm.queryIntentActivities(intent, 0);
    String selectedItem = BCBSharedPrefUtils.getShareSettings(getApplicationContext());
    int selectedPos = -1;
    for (ResolveInfo info : matches) {
        adapter.add(info.loadLabel(pm));
        if (selectedItem.equals(info.loadLabel(pm))) {
            selectedPos = matches.indexOf(info);
        }
    }
    spinner.setAdapter(adapter);

    if (selectedPos != -1) {
        spinner.setSelected(true);
        spinner.setSelection(selectedPos);
    }
    ((TextView) findViewById(R.id.charsLeftTextView)).setText("Chars left: 140");
    ((Button) findViewById(R.id.button1)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            int appSelectedPos = spinner.getSelectedItemPosition();
            ResolveInfo info = matches.get(appSelectedPos);
            intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);

            BCBSharedPrefUtils.setShareSettings(getApplicationContext(), (String) info.loadLabel(pm));
            intent.putExtra(Intent.EXTRA_TEXT,
                    ((EditText) findViewById(R.id.editText1)).getText().toString() + " #barcampblr");
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            startActivity(intent);
            finish();

        }
    });

    BCBFragmentUtils.addNavigationActions(this);
    supportInvalidateOptionsMenu();
    Tracker t = ((BarcampBangalore) getApplication()).getTracker();

    // Set screen name.
    t.setScreenName(this.getClass().getName());

    // Send a screen view.
    t.send(new HitBuilders.AppViewBuilder().build());

}

From source file:net.bible.android.control.page.PageControl.java

/** send the current verse via social applications installed on user's device
 *//* w ww. j  a v  a  2s  . c om*/
public void shareVerse() {
    try {
        Book book = getCurrentPageManager().getCurrentPage().getCurrentDocument();
        Key key = getCurrentPageManager().getCurrentPage().getSingleKey();

        String text = key.getName() + "\n" + SwordContentFacade.getInstance().getCanonicalText(book, key);

        Intent sendIntent = new Intent(Intent.ACTION_SEND);
        sendIntent.setType("text/plain");

        sendIntent.putExtra(Intent.EXTRA_TEXT, text);
        // subject is used when user chooses to send verse via e-mail
        sendIntent.putExtra(Intent.EXTRA_SUBJECT,
                BibleApplication.getApplication().getText(R.string.share_verse_subject));

        Activity activity = CurrentActivityHolder.getInstance().getCurrentActivity();
        activity.startActivity(Intent.createChooser(sendIntent, activity.getString(R.string.share_verse)));

    } catch (Exception e) {
        Log.e(TAG, "Error sharing verse", e);
        Dialogs.getInstance().showErrorMsg("Error sharing verse");
    }
}