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:net.peterkuterna.android.apps.devoxxsched.service.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);

    final Context context = this;
    final SharedPreferences syncServicePrefs = getSharedPreferences(SyncPrefs.DEVOXXSCHED_SYNC,
            Context.MODE_PRIVATE);
    final int localVersion = syncServicePrefs.getInt(SyncPrefs.LOCAL_VERSION, VERSION_NONE);
    final long lastRemoteSync = syncServicePrefs.getLong(SyncPrefs.LAST_REMOTE_SYNC, 0);

    try {//  www . j av  a 2  s.  c om
        // Bulk of sync work, performed by executing several fetches from
        // local and online sources.

        final long startLocal = System.currentTimeMillis();
        final boolean localParse = localVersion < VERSION_LOCAL;
        Log.d(TAG, "found localVersion=" + localVersion + " and VERSION_LOCAL=" + VERSION_LOCAL);
        if (localParse) {
            // Parse values from local cache first
            mLocalExecutor.execute(R.xml.search_suggest, new LocalSearchSuggestHandler());
            mLocalExecutor.execute(context, "cache-rooms.json", new RemoteRoomsHandler());
            mLocalExecutor.execute(context, "cache-presentationtypes.json", new RemoteSessionTypesHandler());
            mLocalExecutor.execute(context, "cache-speakers.json", new RemoteSpeakersHandler());
            mLocalExecutor.execute(context, "cache-presentations.json", new RemoteSessionsHandler());
            mLocalExecutor.execute(context, "cache-schedule.json", new RemoteScheduleHandler());

            // Save local parsed version
            syncServicePrefs.edit().putInt(SyncPrefs.LOCAL_VERSION, VERSION_LOCAL).commit();
        }
        Log.d(TAG, "local sync took " + (System.currentTimeMillis() - startLocal) + "ms");

        final long startRemote = System.currentTimeMillis();
        boolean performRemoteSync = performRemoteSync(mResolver, mHttpClient, intent, context);
        if (performRemoteSync) {
            // Parse values from REST interface
            ArrayList<RequestHash> result = mRemoteExecutor.executeGet(new String[] { Constants.ROOMS_URL, },
                    new RemoteRoomsHandler());
            for (RequestHash requestHash : result) {
                SyncUtils.updateLocalMd5(mResolver, requestHash.getUrl(), requestHash.getMd5());
            }
            result = mRemoteExecutor.executeGet(new String[] { Constants.LABS_PRESENTATION_TYPES_URL, },
                    new RemoteSessionTypesHandler());
            for (RequestHash requestHash : result) {
                SyncUtils.updateLocalMd5(mResolver, requestHash.getUrl(), requestHash.getMd5());
            }
            result = mRemoteExecutor.executeGet(
                    new String[] { Constants.SPEAKERS_URL, Constants.LABS_SPEAKERS_URL, },
                    new RemoteSpeakersHandler());
            for (RequestHash requestHash : result) {
                SyncUtils.updateLocalMd5(mResolver, requestHash.getUrl(), requestHash.getMd5());
            }
            result = mRemoteExecutor.executeGet(
                    new String[] { Constants.PRESENTATIONS_URL, Constants.LABS_PRESENTATIONS_URL, },
                    new RemoteSessionsHandler());
            for (RequestHash requestHash : result) {
                SyncUtils.updateLocalMd5(mResolver, requestHash.getUrl(), requestHash.getMd5());
            }
            result = mRemoteExecutor.executeGet(
                    new String[] { Constants.SCHEDULE_URL, Constants.LABS_SCHEDULE_URL, },
                    new RemoteScheduleHandler());
            for (RequestHash requestHash : result) {
                SyncUtils.updateLocalMd5(mResolver, requestHash.getUrl(), requestHash.getMd5());
            }

            // Save last remote sync time
            syncServicePrefs.edit().putLong(SyncPrefs.LAST_REMOTE_SYNC, startRemote).commit();
            // Save remote parsed version
            syncServicePrefs.edit().putInt(SyncPrefs.LOCAL_VERSION, VERSION_REMOTE).commit();
        }
        Log.d(TAG, "remote sync took " + (System.currentTimeMillis() - startRemote) + "ms");

        if (!localParse && performRemoteSync) {
            NotificationUtils.cancelNotifications(context);
            NotificationUtils.notifyNewSessions(context, getContentResolver());
            NotificationUtils.notifyChangedStarredSessions(context, getContentResolver());
        }
    } 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
    Log.d(TAG, "sync finished");
    if (receiver != null)
        receiver.send(STATUS_FINISHED, Bundle.EMPTY);
}

