Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Handling URL scheme on Android?
Started by marcar Jul 11 2013 04:39 AM

47 replies to this topic
[TOPIC CONTROLS]
Page 2 of 2 1 2
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#26

ojnab

[GLOBAL: userInfoPane.html]
ojnab
  • Contributor

  • 614 posts
  • Corona SDK

Thanks Joshua. That makes sense.

 

But the strange thing is that I tested it with the default browser and as a link in the default email app and none of these seems to work. I would think that when calling system.openURL(“myapp://“) it also calls the default browser to launch the app right?



[TOPIC: post.html]
#27

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

When you call system.openURL("myapp://"), then what we do is turn that URL into an Android intent and then have the Android OS launch the default activity for that URL by calling the Java Activity.startActivity() method...

   http://developer.android.com/reference/android/content/Context.html#startActivity(android.content.Intent)

 

The above is how you can get your app to launch another app via it's intent-filter.  If no app on the device has a matching intent-filter for that URL, then the OS defaults to the Browser app.

 

Now, if the app blindly passes your URL to the Java WebView.loadUrl() method on Android, then it will ignore all app intent-filters on the device and attempt to do an HTTP request to a server that doesn't exist.  In your case, you'll get a 404 error.

   http://developer.android.com/reference/android/webkit/WebView.html#loadUrl(java.lang.String)



[TOPIC: post.html]
#28

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Regarding the Browser not launching your app, it works for me if I use an HTML <a/> tag on my webpage.

Are you invoking your URL via JavaScript instead?

 

I ask because I know there is this "quirk" with Android's WebView Java class where it's WebViewClient.shouldOverrideUrlLoading() does not get called for URLs invoked via JavaScript... and that's the method that most native Android developers use to override URL handling.



[TOPIC: post.html]
#29

ojnab

[GLOBAL: userInfoPane.html]
ojnab
  • Contributor

  • 614 posts
  • Corona SDK

That did the trick.

 

I was just trying to launch the app directly from the browser or email app, but putting the scheme on a html web page worked.

 

We have an app where users can share content by emailing a url scheme with a download code in the launchargs, 

so the app will launch and start downloading the content when tapping the url scheme link.

 

On iOS it is possible to launch the app directly from the mail program, but apparently on android you need to bridge it

using a webpage… but thats not really a problem. 

 

Thank you Joshua. This was very helpful.



[TOPIC: post.html]
#30

ojnab

[GLOBAL: userInfoPane.html]
ojnab
  • Contributor

  • 614 posts
  • Corona SDK

By the way if anyone else is trying to do this kind of thing.

Here is a nice tutorial explaining everything: http://fokkezb.nl/2013/09/20/url-schemes-for-ios-and-android-2/



[TOPIC: post.html]
#31

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Thanks for sharing!

 

Out of interest, what issues were you having with a "singleTask" activity?

 

The only odd quirk that I'm aware of is if you display an activity from a singleTask activity, home out, and then go back to your app... then Android automatically destroys all of the activities displayed by that task and goes back to the singleTask activity.



[TOPIC: post.html]
#32

claes.lindblom

[GLOBAL: userInfoPane.html]
claes.lindblom
  • Observer

  • 27 posts
  • Corona SDK

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 © 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?



[TOPIC: post.html]
#33

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

The data would be passed to your app via an Android intent.  Corona provides *all* of this intent information via launch arguments on startup or the "applicationOpen" event upon resume.  The print functions in your code should print all of the information in the Android intent that launched your app to the Android log, which you can view via the Android SDK's "adb logcat".  If the QR scanner is providing a file, then odds are it is passing it as a file path or URL via this Android intent.  Unfortunately, there is no standard, so you'll have to view this information via the log to see how it is delivered.  If it's not a file path and it is a URL delivered via an Android ContentProvider (with a URL scheme of "content://"), then you can only access that file via native code.



[TOPIC: post.html]
#34

claes.lindblom

[GLOBAL: userInfoPane.html]
claes.lindblom
  • Observer

  • 27 posts
  • Corona SDK

When doing cold start of application logcat gives me this

03-19 22:33:51.005: I/Corona(19993): yourapp: ### --- Launch Arguments ---
03-19 22:33:51.005: I/Corona(19993): ### androidIntent
03-19 22:33:51.005: I/Corona(19993): ### {
03-19 22:33:51.005: I/Corona(19993): ###    categories
03-19 22:33:51.005: I/Corona(19993): ###    {
03-19 22:33:51.005: I/Corona(19993): ###       1: android.intent.category.LAUNCHER
03-19 22:33:51.005: I/Corona(19993): ###    }
03-19 22:33:51.005: I/Corona(19993): ###    url:
03-19 22:33:51.005: I/Corona(19993): ###    action: android.intent.action.MAIN
03-19 22:33:51.005: I/Corona(19993): ###    extras
03-19 22:33:51.005: I/Corona(19993): ###    {
03-19 22:33:51.005: I/Corona(19993): ###    }
03-19 22:33:51.005: I/Corona(19993): ### }
03-19 22:33:51.005: I/Corona(19993): ### url:
03-19 22:33:51.005: I/Corona(19993): yourapp: onSystemEvent [applicationStart] URL: nil
03-19 22:33:52.910: I/Corona(19993): yourapp: onSystemEvent [applicationSuspend] URL: nil
03-19 22:33:53.025: I/Corona(19993): yourapp: onSystemEvent [applicationResume] URL: nil

 

After pic2shop scanner

03-19 22:36:02.395: I/Corona(19993): yourapp: onSystemEvent [applicationSuspend] URL: nil
03-19 22:36:05.440: I/Corona(19993): yourapp: onSystemEvent [applicationResume] URL: nil
03-19 22:36:05.440: I/Corona(19993): yourapp: onSystemEvent [applicationOpen] URL: nil
03-19 22:36:05.440: I/Corona(19993): nil

 

when I add native.requestExit() when app is suspended I get this from pic2shop

03-19 22:39:11.285: I/Corona(23208): yourapp: onSystemEvent [applicationSuspend] URL: nil
03-19 22:39:12.355: I/Corona(23208): yourapp: onSystemEvent [applicationExit] URL: nil
03-19 22:39:16.830: V/Corona(23695): > Class.forName: network.LuaLoader
03-19 22:39:16.830: V/Corona(23695): < Class.forName: network.LuaLoader
03-19 22:39:16.830: V/Corona(23695): Loading via reflection: network.LuaLoader
03-19 22:39:16.835: I/Corona(23695): Platform: GT-I9300 / ARM Neon / 4.3 / Mali-400 MP / OpenGL ES 2.0
03-19 22:39:16.870: V/Corona(23695): > Class.forName: CoronaProvider.licensing.google.LuaLoader
03-19 22:39:16.875: V/Corona(23695): < Class.forName: CoronaProvider.licensing.google.LuaLoader
03-19 22:39:16.880: V/Corona(23695): Loading via reflection: CoronaProvider.licensing.google.LuaLoader
03-19 22:39:16.905: I/Corona(23695): yourapp: ### --- Launch Arguments ---
03-19 22:39:16.905: I/Corona(23695): ### androidIntent
03-19 22:39:16.905: I/Corona(23695): ### {
03-19 22:39:16.905: I/Corona(23695): ###    categories
03-19 22:39:16.905: I/Corona(23695): ###    {
03-19 22:39:16.905: I/Corona(23695): ###    }
03-19 22:39:16.905: I/Corona(23695): ###    url: yourapp:?ean=8806085215733
03-19 22:39:16.905: I/Corona(23695): ###    action: android.intent.action.VIEW
03-19 22:39:16.905: I/Corona(23695): ###    extras
03-19 22:39:16.905: I/Corona(23695): ###    {
03-19 22:39:16.905: I/Corona(23695): ###       com.android.browser.application_id: com.visionsmarts.pic2shop
03-19 22:39:16.905: I/Corona(23695): ###    }
03-19 22:39:16.905: I/Corona(23695): ### }
03-19 22:39:16.905: I/Corona(23695): ### url: yourapp:?ean=8806085215733
03-19 22:39:16.905: I/Corona(23695): yourapp: onSystemEvent [applicationStart] URL: nil
03-19 22:39:25.780: I/Corona(23695): yourapp: onSystemEvent [applicationSuspend] URL: nil
03-19 22:39:26.595: I/Corona(23695): yourapp: onSystemEvent [applicationExit] URL: nil

 

as you can see only launch args contains information about intent. Never in the event applicationOpen.



[TOPIC: post.html]
#35

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

The "applicationOpen" event will only provide pic2shop's intent information if it is "resuming" your app.  That is, it must have been previously suspended such as via the Home button.  If you "back" out of your app, then that exits and the intent information will be provided via the launch arguments again.

 

So, do this.  Launch your app, then suspend it via the Home button, go to the pic2shop app, and then in then trigger your app's intent-filter to resume it.  You'll see the pic2shop intent information in your "applicationOpen" event.  If you're seeing launch arguments instead, then that means that the operating system killed your app after you suspended it (or you unknowingly killed it in your suspend code).



[TOPIC: post.html]
#36

michiel1

[GLOBAL: userInfoPane.html]
michiel1
  • Observer

  • 1 posts
  • Corona SDK

I'm experiencing the exact same thing.   If I kill the app by hand first, I get the proper data from the launchArguments, but if I then go back to the gallery (via Home), the applicationOpen event is triggered without it showing any intent data.     So the second time I'm not seeing the launch arguments nor the data on the applicationOpen event.



[TOPIC: post.html]
#37

anshuman

[GLOBAL: userInfoPane.html]
anshuman
  • Enthusiast

  • 79 posts
  • Corona SDK

I can confirm what Claes has mentioned: the launchArguments url is always empty except when we explicitly do native.requestExit() on suspend. 

 

Setup:

 

Test App calls "pic2shop://scan?callback=test://ag123/EAN". 

Test app is suspended. 

pic2shop gets triggered (opens), the barcode is scanned. The barcode decoded value should ideally be passed in the EAN section. 

Test app resumes, but no url value. 

 

 

 

During normal operations (without explicit exit):

V/Corona  (  303): > Class.forName: network.LuaLoader
V/Corona  (  303): < Class.forName: network.LuaLoader
V/Corona  (  303): Loading via reflection: network.LuaLoader
I/Corona  (  303): Platform: Nexus 4 / ARM Neon / 4.4.2 / Adreno ™ 320 / OpenGL ES 3.0 V@53.0 AU@  (CL@)
V/Corona  (  303): > Class.forName: CoronaProvider.licensing.google.LuaLoader
V/Corona  (  303): < Class.forName: CoronaProvider.licensing.google.LuaLoader
V/Corona  (  303): Loading via reflection: CoronaProvider.licensing.google.LuaLoader
I/Corona  (  303): yourapp: ### --- Launch Arguments ---
I/Corona  (  303): ### androidIntent
I/Corona  (  303): ### {
I/Corona  (  303): ###    categories
I/Corona  (  303): ###    {
I/Corona  (  303): ###       1: android.intent.category.LAUNCHER
I/Corona  (  303): ###    }
I/Corona  (  303): ###    url: 
I/Corona  (  303): ###    action: android.intent.action.MAIN
I/Corona  (  303): ###    extras
I/Corona  (  303): ###    {
I/Corona  (  303): ###    }
I/Corona  (  303): ### }
I/Corona  (  303): ### url: 
I/Corona  (  303): App State:
I/Corona  (  303): ### name: system
I/Corona  (  303): ### type: applicationStart
I/Corona  (  303): yourapp: ### --- Launch Arguments ---
I/Corona  (  303): ### androidIntent
I/Corona  (  303): ### {
I/Corona  (  303): ###    categories
I/Corona  (  303): ###    {
I/Corona  (  303): ###       1: android.intent.category.LAUNCHER
I/Corona  (  303): ###    }
I/Corona  (  303): ###    url: 
I/Corona  (  303): ###    action: android.intent.action.MAIN
I/Corona  (  303): ###    extras
I/Corona  (  303): ###    {
I/Corona  (  303): ###    }
I/Corona  (  303): ### }
I/Corona  (  303): ### url: 
I/Corona  (  303): App State:
I/Corona  (  303): ### name: system
I/Corona  (  303): ### type: applicationSuspend
I/Corona  (  303): yourapp: ### --- Launch Arguments ---
I/Corona  (  303): ### androidIntent
I/Corona  (  303): ### {
I/Corona  (  303): ###    categories
I/Corona  (  303): ###    {
I/Corona  (  303): ###       1: android.intent.category.LAUNCHER
I/Corona  (  303): ###    }
I/Corona  (  303): ###    url: 
I/Corona  (  303): ###    action: android.intent.action.MAIN
I/Corona  (  303): ###    extras
I/Corona  (  303): ###    {
I/Corona  (  303): ###    }
I/Corona  (  303): ### }
I/Corona  (  303): ### url: 
I/Corona  (  303): App State:
I/Corona  (  303): ### name: system
I/Corona  (  303): ### type: applicationResume
I/Corona  (  303): yourapp: ### --- Launch Arguments ---
I/Corona  (  303): ### androidIntent
I/Corona  (  303): ### {
I/Corona  (  303): ###    categories
I/Corona  (  303): ###    {
I/Corona  (  303): ###       1: android.intent.category.LAUNCHER
I/Corona  (  303): ###    }
I/Corona  (  303): ###    url: 
I/Corona  (  303): ###    action: android.intent.action.MAIN
I/Corona  (  303): ###    extras
I/Corona  (  303): ###    {
I/Corona  (  303): ###    }
I/Corona  (  303): ### }
I/Corona  (  303): ### url: 
I/Corona  (  303): App State:
I/Corona  (  303): ### name: system
I/Corona  (  303): ### type: applicationOpen
I/Corona  (  303): yourapp: ### --- Launch Arguments ---
I/Corona  (  303): ### androidIntent
I/Corona  (  303): ### {
I/Corona  (  303): ###    categories
I/Corona  (  303): ###    {
I/Corona  (  303): ###       1: android.intent.category.LAUNCHER
I/Corona  (  303): ###    }
I/Corona  (  303): ###    url: 
I/Corona  (  303): ###    action: android.intent.action.MAIN
I/Corona  (  303): ###    extras
I/Corona  (  303): ###    {
I/Corona  (  303): ###    }
I/Corona  (  303): ### }
I/Corona  (  303): ### url: 

(no URL passed in above case)

 

 

But when using explicit exit on suspend, we do get the URL:

V/Corona  (29644): > Class.forName: network.LuaLoader
V/Corona  (29644): < Class.forName: network.LuaLoader
V/Corona  (29644): Loading via reflection: network.LuaLoader
I/Corona  (29644): Platform: Nexus 4 / ARM Neon / 4.4.2 / Adreno ™ 320 / OpenGL ES 3.0 V@53.0 AU@  (CL@)
V/Corona  (29644): > Class.forName: CoronaProvider.licensing.google.LuaLoader
V/Corona  (29644): < Class.forName: CoronaProvider.licensing.google.LuaLoader
V/Corona  (29644): Loading via reflection: CoronaProvider.licensing.google.LuaLoader
I/Corona  (29644): yourapp: ### --- Launch Arguments ---
I/Corona  (29644): ### androidIntent
I/Corona  (29644): ### {
I/Corona  (29644): ###    categories
I/Corona  (29644): ###    {
I/Corona  (29644): ###       1: android.intent.category.LAUNCHER
I/Corona  (29644): ###    }
I/Corona  (29644): ###    url: 
I/Corona  (29644): ###    action: android.intent.action.MAIN
I/Corona  (29644): ###    extras
I/Corona  (29644): ###    {
I/Corona  (29644): ###    }
I/Corona  (29644): ### }
I/Corona  (29644): ### url: 
I/Corona  (29644): App State:
I/Corona  (29644): ### name: system
I/Corona  (29644): ### type: applicationStart
I/Corona  (29644): yourapp: ### --- Launch Arguments ---
I/Corona  (29644): ### androidIntent
I/Corona  (29644): ### {
I/Corona  (29644): ###    categories
I/Corona  (29644): ###    {
I/Corona  (29644): ###       1: android.intent.category.LAUNCHER
I/Corona  (29644): ###    }
I/Corona  (29644): ###    url: 
I/Corona  (29644): ###    action: android.intent.action.MAIN
I/Corona  (29644): ###    extras
I/Corona  (29644): ###    {
I/Corona  (29644): ###    }
I/Corona  (29644): ### }
I/Corona  (29644): ### url: 
I/Corona  (29644): App State:
I/Corona  (29644): ### name: system
I/Corona  (29644): ### type: applicationSuspend
I/Corona  (29644): yourapp: ### --- Launch Arguments ---
I/Corona  (29644): ### androidIntent
I/Corona  (29644): ### {
I/Corona  (29644): ###    categories
I/Corona  (29644): ###    {
I/Corona  (29644): ###       1: android.intent.category.LAUNCHER
I/Corona  (29644): ###    }
I/Corona  (29644): ###    url: 
I/Corona  (29644): ###    action: android.intent.action.MAIN
I/Corona  (29644): ###    extras
I/Corona  (29644): ###    {
I/Corona  (29644): ###    }
I/Corona  (29644): ### }
I/Corona  (29644): ### url: 
I/Corona  (29644): App State:
I/Corona  (29644): ### name: system
I/Corona  (29644): ### type: applicationExit  ------- this is the explicit exit
V/Corona  (29644): > Class.forName: network.LuaLoader
V/Corona  (29644): < Class.forName: network.LuaLoader
V/Corona  (29644): Loading via reflection: network.LuaLoader
I/Corona  (29644): Platform: Nexus 4 / ARM Neon / 4.4.2 / Adreno ™ 320 / OpenGL ES 3.0 V@53.0 AU@  (CL@)
V/Corona  (29644): > Class.forName: CoronaProvider.licensing.google.LuaLoader
V/Corona  (29644): < Class.forName: CoronaProvider.licensing.google.LuaLoader
V/Corona  (29644): Loading via reflection: CoronaProvider.licensing.google.LuaLoader
I/Corona  (29644): yourapp: ### --- Launch Arguments ---
I/Corona  (29644): ### androidIntent
I/Corona  (29644): ### {
I/Corona  (29644): ###    categories
I/Corona  (29644): ###    {
I/Corona  (29644): ###    }
I/Corona  (29644): ###    url: test://ag123/8809376760059
I/Corona  (29644): ###    action: android.intent.action.VIEW
I/Corona  (29644): ###    extras
I/Corona  (29644): ###    {
I/Corona  (29644): ###       com.android.browser.application_id: com.visionsmarts.pic2shop
I/Corona  (29644): ###    }
I/Corona  (29644): ### }
I/Corona  (29644): ### url: test://ag123/8809376760059
I/Corona  (29644): App State:
I/Corona  (29644): ### name: system
I/Corona  (29644): ### type: applicationStart
I/Corona  (29644): yourapp: ### --- Launch Arguments ---
I/Corona  (29644): ### androidIntent
I/Corona  (29644): ### {
I/Corona  (29644): ###    categories
I/Corona  (29644): ###    {
I/Corona  (29644): ###    }
I/Corona  (29644): ###    url: test://ag123/8809376760059
I/Corona  (29644): ###    action: android.intent.action.VIEW
I/Corona  (29644): ###    extras
I/Corona  (29644): ###    {
I/Corona  (29644): ###       com.android.browser.application_id: com.visionsmarts.pic2shop
I/Corona  (29644): ###    }
I/Corona  (29644): ### }
I/Corona  (29644): ### url: test://ag123/8809376760059
I/Corona  (29644): App State:
I/Corona  (29644): ### name: system
I/Corona  (29644): ### type: applicationSuspend
I/Corona  (29644): yourapp: ### --- Launch Arguments ---
I/Corona  (29644): ### androidIntent
I/Corona  (29644): ### {
I/Corona  (29644): ###    categories
I/Corona  (29644): ###    {
I/Corona  (29644): ###    }
I/Corona  (29644): ###    url: test://ag123/8809376760059
I/Corona  (29644): ###    action: android.intent.action.VIEW
I/Corona  (29644): ###    extras
I/Corona  (29644): ###    {
I/Corona  (29644): ###       com.android.browser.application_id: com.visionsmarts.pic2shop
I/Corona  (29644): ###    }
I/Corona  (29644): ### }
I/Corona  (29644): ### url: test://ag123/8809376760059
I/Corona  (29644): App State:
I/Corona  (29644): ### name: system
I/Corona  (29644): ### type: applicationExit

As can be seen, url: test://ag123/8809376760059 has been populated this time. 

 

But this is not a very practical (or recommended?) approach to kill off the app everytime we suspend it? 

 

 

Please advise. 

 

Cheers,

Anshuman



[TOPIC: post.html]
#38

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Anshuman,

 

I tested this today and confirmed that the "applicationOpen" event is *not* providing the "androidIntent" information.  This is indeed a bug in the newest release, because this feature used to work.  I've written up a bug report for this issue and added it to our queue.  No ETA at the moment.



[TOPIC: post.html]
#39

anshuman

[GLOBAL: userInfoPane.html]
anshuman
  • Enthusiast

  • 79 posts
  • Corona SDK

Hi Joshua, Thanks for the investigation update. 

 

It would be good to have it sorted in the near future to avoid exiting apps instead of suspending them as a workaround. 

 

Many thanks for filing the bug.

 

Cheers,

Anshuman



[TOPIC: post.html]
#40

dchan

[GLOBAL: userInfoPane.html]
dchan
  • Contributor

  • 360 posts
  • Corona Staff

This has been fixed in build 2224.



[TOPIC: post.html]
#41

claes.lindblom

[GLOBAL: userInfoPane.html]
claes.lindblom
  • Observer

  • 27 posts
  • Corona SDK

Great news! :)

