I did a test application based on an example above from Joshua and a sample for Pic2Shop integration. I’m using Android right now.
I’m calling QR scanner pic2shop and specify a callback. What happens is that the application is called after scanning image but no data is passed. I also did a test with my own application to start this code and found that it only works if application is cold started, not on resume.
I had to add a native.requestExit(); to get it to work but I dont want to close the application and I had other side effetcs like returning to pic2shop scanner.
-- Example showing how to integrate Pic2Shop Barcode Scanning into a Corona APP -- Sample code is MIT licensed, see http://www.coronalabs.com/links/code/license -- Copyright (C) 2013 Minion Multimedia. All Rights Reserved. local scanButton local information scanButton = display.newRect( 10, 50, 100, 50 ) scanButton:setFillColor ( 244 ) information = display.newText( "Press Above to Scan", 10, 120, 200, 0, native.systemFont, 20 ) local function buttonTouch ( event ) if event.phase == "ended" then system.openURL( "pic2shop://scan?callback=yourapp%3A") end end scanButton:addEventListener ( "touch", buttonTouch ) -- Prints all contents of a Lua table to the log. local function printTable(table, stringPrefix) if not stringPrefix then stringPrefix = "### " end if type(table) == "table" then for key, value in pairs(table) do if type(value) == "table" then print(stringPrefix .. tostring(key)) print(stringPrefix .. "{") printTable(value, stringPrefix .. " ") print(stringPrefix .. "}") else print(stringPrefix .. tostring(key) .. ": " .. tostring(value)) end end end end local launchArguments = ... if launchArguments then print("yourapp: ### --- Launch Arguments ---") printTable(launchArguments) end local launchURL local function onSystemEvent( event ) print( "yourapp: onSystemEvent [" .. tostring(event.type) .. "] URL: " .. tostring(event.url) ) if event.type == "applicationSuspend" then --native.requestExit(); elseif event.type == "applicationOpen" and event.url then -- Prints all launch arguments printTable(event) launchURL = event.url information.text = "Raw: " .. event.url print( launchURL ) -- output: coronasdkapp://mycustomstring local testA = string.find ( launchURL, "=" ) if tostring(testA) ~= "nil" then barCodeFinal = string.sub ( launchURL, testA + 1 ) information.text = information.text .. "\n" .. "Afterwards: " .. barCodeFinal information.x = 10 end end end Runtime:addEventListener( "system", onSystemEvent )
build.settings look like this for the URL scheme parts.
android = { intentFilters = { { label = "Optional Title Goes Here", actions = { "android.intent.action.VIEW" }, categories = { "android.intent.category.DEFAULT", "android.intent.category.BROWSABLE", }, data = { scheme = "yourapp" }, }, -- You can add more intent filters here. }, },
Am I missing something?