From source file:bupt.tiantian.callrecorder.callrecorder.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        Intent intent = new Intent(this, SettingsActivity.class);
        intent.putExtra("write_external", permissionWriteExternal);
        startActivity(intent);/* ww w.j a  v  a  2s .  co m*/
        return true;
    }

    if (id == R.id.action_save) {
        if (null != selectedItems && selectedItems.length > 0) {
            Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    for (PhoneCallRecord record : selectedItems) {
                        record.getPhoneCall().setKept(true);
                        record.getPhoneCall().save(MainActivity.this);
                    }
                    LocalBroadcastManager.getInstance(MainActivity.this)
                            .sendBroadcast(new Intent(LocalBroadcastActions.NEW_RECORDING_BROADCAST)); // Causes refresh

                }
            };
            handler.post(runnable);
        }
        return true;
    }

    if (id == R.id.action_share) {
        if (null != selectedItems && selectedItems.length > 0) {
            Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    ArrayList<Uri> fileUris = new ArrayList<Uri>();
                    for (PhoneCallRecord record : selectedItems) {
                        fileUris.add(Uri.fromFile(new File(record.getPhoneCall().getPathToRecording())));
                    }
                    Intent shareIntent = new Intent();
                    shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
                    shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, fileUris);
                    shareIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.email_title));
                    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
                        shareIntent.putExtra(Intent.EXTRA_HTML_TEXT,
                                Html.fromHtml(getString(R.string.email_body_html), Html.FROM_HTML_MODE_LEGACY));
                    } else {
                        shareIntent.putExtra(Intent.EXTRA_HTML_TEXT,
                                Html.fromHtml(getString(R.string.email_body_html)));
                    }
                    shareIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.email_body));
                    shareIntent.setType("audio/*");
                    startActivity(Intent.createChooser(shareIntent, getString(R.string.action_share)));
                }
            };
            handler.post(runnable);
        }
        return true;
    }

    if (id == R.id.action_delete) {
        if (null != selectedItems && selectedItems.length > 0) {
            AlertDialog.Builder alert = new AlertDialog.Builder(this);
            alert.setTitle(R.string.delete_recording_title);
            alert.setMessage(R.string.delete_recording_subject);
            alert.setPositiveButton(R.string.dialog_yes, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {

                    Runnable runnable = new Runnable() {
                        @Override
                        public void run() {
                            Database callLog = Database.getInstance(MainActivity.this);
                            for (PhoneCallRecord record : selectedItems) {
                                int id = record.getPhoneCall().getId();
                                callLog.removeCall(id);
                            }

                            LocalBroadcastManager.getInstance(MainActivity.this).sendBroadcast(
                                    new Intent(LocalBroadcastActions.RECORDING_DELETED_BROADCAST));
                            //?selectedItems
                            onListFragmentInteraction(new PhoneCallRecord[] {});
                        }
                    };
                    handler.post(runnable);

                    dialog.dismiss();

                }
            });
            alert.setNegativeButton(R.string.dialog_no, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {

                    dialog.dismiss();
                }
            });

            alert.show();
        }
        return true;
    }

    if (id == R.id.action_delete_all) {

        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setTitle(R.string.delete_recording_title);
        alert.setMessage(R.string.delete_all_recording_subject);
        alert.setPositiveButton(R.string.dialog_yes, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {

                Runnable runnable = new Runnable() {
                    @Override
                    public void run() {
                        Database.getInstance(MainActivity.this).removeAllCalls(false);
                        LocalBroadcastManager.getInstance(getApplicationContext())
                                .sendBroadcast(new Intent(LocalBroadcastActions.RECORDING_DELETED_BROADCAST));
                        //?selectedItems
                        onListFragmentInteraction(new PhoneCallRecord[] {});
                    }
                };
                handler.post(runnable);

                dialog.dismiss();

            }
        });
        alert.setNegativeButton(R.string.dialog_no, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {

                dialog.dismiss();
            }
        });

        alert.show();

        return true;
    }

    if (R.id.action_whitelist == id) {
        if (permissionReadContacts) {
            Intent intent = new Intent(this, WhitelistActivity.class);
            startActivity(intent);
        } else {
            AlertDialog.Builder alert = new AlertDialog.Builder(this);
            alert.setTitle(R.string.permission_whitelist_title);
            alert.setMessage(R.string.permission_whitelist);
        }
        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.carlrice.reader.fragment.EntryFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (mEntriesIds != null) {
        Activity activity = getActivity();

        switch (item.getItemId()) {
        case R.id.menu_star: {
            mFavorite = !mFavorite;//from w  w w  .j a v a2  s .  c  o m

            if (mFavorite) {
                item.setTitle(R.string.menu_unstar).setIcon(R.drawable.rating_important);
            } else {
                item.setTitle(R.string.menu_star).setIcon(R.drawable.rating_not_important);
            }

            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread() {
                @Override
                public void run() {
                    ContentValues values = new ContentValues();
                    values.put(EntryColumns.IS_FAVORITE, mFavorite ? 1 : 0);
                    ContentResolver cr = Application.context().getContentResolver();
                    cr.update(uri, values, null, null);

                    // Update the cursor
                    Cursor updatedCursor = cr.query(uri, null, null, null, null);
                    updatedCursor.moveToFirst();
                    mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor);
                }
            }.start();
            break;
        }
        case R.id.menu_share: {
            Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
            if (cursor != null) {
                String link = cursor.getString(mLinkPos);
                if (link != null) {
                    String title = cursor.getString(mTitlePos);
                    startActivity(Intent.createChooser(
                            new Intent(Intent.ACTION_SEND).putExtra(Intent.EXTRA_SUBJECT, title)
                                    .putExtra(Intent.EXTRA_TEXT, link).setType(Constants.MIMETYPE_TEXT_PLAIN),
                            getString(R.string.menu_share)));
                }
            }
            break;
        }
        case R.id.menu_full_screen: {
            setImmersiveFullScreen(true);
            break;
        }
        case R.id.menu_copy_clipboard: {
            Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
            String link = cursor.getString(mLinkPos);
            ClipboardManager clipboard = (ClipboardManager) activity
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("Copied Text", link);
            clipboard.setPrimaryClip(clip);

            Toast.makeText(activity, R.string.copied_clipboard, Toast.LENGTH_SHORT).show();
            break;
        }
        case R.id.menu_mark_as_unread: {
            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread() {
                @Override
                public void run() {
                    ContentResolver cr = Application.context().getContentResolver();
                    cr.update(uri, FeedData.getUnreadContentValues(), null, null);
                }
            }.start();
            activity.finish();
            break;
        }
        }
    }

    return true;
}