I have tested the latest version and verified that it is working as it should. Thanks!

 

-Claes



[TOPIC: post.html]
#42

Kevin H

[GLOBAL: userInfoPane.html]
Kevin H
  • Contributor

  • 132 posts
  • Corona SDK

I've successfully implemented these steps http://coronalabs.com/blog/2013/02/05/ios-tutorial-using-email-attachments/ for iOS to pass the directory path of a saved attachment back into my app. And now I'd LOVE to be able to do the same on the Android side. Any resources available for such a thing?



[TOPIC: post.html]
#43

derek14

[GLOBAL: userInfoPane.html]
derek14
  • Observer

  • 21 posts
  • Corona SDK

By the way if anyone else is trying to do this kind of thing.

Here is a nice tutorial explaining everything: http://fokkezb.nl/2013/09/20/url-schemes-for-ios-and-android-2/

interesting tutorial! 

 

I've got my app to launch via a custom url scheme eg myapp://,  but could not get it to launch using an intent anchor, eg:

 

intent://view#Intent;package=com.mypackageid;scheme=myapp;end;

 

from the launching app I get this generic error:

 

I/Corona  (29076): Warning: system.openURL() failed to open URL: intent://view#Intent;package=com.mypackageid;scheme=myapp;end;

 

 

Is there something wrong with the intent anchor syntax, or do I require something additional in build.settings?  Or does corona just not support intent anchors?

 

