Example usage for android.content Intent EXTRA_TEXT

List of usage examples for android.content Intent EXTRA_TEXT

Introduction

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

Prototype

String EXTRA_TEXT

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

Click Source Link

Document

A constant CharSequence that is associated with the Intent, used with #ACTION_SEND to supply the literal data to be sent.

Usage

From source file:com.codebutler.farebot.activities.AdvancedCardInfoActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    try {//from   w  ww  .ja  v  a 2  s  .c  o  m
        String xml = Utils.xmlNodeToString(mCard.toXML().getOwnerDocument());
        if (item.getItemId() == R.id.copy_xml) {
            @SuppressWarnings("deprecation")
            ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            clipboard.setText(xml);
            Toast.makeText(this, "Copied to clipboard.", 5).show();
            return true;

        } else if (item.getItemId() == R.id.share_xml) {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, xml);
            startActivity(intent);
            return true;

        } else if (item.getItemId() == android.R.id.home) {
            finish();
            return true;
        }
    } catch (Exception ex) {
        new AlertDialog.Builder(this).setMessage(ex.toString()).show();
    }
    return false;
}

From source file:com.bringcommunications.etherpay.ReceiveActivity.java

private void do_share_guts() {
    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("image/*");
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    qr_bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);

    String path = null;//w w w  .j a  v a  2 s  . c  o m
    try {
        path = MediaStore.Images.Media.insertImage(getContentResolver(), qr_bitmap, "QR Code", null);
        if (path == null) {
            //turns out there's an Android bug, where it happens when the user hasn't taken a photo on the device before (i.e. gallery is empty
            //and hasn't been initialized.). The workaround is to initialize the photo directory manually:
            File sdcard = Environment.getExternalStorageDirectory();
            if (sdcard != null) {
                File mediaDir = new File(sdcard, "DCIM/Camera");
                if (!mediaDir.exists())
                    mediaDir.mkdirs();
            }
            path = MediaStore.Images.Media.insertImage(getContentResolver(), qr_bitmap, "QR Code", null);
        }
    } catch (Exception e) {
    }
    if (path == null) {
        String msg = getResources().getString(R.string.receive_err_no_media_access_msg);
        Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
        return;
    }

    Uri imageUri = Uri.parse(path);
    share.putExtra(Intent.EXTRA_STREAM, imageUri);
    if (show_private)
        share.putExtra(Intent.EXTRA_TEXT, private_key);
    else
        share.putExtra(Intent.EXTRA_TEXT, acct_addr);
    try {
        startActivity(Intent.createChooser(share, "Select"));
    } catch (android.content.ActivityNotFoundException ex) {
        ex.printStackTrace();
    }
}

From source file:palamarchuk.smartlife.app.fragments.ProfileFragment.java

private void feedback() {
    Intent sendIntent;/*  w  w w  . j  a v  a  2 s  .c o m*/
    sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "support@smartlife.com.kz" });
    sendIntent.putExtra(Intent.EXTRA_SUBJECT, "");
    sendIntent.putExtra(Intent.EXTRA_TEXT, "");
    sendIntent.setType("image/jpeg");

    try {
        startActivity(Intent.createChooser(sendIntent, "Send Mail"));
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(parentActivity, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
    }
}

From source file:org.peterbaldwin.client.android.tinyurl.SendTinyUrlActivity.java

private void send() {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");

    Intent originalIntent = getIntent();
    if (Intent.ACTION_SEND.equals(originalIntent.getAction())) {
        // Copy extras from the original intent because they might contain
        // additional information about the URL (e.g., the title of a
        // YouTube video). Do this before setting Intent.EXTRA_TEXT to avoid
        // overwriting the TinyURL.
        intent.putExtras(originalIntent.getExtras());
    }/*from   ww w  .ja  v  a  2  s .  com*/

    intent.putExtra(Intent.EXTRA_TEXT, mTinyUrl);
    try {
        CharSequence template = getText(R.string.title_send);
        String title = String.format(String.valueOf(template), mTinyUrl);
        startActivity(Intent.createChooser(intent, title));
        finish();
    } catch (ActivityNotFoundException e) {
        handleError(e);
    }
}