From source file:com.architjn.materialicons.ui.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_sendemail) {
        StringBuilder emailBuilder = new StringBuilder();

        Intent intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("mailto:" + getResources().getString(R.string.email_id)));
        intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.email_subject));

        emailBuilder.append("\n \n \nOS Version: ").append(System.getProperty("os.version")).append("(")
                .append(Build.VERSION.INCREMENTAL).append(")");
        emailBuilder.append("\nOS API Level: ").append(Build.VERSION.SDK_INT);
        emailBuilder.append("\nDevice: ").append(Build.DEVICE);
        emailBuilder.append("\nManufacturer: ").append(Build.MANUFACTURER);
        emailBuilder.append("\nModel (and Product): ").append(Build.MODEL).append(" (").append(Build.PRODUCT)
                .append(")");
        PackageInfo appInfo = null;/*from   ww  w.j av  a  2s  . c om*/
        try {
            appInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        assert appInfo != null;
        emailBuilder.append("\nApp Version Name: ").append(appInfo.versionName);
        emailBuilder.append("\nApp Version Code: ").append(appInfo.versionCode);

        intent.putExtra(Intent.EXTRA_TEXT, emailBuilder.toString());
        startActivity(Intent.createChooser(intent, (getResources().getString(R.string.send_title))));
        return true;
    } else if (id == R.id.action_share) {
        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        String shareBody = getResources().getString(R.string.share_one)
                + getResources().getString(R.string.developer_name)
                + getResources().getString(R.string.share_two) + MARKET_URL + getPackageName();
        sharingIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
        startActivity(Intent.createChooser(sharingIntent, (getResources().getString(R.string.share_title))));
    } else if (id == R.id.action_changelog) {
        showChangelog();
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.code.android.vibevault.ShowDetailsScreen.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.nowPlaying: //Open playlist activity
        Intent i = new Intent(ShowDetailsScreen.this, NowPlayingScreen.class);

        startActivity(i);/*from  w  w  w .  java2s.c  o  m*/
        break;
    case R.id.recentShows:
        Intent rs = new Intent(ShowDetailsScreen.this, RecentShowsScreen.class);

        startActivity(rs);
        break;
    case R.id.scrollableDialog:
        AlertDialog.Builder ad = new AlertDialog.Builder(this);
        ad.setTitle("Help!");
        View v = LayoutInflater.from(this).inflate(R.layout.scrollable_dialog, null);
        ((TextView) v.findViewById(R.id.DialogText)).setText(R.string.show_details_screen_help);
        ad.setPositiveButton("Okay.", new android.content.DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int arg1) {
            }
        });
        ad.setView(v);
        ad.show();
        break;
    case R.id.emailLink:
        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.setType("plain/text");
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                "Great show on archive.org: " + show.getArtistAndTitle());
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
                "Hey,\n\nYou should listen to " + show.getArtistAndTitle() + ".  You can find it here: "
                        + show.getShowURL() + "\n\nSent using VibeVault for Android.");
        startActivity(Intent.createChooser(emailIntent, "Send mail..."));
        break;
    case R.id.downloadShow:
        for (int j = 0; j < downloadLinks.size(); j++) {
            downloadLinks.get(j).setDownloadShow(show);
            dService.addSong(downloadLinks.get(j));
        }
        break;
    default:
        break;
    }
    return true;
}

