Android ClipboardManager - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android ClipboardManager class.

This code example shows how to use the following methods:getText, hasText
    } 
 
    @Override 
    public String getText() {
        final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
        if ( clipboard.hasText() ) {
            return String.valueOf(clipboard.getText());
        } else { 
            return null; 
        } 
    } 
 
    @Override 
    public void setText(@NotNull String text) {
        final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setText(text);
    } 
 
    @Override 
    public void setText(@NotNull CharSequence text) {
6
CodeRank
This code example shows how to use the following methods:setText
	 
	public static void copyToClipboard(Context context, String text) throws SamsungClipboardException {
		ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
		 
		try { 
			clipboard.setText(text);
		} catch (NullPointerException e) {
			throw new SamsungClipboardException(e);
		} 
	} 
	 
	public static void gotoUrl(Context context, String url) throws ActivityNotFoundException {
		if ( url != null && url.length() > 0 ) {
			Uri uri = Uri.parse(url);
			context.startActivity(new Intent(Intent.ACTION_VIEW, uri));
		} 
	} 
	 
	public static void gotoUrl(Context context, int resId) throws ActivityNotFoundException {
		gotoUrl(context, context.getString(resId));
6
CodeRank
This code example shows how to use the following methods:getText, hasText
	public void setText(CharSequence text) {
		cbV3.setText(text);
	} 
 
	public CharSequence getText() {
		if (cbV3.hasText())
			return cbV3.getText();
		else 
			return null; 
	} 
} 
6
CodeRank
This code example shows how to use the following methods:getText, hasText, setText
    @Override 
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
         
        ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        if (cm.hasText()) {
        	CharSequence cs = cm.getText();
        	if (cs != null) {
        		String data = cs.toString();
				try { 
					int num = Integer.parseInt(data);
	        		String convertData = String.valueOf(num);
	        		cm.setText(convertData);
	        		showMessage("変換に成功しました。"); 
				} catch (NumberFormatException e) {
					showMessage("数値以外の文字が含まれています。"); 
				} 
        	} 
        } else { 
        	showMessage("クリップボードが空です"); 
5
CodeRank
This code example shows how to use the following methods:getText, hasText, setText
             
            String clipboardPassword = Session.getInstance().getClipboardPassword();
            // We only clear the clipboard when the content equals the last 
            // copied password. 
            if (clipboardPassword != null &&
                cm.hasText() &&
                cm.getText().equals(clipboardPassword)) {
 
                cm.setText("");
                Session.getInstance().setClipboardPassword(null); 
            } 
        } 
    } 
} 
5
CodeRank
This code example shows how to use the following methods:setText
 
    public static void copyToClipBoard(final Context context,
            final String content) {
        final ClipboardManager cm = (ClipboardManager) context
                .getSystemService(Context.CLIPBOARD_SERVICE);
        cm.setText(content);
    } 
 
    public static void deleteDir(final File target) {
        if (!target.exists()) {
            return; 
        } 
        if (target.isFile()) {
            target.delete();
        } 
 
        if (target.isDirectory()) {
            final File[] files = target.listFiles();
            for (final File file : files) {
                IOHelper.deleteDir(file);
5
CodeRank
This code example shows how to use the following methods:setText
    } 
 
    public final void setClipboardContent (String newText)
    { 
        ClipboardManager clipboard = (ClipboardManager) getSystemService (CLIPBOARD_SERVICE);
        clipboard.setText (newText);
    } 
 
    //============================================================================== 
    public final void showMessageBox (String title, String message, final long callback)
    { 
        AlertDialog.Builder builder = new AlertDialog.Builder (this);
        builder.setTitle (title)
               .setMessage (message)
               .setCancelable (true)
               .setPositiveButton ("OK", new DialogInterface.OnClickListener()
                    { 
                        public void onClick (DialogInterface dialog, int id)
                        { 
                            dialog.cancel();
4
CodeRank
This code example shows how to use the following methods:setText
This code example shows how to use the following methods:setText
This code example shows how to use the following methods:setText
 
	public static void copyTextToClipboard(String text) {
		Context c = AppConfig.getInstance();
		if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB){
			android.text.ClipboardManager clipboard = (ClipboardManager) c.getSystemService(Context.CLIPBOARD_SERVICE);
			clipboard.setText(text);
		} else { 
			android.content.ClipboardManager clipboard = (android.content.ClipboardManager) c.getSystemService(Context.CLIPBOARD_SERVICE);
			ClipData data = ClipData.newPlainText("Copied Text", text);
			clipboard.setPrimaryClip(data);
		} 
		ToastHelper.show("已复制"); 
	} 
} 
4
CodeRank

Related Android ClipboardManager Questions & Answers:

See Code Examples for Android ClipboardManager Methods: