Example usage for android.content ClipboardManager setPrimaryClip

List of usage examples for android.content ClipboardManager setPrimaryClip

Introduction

In this page you can find the example usage for android.content ClipboardManager setPrimaryClip.

Prototype

public void setPrimaryClip(@NonNull ClipData clip) 

Source Link

Document

Sets the current primary clip on the clipboard.

Usage

From source file:com.irccloud.android.activity.VideoPlayerActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        finish();/*from   www . j a  v a 2s  .  c o m*/
        overridePendingTransition(R.anim.fade_in, R.anim.slide_out_right);
        return true;
    } else if (item.getItemId() == R.id.action_download) {
        if (Build.VERSION.SDK_INT >= 16 && ActivityCompat.checkSelfPermission(this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0);
        } else {
            DownloadManager d = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
            if (d != null) {
                String uri = getIntent().getDataString()
                        .replace(getResources().getString(R.string.VIDEO_SCHEME), "http");
                DownloadManager.Request r = new DownloadManager.Request(Uri.parse(uri));
                r.setDestinationInExternalPublicDir(Environment.DIRECTORY_MOVIES,
                        getIntent().getData().getLastPathSegment());
                r.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                r.allowScanningByMediaScanner();
                d.enqueue(r);
                Answers.getInstance().logShare(new ShareEvent().putContentType("Video").putMethod("Download"));
            }
        }
        return true;
    } else if (item.getItemId() == R.id.action_copy) {
        android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                CLIPBOARD_SERVICE);
        android.content.ClipData clip = android.content.ClipData.newRawUri("IRCCloud Video URL", Uri.parse(
                getIntent().getDataString().replace(getResources().getString(R.string.VIDEO_SCHEME), "http")));
        clipboard.setPrimaryClip(clip);
        Toast.makeText(VideoPlayerActivity.this, "Link copied to clipboard", Toast.LENGTH_SHORT).show();
        Answers.getInstance().logShare(new ShareEvent().putContentType("Video").putMethod("Copy to Clipboard"));
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && item.getItemId() == R.id.action_share) {
        Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse(
                getIntent().getDataString().replace(getResources().getString(R.string.VIDEO_SCHEME), "http")));
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT,
                getIntent().getDataString().replace(getResources().getString(R.string.VIDEO_SCHEME), "http"));
        intent.putExtra(ShareCompat.EXTRA_CALLING_PACKAGE, getPackageName());
        intent.putExtra(ShareCompat.EXTRA_CALLING_ACTIVITY,
                getPackageManager().getLaunchIntentForPackage(getPackageName()).getComponent());
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(Intent.createChooser(intent, "Share Video"));
        Answers.getInstance().logShare(new ShareEvent().putContentType("Video"));
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.gmail.taneza.ronald.carbs.main.MainActivity.java

@SuppressWarnings("deprecation")
private void copyMealTotalToClipboard() {
    String mealTotalValue = String.format(Locale.getDefault(), "%.1f", mTotalCarbsInGrams);

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                Context.CLIPBOARD_SERVICE);
        android.content.ClipData clip = android.content.ClipData.newPlainText("Carbs meal total",
                mealTotalValue);//from  w  ww  .ja v  a2s.c  o  m
        clipboard.setPrimaryClip(clip);
    } else {
        android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                Context.CLIPBOARD_SERVICE);
        clipboard.setText(mealTotalValue);
    }

    String message = String.format(Locale.US, getResources().getString(R.string.meal_total_copied_to_clipboard),
            mealTotalValue);
    Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
}