From source file:com.anysoftkeyboard.ui.dev.DeveloperToolsFragment.java

private void shareFile(File fileToShare, String title, String message) {
    Intent sendMail = new Intent();
    sendMail.setAction(Intent.ACTION_SEND);
    sendMail.setType("plain/text");
    sendMail.putExtra(Intent.EXTRA_SUBJECT, title);
    sendMail.putExtra(Intent.EXTRA_TEXT, message);
    if (fileToShare != null) {
        sendMail.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(fileToShare));
    }// w  w  w  .j  a  v  a  2s  .c  o  m

    try {
        Intent sender = Intent.createChooser(sendMail, "Share");
        sender.putExtra(Intent.EXTRA_SUBJECT, title);
        sender.putExtra(Intent.EXTRA_TEXT, message);
        startActivity(sender);
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(getActivity().getApplicationContext(), "Unable to send bug report via e-mail!",
                Toast.LENGTH_LONG).show();
    }
}

From source file:com.code19.library.SystemUtils.java

public static void shareText(Context ctx, String title, String text) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    //intent.putExtra(Intent.EXTRA_SUBJECT, title);
    intent.putExtra(Intent.EXTRA_TEXT, text);
    ctx.startActivity(Intent.createChooser(intent, title));
    /* List<ResolveInfo> ris = getShareTargets(ctx);
     if (ris != null && ris.size() > 0) {
    ctx.startActivity(Intent.createChooser(intent, title));
     }*//*from  w w w . j av  a 2  s .  co m*/
}

From source file:ch.dbrgn.android.simplerepost.activities.RepostActivity.java

private void createInstagramIntent(String type, String mediaPath, String caption) {
    // Create the new Intent using the 'Send' action.
    Intent share = new Intent(Intent.ACTION_SEND);

    // Set the MIME type
    share.setType(type);// ww  w.ja va 2 s.  c  om

    // Create the URI from the media
    File media = new File(mediaPath);
    Uri uri = Uri.fromFile(media);

    // Add the URI and the caption to the Intent.
    share.putExtra(Intent.EXTRA_STREAM, uri);
    share.putExtra(Intent.EXTRA_TEXT, caption);

    // Broadcast the Intent.
    startActivity(Intent.createChooser(share, "Share to"));
}

From source file:key.secretkey.crypto.PgpHandler.java

public void shareAsPlaintext() {

    if (findViewById(R.id.share_password_as_plaintext) == null)
        return;//from w ww  .  jav  a  2  s  .  c  o m

    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT, decodedPassword);
    sendIntent.setType("text/plain");
    startActivity(
            Intent.createChooser(sendIntent, getResources().getText(R.string.send_plaintext_password_to)));//Always show a picker to give the user a chance to cancel
}