From source file:com.codebutler.farebot.activity.AdvancedCardInfoActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    try {//w w  w.  j  a va  2s  . c  o  m
        if (item.getItemId() == R.id.copy_xml) {
            String xml = mCard.toXml(FareBotApplication.getInstance().getSerializer());
            @SuppressWarnings("deprecation")
            ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            clipboard.setText(xml);
            Toast.makeText(this, "Copied to clipboard.", Toast.LENGTH_SHORT).show();
            return true;

        } else if (item.getItemId() == R.id.share_xml) {
            String xml = mCard.toXml(FareBotApplication.getInstance().getSerializer());
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, xml);
            startActivity(intent);
            return true;

        } else if (item.getItemId() == android.R.id.home) {
            finish();
            return true;
        }
    } catch (Exception ex) {
        new AlertDialog.Builder(this).setMessage(ex.toString()).show();
    }
    return false;
}

From source file:com.example.igorklimov.popularmoviesdemo.fragments.DetailFragment.java

private Intent createShareIntent() {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT, "#Popular Movies app https://www.youtube.com/watch?v=" + mTrailerUri);
    return intent;
}

From source file:org.teleportr.activity.Autocompletion.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

    case R.id.about:
        startActivity(new Intent(this, About.class));
        break;/*from ww  w. j  ava  2s . c  o  m*/

    case R.id.refresh:
        new FetchNearbyDownloads().execute("");
        break;

    case R.id.feedback:
        new AlertDialog.Builder(this).setTitle("feedback").setIcon(android.R.drawable.ic_dialog_info)
                .setPositiveButton("send logs", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        LogCollector.feedback(Autocompletion.this, "scotty@teleportr.org, flo@andlabs.de");
                    }
                }).setNeutralButton("mail scotty", new Dialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(Intent.ACTION_SENDTO,
                                Uri.parse("mailto:scotty@teleportr.org, flo@andlabs.de"));
                        intent.putExtra(Intent.EXTRA_SUBJECT, "feedback " + getString(R.string.app_name));
                        try {
                            PackageInfo info = getPackageManager().getPackageInfo("org.teleportr",
                                    PackageManager.GET_META_DATA);
                            intent.putExtra(Intent.EXTRA_TEXT,
                                    "version: " + info.versionName + " (" + info.versionCode + ") \n");
                        } catch (NameNotFoundException e) {
                        }
                        startActivity(intent);
                    }
                }).show();
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.piusvelte.sonet.core.SonetCreatePost.java

@Override
protected void onResume() {
    super.onResume();
    Intent intent = getIntent();//from w w w  .  ja  v a  2  s . co m
    if (intent != null) {
        String action = intent.getAction();
        if ((action != null) && action.equals(Intent.ACTION_SEND)) {
            if (intent.hasExtra(Intent.EXTRA_STREAM))
                getPhoto((Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM));
            if (intent.hasExtra(Intent.EXTRA_TEXT)) {
                final String text = intent.getStringExtra(Intent.EXTRA_TEXT);
                mMessage.setText(text);
                mCount.setText(Integer.toString(text.length()));
            }
            chooseAccounts();
        } else {
            Uri data = intent.getData();
            if ((data != null) && data.toString().contains(Accounts.getContentUri(this).toString())) {
                // default to the account passed in, but allow selecting additional accounts
                Cursor account = this.getContentResolver().query(Accounts.getContentUri(this),
                        new String[] { Accounts._ID, Accounts.SERVICE }, Accounts._ID + "=?",
                        new String[] { data.getLastPathSegment() }, null);
                if (account.moveToFirst())
                    mAccountsService.put(account.getLong(0), account.getInt(1));
                account.close();
            } else if (intent.hasExtra(Widgets.INSTANT_UPLOAD)) {
                // check if a photo path was passed and prompt user to select the account
                setPhoto(intent.getStringExtra(Widgets.INSTANT_UPLOAD));
                chooseAccounts();
            }
        }
    }
}

From source file:ca.mudar.mtlaucasou.services.SyncService.java

