Android Question Clear Clipboard - Source code

T201016

Active Member
Licensed User
Longtime User
Hi,
I admit that I lost somewhere sources of a subordinate memory class,
and I need a fast -acting code in B4A,
For the "clrettext" function - i.e. cleaning cache, in Java.

I want to proceed as for the "Settext" foundation in the example below.

Thank you in advance for your help.

B4A:
Public Sub SetText(txt As String) As Boolean
    Dim r As Reflector
    Dim jo As JavaObject
    jo = Me
    Dim bOk As Boolean
    bOk = jo.RunMethod("SetTextToClipboard", Array As Object(txt, r.GetContext))
    Return bOk
End Sub

Public Sub ClrText() As Boolean

    ...??...

End Sub


#IF JAVA

import android.content.ClipboardManager;
import android.content.ClipData;
import android.content.ClipDescription;
import android.content.Context;

public Boolean SetTextToClipboard(Object objtxt, Object mObjContext) {
    try{
        String txt = (String) objtxt;
        Context mContext = (Context) mObjContext;
        ClipboardManager myClipboard = (ClipboardManager) mContext.getSystemService("clipboard");
        ClipData myClip;
        myClip = ClipData.newPlainText("text", txt);
        myClipboard.setPrimaryClip(myClip);
        return true;
    }   
    catch(Exception ex){
        return false;
    }
};

...


#End If
 

Attachments

  • FORUM — kopia.txt
    905 bytes · Views: 43
Solution
Why not use the library Clipboard? it has clrText ,setText methods etc.
or
B4X:
Public Sub ClrText() As Boolean
    Dim ctx,jo=Me As JavaObject
    jo.RunMethod("SetTextToClipboard", Array As Object(Null, ctx.InitializeContext))
End Sub

teddybear

Well-Known Member
Licensed User
Why not use the library Clipboard? it has clrText ,setText methods etc.
or
B4X:
Public Sub ClrText() As Boolean
    Dim ctx,jo=Me As JavaObject
    jo.RunMethod("SetTextToClipboard", Array As Object(Null, ctx.InitializeContext))
End Sub
 
Last edited:
Upvote 0
Solution
Cookies are required to use this site. You must accept them to continue using the site. Learn more…