relevant section from build.settings:

   intentFilters =
      {
         {
            label = "launch from URL",
            actions = { "android.intent.action.VIEW" },
            categories =
            {
               "android.intent.category.DEFAULT",
               "android.intent.category.BROWSABLE",
            },
            data = { scheme = "myapp" },
         },
}


[TOPIC: post.html]
#44

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Corona will just pass your URL to the appropriate Android OS as-is.  So, perhaps the Android OS doesn't know what to do with it?

 

I've never tried an Android intent URL with an anchor tag before.  I don't think that's commonly used by Android developers.  I typically see URL arguments passed in Android intents instead.  For example:

   myapp://mypage?x=1&y=2

 

I know URL arguments are supported by Android intents.  Corona internally uses them to launch a Corona app when its local/push notification has been tapped on the top status bar.  This is how we identify which notification got tapped on.



[TOPIC: post.html]
#45

derek14

[GLOBAL: userInfoPane.html]
derek14
  • Observer

  • 21 posts
  • Corona SDK

I can use the myapp:// method, but given i'm going to implement this across 30+ android apps, it would be easier to document and manage if the scheme was identical and I could just say "insert package name here"

 

I have read some articles that suggest that while intent:// is not commonplace, it should work:

 

https://developer.chrome.com/multidevice/android/intents

