pasteboard.paste Android Bug?

Hi,

pasteboard.paste does not work on Android for me. My listener never even gets called and nothing happens when I try to paste. pasteboard.getType() does work. I can also paste my text into other apps (like gmail or notes) with no issues. pasteboard.paste() does work on iOS as well, but it does absolutely nothing on Android. Anyone else with this issue?

Thanks for any help.

Hi @naveen_pcs,

Can I see your basic code where pasteboard.paste() is being used for Android?

Brent

[lua]

local function didPaste(e)

print ("paste type: " … pasteboard.getType())

print ("paste string: " … tostring(e.string))

end

pasteboard.paste(didPaste)

[/lua]

The listener doesn’t even get called on Android. Tested the exact same code on iOS and Android, using the exact same string of text which I copied from an email. Im able to paste this string in other parts of the Android OS, just not in my Corona app.

What is the value of pasteboard.getType() before you attempt to use pasteboard.paste() ?

The value is “string”.

Hi @naveen_pcs,

Do you have another Android device to test on? If not, can you zip up your project (or a basic rendition of it) so I can test on mine?

Thanks,

Brent

I’ve actually tested it on 4 personal devices, plus I run a beta for my app with ~2,000 people on various devices. Every single person reports that it doesn’t work, regardless of android version, device etc.

Do you still need a project? It’s literally the 6 lines I posted a few posts above. Nothing else fancy is going on. I stripped down all my code to those few lines to test it.

Naveen

No, I don’t need a project, let me just test a bit on my side…

It works on my Android Asus ZenFone without any issues, same as iOS.

Here’s my test code:

[lua]local pasteboard = require( “plugin.pasteboard” )

local function didPaste(e)

    print ("paste type: " … pasteboard.getType())

    print ("paste string: " … tostring(e.string))

end

local function pasteb()

    pasteboard.paste( didPaste )

end

local b = display.newRect( 100, 100, 100, 100 )

b:setFillColor(1,0,0)

b:addEventListener( “tap”, pasteb )

[/lua]

It seems like this issue is only happening with long strings on Android. Shorter ones work, but longer ones with thousands of characters don’t. These long strings can be pasted in other parts of the Android OS, just not in my Corona app.

Are you getting and errors/warnings reported in the logcat?

I finally figured it out. It turns out that on Android, there’s a slight delay when doing pasteboard.paste(). Here’s what I was doing:

[lua]

local pastedText = nil

local function didPaste(e)

       pastedText = tostring(e.string)

end

pasteboard.paste(didPaste)

if (pastedText ~= nil) then

       --Some stuff here

end

[/lua]

The code would jump straight to line 9 before pastedText had a chance to be set to the data from the clipboard. So pastedText was being set correctly, the problem was that it was happening too late since the rest of the code had already run. iOS doesn’t have this problem. I solved it by putting in a small delay before running my if statement at line 9. Works perfectly now! I think you should maybe mention this, since it would seem like something you’d need to use fairly often when working with the clipboard. It took me a while to figure out what was going on, but I’m glad it’s all working now. I’m still not sure why my code from 5 posts up didn’t work. All the code was in a button listener and running on the began phase. Maybe there’s another bug lurking somewhere with pasteboard? I’ve separated it all out now and have it working with my timer delays. Thanks for the help!

Thanks for the info.

I’ll take a look at the Pasteboard code and see if there is anything funky going on.
Cheers

I am having the same issue. What did you do with a timer to fix it? In my situation I am using the string that is in the clipboard be put into a function and then the output is displayed in a textBox. The app works perfectly on iOS and is currently listed on the app store, but the android version is not working correctly.

Hi @naveen_pcs,

Can I see your basic code where pasteboard.paste() is being used for Android?

Brent

[lua]

local function didPaste(e)

print ("paste type: " … pasteboard.getType())

print ("paste string: " … tostring(e.string))

end

pasteboard.paste(didPaste)

[/lua]

The listener doesn’t even get called on Android. Tested the exact same code on iOS and Android, using the exact same string of text which I copied from an email. Im able to paste this string in other parts of the Android OS, just not in my Corona app.

What is the value of pasteboard.getType() before you attempt to use pasteboard.paste() ?

The value is “string”.

Hi @naveen_pcs,

Do you have another Android device to test on? If not, can you zip up your project (or a basic rendition of it) so I can test on mine?

Thanks,

Brent

I’ve actually tested it on 4 personal devices, plus I run a beta for my app with ~2,000 people on various devices. Every single person reports that it doesn’t work, regardless of android version, device etc.

Do you still need a project? It’s literally the 6 lines I posted a few posts above. Nothing else fancy is going on. I stripped down all my code to those few lines to test it.

Naveen