Button to copy the value of a string to the clipboard

后端 未结 2 441
别跟我提以往
别跟我提以往 2021-02-09 15:01

I\'m modifying an old Android application. I have a GPS lat and long being stored in a string value and displayed to the user in a non-editable text box when it resolves. I wa

相关标签:
2条回答
  • 2021-02-09 15:15

    If it is just Text, it is very simple.

    ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("label","Your Text");
    clipboard.setPrimaryClip(clip);
    

    For further Information check out this link

    0 讨论(0)
  • 2021-02-09 15:15

    provide a context before

    getSystemService(Context.CLIPBOARD_SERVICE);
    

    like

    Context context = ...;
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    
    0 讨论(0)
提交回复
热议问题