Android Question Using the clipboard to copy text between applications

akf

New Member
Licensed User
Longtime User
In my app (under B4XPages) I want to create a notification as a button function in which two action buttons should offer the option of placing a text string in the clipboard. I then want to paste the respective value in a notes app after copying, for example. Up to this point everything works as desired. In debugging I can see that the correct values are placed in the clipboard - if I paste the value in the other app I always get the same value, usually the one copied first.
For testing purposes I have added a text field to the layout in my source application. If I now carry out the two copy actions one after the other from the notification, I always get the correct value from the clipboard when pasting.
What is my mistake?
 
Solution
Since the recipient of the data is any other application (browser, text editor, etc.), the data could not be read from a file. Maybe I can find another solution.
Thank you for the quick help!

akf

New Member
Licensed User
Longtime User
First choose a list entry:

Trigger.jpg


Put the data into global variables and set the notification:

B4X:
Private Sub notifIV_Click        'AKF13112024
        
    Private pnl As Panel
    Private lv_index As Int
    Private lv_line, lv_value As String
    
    lv_index = clv.GetItemFromView(Sender)
    pnl = clv.GetPanel(lv_index)

    lv_line = Main.ga_csv(Main.gv_cat_index).Get(0)
    Main.gv_nf_cat = AKFstrings.CutString(lv_line, "#", 1)

    lv_line = Main.ga_csv(Main.gv_cat_index).Get(lv_index+2)        '2 addieren um auf den gewählten Eintrag zu positionieren
    Main.gv_nf_titel = DelQuotas(AKFstrings.CutString(lv_line, ",", 1))
    Main.gv_nf_user = DelQuotas(AKFstrings.CutString(lv_line, ",", 2))
    Main.gv_nf_pwd = DelQuotas(AKFstrings.CutString(lv_line, ",", 3))
    
    PublicSubs.Notification_Set
    
End Sub

B4X:
'Code module: PublicSubs
'Subs in this code module will be accessible from all modules.
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI 'standard

End Sub

Sub Notification_Set        'AKF13112024
        
    Private cs As CSBuilder
    Private lv_icon As Bitmap
    Private lv_titel As String
    
    lv_icon = LoadBitmapResize(File.DirAssets, "notificon.png", 24dip, 24dip, False)
    
    Main.NF.Initialize("default", Application.LabelName, "HIGH").SmallIcon(lv_icon)
    Main.NF.AddButtonAction(lv_icon, "User", MyReceiver, "ActUser")
    Main.NF.AddButtonAction(lv_icon, "Password", MyReceiver, "ActPass")
    
    Main.NF.AddButtonAction(Null, cs.Initialize.Color(Colors.Red).Bold.Append("Close").PopAll, MyReceiver, "ActCancel")
    Main.NF.DeleteAction(MyReceiver, "delete action")
    Main.NF.OnGoing(True)
    
    cs.Initialize.size(22).Color(Colors.DarkGray).Bold.Append("Entry: ").Color(Colors.blue).Bold.Append(Main.gv_nf_cat & " - " & Main.gv_nf_titel).PopAll
    Main.NF.Build("MyPasswords", cs, "tag", Main).Notify(1)
    Main.gv_nf_active = True
    
End Sub

Here is the notification:

Action.jpg


Then switch to a Notes App, open the notification, choose the first action (ActUser) and paste the value from the clipboard.
Open the notification once again, choose the second action (ActPass) and paste from clipboard into the notes app.

Logging the data:

Logs.jpg


And the result:

Notice.jpg
 

Attachments

  • Notice.jpg
    Notice.jpg
    39.7 KB · Views: 10
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

akf

New Member
Licensed User
Longtime User
Since the recipient of the data is any other application (browser, text editor, etc.), the data could not be read from a file. Maybe I can find another solution.
Thank you for the quick help!
 
Upvote 0
Solution
Top