@Override
protected void onHandleIntent(Intent intent) {
    final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_STATUS_RECEIVER);
    if (receiver != null) {
        receiver.send(STATUS_RUNNING, Bundle.EMPTY);
    }/*from ww w.j  av a 2 s.  co m*/

    final Context context = this;

    try {
        // Bulk of sync work, performed by executing several fetches from
        // local and online sources.

        final long startLocal = System.currentTimeMillis();

        /**
         * Five Assets files to load, so progress goes by 20%.
         */
        Bundle bundle = new Bundle();
        bundle.putInt(Const.KEY_BUNDLE_PROGRESS_INCREMENT, 20);

        // Parse values from local cache first, since SecurityServices copy
        // or network might be down.

        receiver.send(STATUS_RUNNING, bundle);
        mLocalExecutor.execute(context, KmlLocalAssets.FIRE_HALLS,
                new RemotePlacemarksHandler(FireHalls.CONTENT_URI, true));

        receiver.send(STATUS_RUNNING, bundle);
        mLocalExecutor.execute(context, KmlLocalAssets.SPVM_STATIONS,
                new RemotePlacemarksHandler(SpvmStations.CONTENT_URI, true));

        receiver.send(STATUS_RUNNING, bundle);
        mLocalExecutor.execute(context, KmlLocalAssets.WATER_SUPPLIES,
                new RemotePlacemarksHandler(WaterSupplies.CONTENT_URI));

        receiver.send(STATUS_RUNNING, bundle);
        mLocalExecutor.execute(context, KmlLocalAssets.EMERGENCY_HOSTELS,
                new RemotePlacemarksHandler(EmergencyHostels.CONTENT_URI));

        receiver.send(STATUS_RUNNING, bundle);
        mLocalExecutor.execute(context, KmlLocalAssets.CONDITIONED_PLACES,
                new RemotePlacemarksHandler(ConditionedPlaces.CONTENT_URI));

        Log.v(TAG, "Sync duration: " + (System.currentTimeMillis() - startLocal) + " ms");

        // TODO: update data from remote source
        // Always hit remote SecurityServices for any updates
        // final long startRemote = System.currentTimeMillis();
        // mRemoteExecutor
        // .executeGet(WORKSHEETS_URL, new
        // RemoteSecurityServicesHandler(mRemoteExecutor));
        // Log.d(TAG, "remote sync took " + (System.currentTimeMillis() -
        // startRemote) + "ms");

    } catch (Exception e) {
        Log.e(TAG, e.getMessage());

        if (receiver != null) {
            /**
             * Pass back error to surface listener
             */
            final Bundle bundle = new Bundle();
            bundle.putString(Intent.EXTRA_TEXT, e.toString());
            receiver.send(STATUS_ERROR, bundle);
        }
    }

    if (receiver != null) {
        receiver.send(STATUS_FINISHED, Bundle.EMPTY);
    }
}

From source file:com.infine.android.devoxx.service.RestService.java

@Override
protected void onHandleIntent(Intent intent) {

    final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_STATUS_RECEIVER);

    // si passage du numero de version
    // final int latestVersion = intent.getIntExtra(EXTRA_LASTEST_VERSION,
    // 1);//ww  w.  j ava 2 s  .c  o m

    if (receiver != null)
        receiver.send(ServiceStatus.STATUS_RUNNING, Bundle.EMPTY);

    // final Context context = this;
    // final SharedPreferences prefs =
    // getSharedPreferences(Prefs.DEVOXX_SCHEDULE_SYNC,
    // Context.MODE_PRIVATE);
    // final int localVersion = prefs.getInt(Prefs.LOCAL_VERSION,
    // VERSION_NONE);

    try {

        // Bulk of sync work, performed by executing several fetches from
        // local and online sources.
        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mApplicationContext);
        int scheduleVersion = prefs.getInt(PREFS_SCHEDULE_VERSION, -1);
        int sessionVersion = prefs.getInt(PREFS_SESSION_VERSION, -1);
        int speakerVersion = prefs.getInt(PREFS_SPEAKER_VERSION, -1);

        if (scheduleVersion + sessionVersion + speakerVersion < 0) {
            // on charge les fichiers statiques que la premiere fois
            // ou quand un jeu de donnes schedule ou session est pourri
            // verion = -1
            loadStaticFiles();
        }
        loadStaticRoom();

        // Always hit remote spreadsheet for any updates
        loadRemoteData();

    } catch (Exception e) {
        Log.e(TAG, "Problem while syncing", e);
        if (receiver != null) {
            // Pass back error to surface listener
            final Bundle bundle = new Bundle();
            bundle.putString(Intent.EXTRA_TEXT, e.toString());
            receiver.send(STATUS_ERROR, bundle);
        }
    }

    // Announce success to any surface listener
    if (receiver != null)
        receiver.send(STATUS_FINISHED, Bundle.EMPTY);
}