From source file:net.news.inrss.fragment.EntryFragment.java

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

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

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

            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 = MainApplication.getContext().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 = MainApplication.getContext().getContentResolver();
                    cr.update(uri, FeedData.getUnreadContentValues(), null, null);
                }
            }.start();
            activity.finish();
            break;
        }
        case R.id.menu_open_in_browser: {
            Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
            if (cursor != null) {
                String link = cursor.getString(mLinkPos);
                if (link != null) {
                    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
                    startActivity(browserIntent);
                }
            }
            break;
        }
        case R.id.menu_switch_full_original: {
            if (mPreferFullText) {
                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        mPreferFullText = false;
                        Log.d(TAG, "run: manual call of displayEntry(), fullText=false");
                        mEntryPagerAdapter.displayEntry(mCurrentPagerPos, null, true);
                    }
                });
            } else {
                Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
                final boolean alreadyMobilized = !cursor.isNull(mMobilizedHtmlPos);

                if (alreadyMobilized) {
                    Log.d(TAG, "onOptionsItemSelected: alreadyMobilized");
                    mPreferFullText = true;
                    activity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Log.d(TAG, "run: manual call of displayEntry(), fullText=true");
                            mEntryPagerAdapter.displayEntry(mCurrentPagerPos, null, true);
                        }
                    });
                } else if (!isRefreshing()) {
                    Log.d(TAG, "onOptionsItemSelected: about to load article...");
                    mPreferFullText = false;
                    ConnectivityManager connectivityManager = (ConnectivityManager) activity
                            .getSystemService(Context.CONNECTIVITY_SERVICE);
                    final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();

                    // since we have acquired the networkInfo, we use it for basic checks
                    if (networkInfo != null && networkInfo.getState() == NetworkInfo.State.CONNECTED) {
                        FetcherService.addEntriesToMobilize(new long[] { mEntriesIds[mCurrentPagerPos] });
                        activity.startService(new Intent(activity, FetcherService.class)
                                .setAction(FetcherService.ACTION_MOBILIZE_FEEDS));
                    } else {
                        activity.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(activity, R.string.network_error, Toast.LENGTH_SHORT).show();
                            }
                        });
                        Log.d(TAG, "onOptionsItemSelected: cannot load article. no internet connection.");
                    }
                } else {
                    Log.d(TAG, "onOptionsItemSelected: refreshing already in progress");
                }
            }
            mShowFullContentItem.setChecked(mPreferFullText);
            break;
        }
        default:
            break;
        }
    }

    return super.onOptionsItemSelected(item);
}

From source file:layout.FragmentBoardItemList.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    if (info.targetView.getParent() == listViewBoardItems) {
        BoardItem bi = boardItems.get(info.position);
        switch (item.getItemId()) {
        case R.id.menu_copy:
            System.out.println("Post copiado");
            ClipboardManager cm = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData cd = ClipData.newPlainText("Reply", boardItems.get(info.position).getMessage());
            cm.setPrimaryClip(cd);
            break;
        case R.id.menu_reply:
            Intent in = new Intent(getActivity().getApplicationContext(), ResponseActivity.class);
            Bundle b = new Bundle();
            b.putParcelable("theReply", boardItems.get(info.position));
            b.putBoolean("quoting", true);
            in.putExtras(b);/*  w w w  . j  a v a2  s. co  m*/
            getActivity().startActivity(in);
            break;
        case R.id.menu_savereply:
            try {
                File txt = new File(Environment.getExternalStorageDirectory().getPath() + "/Bai/"
                        + bi.getParentBoard().getBoardDir() + "_" + bi.getId() + ".txt");
                FileOutputStream stream = new FileOutputStream(txt);
                OutputStreamWriter outputStreamWriter = new OutputStreamWriter(stream);
                outputStreamWriter.write(bi.getMessage());
                outputStreamWriter.close();
                stream.close();
                Toast.makeText(getContext(),
                        bi.getParentBoard().getBoardDir() + "_" + bi.getId() + ".txt guardado.",
                        Toast.LENGTH_SHORT).show();
            } catch (Exception e) {
                e.printStackTrace();
            }
            break;
        case R.id.menu_delpost:
            deletePost(false, bi);
            break;
        case R.id.menu_delimage:
            deletePost(true, bi);
            break;
        }
    }
    return super.onContextItemSelected(item);
}