http://stackoverflow.com/questions/23231589/intent-anchor-syntax-description

 

Examining the source of the toURI() method in the Intent class, my URI looks ok.  I just can't get it to work.

 

In any case this is by no means a showstopper, just a nice to have and I also hate to leave a problem unsolved!

 

thanks



[TOPIC: post.html]
#46

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

I'm not set up to test Android apps at the moment.  So, would you mind doing the following quick test?

 

Try changing the following intent-filter part in your app from this...

   data = { scheme = "myapp" },

 

...to this...

   data = { scheme = "myapp" android:host="com.mypackageid" android:path="/view/" },

 

The above should theoretically make the following URI work according to Google's example...

   intent://view/#Intent;scheme=myapp;package=com.mypackageid;end



[TOPIC: post.html]
#47

derek14

[GLOBAL: userInfoPane.html]
derek14
  • Observer

  • 21 posts
  • Corona SDK

this gave me a build error:  Syntax error: '}' expected near 'android'

 

data = { scheme = "myapp" android:host="com.mypackageid" android:path="/view/" }

 

 

adding commas gave me a different build error:  Syntax error: function arguments expected near '='

data = { scheme = "myapp" ,  android:host="com.mypackageid"  , android:path="/view/" }

 

They both ran OK in the simulator but a modal dialog appeared during the build:

There is an error in your build.settings.

Please correct the error and try building again. (Check the console for more information.)

 

 

this built ok, but i still could not launch the app with the intent anchor

data = { scheme = "myapp" ,  host="com.mypackageid"  , path="/view/" }

 

 

 



[TOPIC: post.html]
#48

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Sorry.  I copied and pasted that from XML and forgot to convert it to the appropriate Lua syntax.  What you scripted at the bottom of your post is what was needed.

 

If what I suggested doesn't work, then I don't know what else to recommend.  From what I gathered from Google's write-up that you linked to, this anchor intent syntax is an undocumented feature that is only supported by Google's Chrome browser app.  Meaning that it most likely won't work in an embedded native WebView or via native Android APIs used to launch Android intents (like the ones Corona uses to launch an app via system.openURL() function).  In which case, implementing your own URL scheme or, even better, using an http:// scheme where you set up an intent-filter to launch your app via the host/domain name would be better from a cross-platform and cross-browser standpoint.




[topic_controls]
Page 2 of 2 1 2
 
[/topic_controls]