From source file:com.forrestguice.suntimeswidget.LocationConfigView.java

public void copyLocationToClipboard(Context context, boolean silent) {
    WidgetSettings.Location location = getLocation();
    String clipboardText = location.toString();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("lat, lon", clipboardText);
        clipboard.setPrimaryClip(clip);

    } else {/* w  w w .ja v a2 s  .c  o  m*/
        @SuppressWarnings("deprecation")
        android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context
                .getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setText(clipboardText);
    }

    if (!silent) {
        Toast copiedMsg = Toast.makeText(context,
                Html.fromHtml(context.getString(R.string.location_dialog_toast_copied, clipboardText)),
                Toast.LENGTH_LONG);
        copiedMsg.show();
    }
}

From source file:com.krayzk9s.imgurholo.ui.ImagesFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // handle item selection
    final Activity activity = getActivity();
    switch (item.getItemId()) {
    case R.id.action_download:
        Toast.makeText(activity,//  ww w.j a  v  a  2 s.  c o m
                String.format(getActivity().getResources().getString(R.string.toast_downloading), urls.size()),
                Toast.LENGTH_SHORT).show();
        Intent serviceIntent = new Intent(activity, DownloadService.class);
        serviceIntent.putParcelableArrayListExtra("ids", ids);
        if (albumId != null)
            serviceIntent.putExtra("albumName", albumId);
        else
            serviceIntent.putExtra("albumName", imageCall);
        activity.startService(serviceIntent);
        return true;
    case R.id.action_refresh:
        urls = new ArrayList<String>();
        ids = new ArrayList<JSONParcelable>();
        page = 0;
        makeGallery();
        return true;
    case R.id.action_copy:
        ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("imgur Link", "http://imgur.com/a/" + albumId);
        clipboard.setPrimaryClip(clip);
        Toast.makeText(activity, R.string.toast_copied, Toast.LENGTH_SHORT).show();
        return true;
    case R.id.action_share:
        Intent intent = new Intent(android.content.Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        intent.putExtra(Intent.EXTRA_TEXT, "http://imgur.com/a/" + albumId);
        startActivity(intent);
        return true;
    case R.id.action_new:
        Intent i = new Intent(this.getActivity().getApplicationContext(), ImageSelectActivity.class);
        startActivityForResult(i, 1);
        //select image
        return true;
    case R.id.action_comments:
        if (galleryAlbumData != null) {
            CommentsAsync commentsAsync = new CommentsAsync(((ImgurHoloActivity) getActivity()),
                    galleryAlbumData);
            commentsAsync.execute();
            return true;
        } else
            return super.onOptionsItemSelected(item);
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.almalence.opencam.Fragment.java

@TargetApi(13)
private void showCameraParameters() {
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
    alertDialog.setTitle(R.string.Pref_CameraParameters_Title);
    final StringBuilder about_string = new StringBuilder();
    String version = "UNKNOWN_VERSION";
    int version_code = -1;
    try {//from  www.j a  v  a 2 s. com
        PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
        version = pInfo.versionName;
        version_code = pInfo.versionCode;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    about_string.append("\nApplication name: ");
    about_string.append(MainScreen.getInstance().getResources().getString(R.string.Pref_About));
    about_string.append("\nAndroid API version: ");
    about_string.append(Build.VERSION.SDK_INT);
    about_string.append("\nDevice manufacturer: ");
    about_string.append(Build.MANUFACTURER);
    about_string.append("\nDevice model: ");
    about_string.append(Build.MODEL);
    about_string.append("\nDevice code-name: ");
    about_string.append(Build.HARDWARE);
    about_string.append("\nDevice variant: ");
    about_string.append(Build.DEVICE);
    {
        ActivityManager activityManager = (ActivityManager) getActivity()
                .getSystemService(Activity.ACTIVITY_SERVICE);
        about_string.append("\nStandard max heap (MB): ");
        about_string.append(activityManager.getMemoryClass());
        about_string.append("\nLarge max heap (MB): ");
        about_string.append(activityManager.getLargeMemoryClass());
    }
    {
        Point display_size = new Point();
        Display display = getActivity().getWindowManager().getDefaultDisplay();
        display.getSize(display_size);
        about_string.append("\nDisplay size: ");
        about_string.append(display_size.x);
        about_string.append("x");
        about_string.append(display_size.y);
    }

    //show camera 2 support level
    int level = CameraController.getCamera2Level();
    about_string.append("\nCamera2 API: ");
    switch (level) {
    case 0://limited
        about_string.append("limited");
        break;
    case 1://full
        about_string.append("full");
        break;
    case 2://legacy
        about_string.append("legacy");
        break;
    default:
        about_string.append("not supported");
    }

    //      about_string.append("\nSensor orientation, back camera: ");
    //      about_string.append(CameraController.getSensorOrientation(0));
    //      about_string.append("\nSensor orientation, front camera: ");
    //      about_string.append(CameraController.getSensorOrientation(1));

    if (MainScreen.getInstance().preview_sizes != null) {
        about_string.append("\nPreview resolutions: ");
        for (int i = 0; i < MainScreen.getInstance().preview_sizes.size(); i++) {
            if (i > 0) {
                about_string.append(", ");
            }
            about_string.append(MainScreen.getInstance().preview_sizes.get(i).getWidth());
            about_string.append("x");
            about_string.append(MainScreen.getInstance().preview_sizes.get(i).getHeight());
        }
    }

    about_string.append("\nCurrent camera ID: ");
    about_string.append(MainScreen.getInstance().cameraId);

    if (MainScreen.getInstance().picture_sizes != null) {
        about_string.append("\nPhoto resolutions: ");
        for (int i = 0; i < MainScreen.getInstance().picture_sizes.size(); i++) {
            if (i > 0) {
                about_string.append(", ");
            }
            about_string.append(MainScreen.getInstance().picture_sizes.get(i).getWidth());
            about_string.append("x");
            about_string.append(MainScreen.getInstance().picture_sizes.get(i).getHeight());
        }
    }

    if (MainScreen.getInstance().video_sizes != null) {
        about_string.append("\nVideo resolutions: ");
        for (int i = 0; i < MainScreen.getInstance().video_sizes.size(); i++) {
            if (i > 0) {
                about_string.append(", ");
            }
            about_string.append(MainScreen.getInstance().video_sizes.get(i).getWidth());
            about_string.append("x");
            about_string.append(MainScreen.getInstance().video_sizes.get(i).getHeight());
        }
    }

    about_string.append("\nVideo stabilization: ");
    about_string.append(MainScreen.getInstance().supports_video_stabilization ? "true" : "false");

    about_string.append("\nFlash modes: ");
    if (MainScreen.getInstance().flash_values != null && MainScreen.getInstance().flash_values.size() > 0) {
        for (int i = 0; i < MainScreen.getInstance().flash_values.size(); i++) {
            if (i > 0) {
                about_string.append(", ");
            }
            about_string.append(MainScreen.getInstance().flash_values.get(i));
        }
    } else {
        about_string.append("None");
    }

    about_string.append("\nFocus modes: ");
    if (MainScreen.getInstance().focus_values != null && MainScreen.getInstance().focus_values.size() > 0) {
        for (int i = 0; i < MainScreen.getInstance().focus_values.size(); i++) {
            if (i > 0) {
                about_string.append(", ");
            }
            about_string.append(MainScreen.getInstance().focus_values.get(i));
        }
    } else {
        about_string.append("None");
    }

    about_string.append("\nScene modes: ");
    if (MainScreen.getInstance().scene_modes_values != null
            && MainScreen.getInstance().scene_modes_values.size() > 0) {
        for (int i = 0; i < MainScreen.getInstance().scene_modes_values.size(); i++) {
            if (i > 0) {
                about_string.append(", ");
            }
            about_string.append(MainScreen.getInstance().scene_modes_values.get(i));
        }
    } else {
        about_string.append("None");
    }

    about_string.append("\nWhite balances: ");
    if (MainScreen.getInstance().white_balances_values != null
            && MainScreen.getInstance().white_balances_values.size() > 0) {
        for (int i = 0; i < MainScreen.getInstance().white_balances_values.size(); i++) {
            if (i > 0) {
                about_string.append(", ");
            }
            about_string.append(MainScreen.getInstance().white_balances_values.get(i));
        }
    } else {
        about_string.append("None");
    }

    about_string.append("\nISOs: ");
    if (MainScreen.getInstance().isos != null && MainScreen.getInstance().isos.size() > 0) {
        for (int i = 0; i < MainScreen.getInstance().isos.size(); i++) {
            if (i > 0) {
                about_string.append(", ");
            }
            about_string.append(MainScreen.getInstance().isos.get(i));
        }
    } else {
        about_string.append("None");
    }

    String save_location = SavingService.getSaveToPath();
    about_string.append("\nSave Location: " + save_location);

    if (MainScreen.getInstance().flattenParamteters != null
            && !MainScreen.getInstance().flattenParamteters.equals("")) {
        about_string.append("\nFULL INFO:\n");
        about_string.append(MainScreen.getInstance().flattenParamteters);
    }

    alertDialog.setMessage(about_string);
    alertDialog.setPositiveButton(R.string.Pref_CameraParameters_Ok, null);
    alertDialog.setNegativeButton(R.string.Pref_CameraParameters_CopyToClipboard,
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    ClipboardManager clipboard = (ClipboardManager) getActivity()
                            .getSystemService(Activity.CLIPBOARD_SERVICE);
                    ClipData clip = ClipData.newPlainText("OpenCamera About", about_string);
                    clipboard.setPrimaryClip(clip);
                }
            });
    alertDialog.show();
}

From source file:de.enlightened.peris.PostsFragment.java

@SuppressLint("NewApi")
private void storePostInClipboard() {

    //Copy text support for all Android versions
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        final ClipboardManager clipboard = (ClipboardManager) this.activity
                .getSystemService(Context.CLIPBOARD_SERVICE);
        final ClipData cd = ClipData.newHtmlText(this.currentThreadSubject, this.selectedPost.body,
                this.selectedPost.body);
        clipboard.setPrimaryClip(cd);
    } else {//from ww  w .j a  v  a 2s.c o m
        final android.text.ClipboardManager clipboard = (android.text.ClipboardManager) this.activity
                .getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setText(this.selectedPost.body);
    }

    final Toast toast = Toast.makeText(this.activity, "Text copied!", Toast.LENGTH_SHORT);
    toast.show();
}

From source file:com.tinfoil.sms.sms.SendMessageActivity.java

@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void copyText(String message) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {

        android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                Context.CLIPBOARD_SERVICE);
        android.content.ClipData clip = android.content.ClipData.newPlainText(MESSAGE_LABEL, message);
        clipboard.setPrimaryClip(clip);
    } else {/*from   w ww  .j  a  va 2s  . c  o  m*/

        android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                Context.CLIPBOARD_SERVICE);
        clipboard.setText(message);
    }
}

From source file:com.ucmap.dingdinghelper.services.DingDingHelperAccessibilityService.java

/**
 * //  ww w  .ja va  2s. co  m
 */
private void setTextToView(AccessibilityNodeInfo node, String text) {
    Bundle arguments = new Bundle();
    arguments.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT,
            AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD);
    arguments.putBoolean(AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN, true);
    node.performAction(AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY, arguments);
    /*?*/
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Bundle args = new Bundle();
        args.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, text);
        node.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, args);
    } else {
        ClipData data = ClipData.newPlainText("reply", text);
        ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        clipboardManager.setPrimaryClip(data);
        node.performAction(AccessibilityNodeInfo.ACTION_FOCUS); // ?
        node.performAction(AccessibilityNodeInfo.ACTION_PASTE); // 
    }

}