Android > Launch App from share with dialog > How to get shared image

Hi,

I want my app do be launched from the android image gallery or whereever a user selects an image and opens the share with dialog.

I already managed that my app will show up in the share with dialog and my app will also launch on that request but how will I get the image that the user wants to share with my app ??

i tried to read the launchArgs but without any success.

Some ideas on that?

thx

here is a code snippet of my main.lua

local function handleLaunch(event)
  if (event and event.url) then
    local url = event.url

    if (string.sub(url, 1, 7) == “file://”) then – handle file
      local alert = native.showAlert( “Got file url”, url, { “OK” })
    else
      local alert = native.showAlert( “Got url”, url, { “OK” })
    end

  end
end

handleLaunch(launchArgs)

launchArgs isn’t an event, it’s just data passed to the app.

Add this to your main.lua:

local json = require("json")local launchArgs = ... print("### --- Launch Arguments ---") print( json.prettify( launchArgs ) )

And see what data is there you can use.

Rob

Hi Rob,

this is what I get:

{

 “androidIntent”:{

   “url”:"",

   “categories”:[],

   “action”:“android.intent.action.SEND”,
   “extras”:"{

    “android.intent.extra.STREAM”:“content://media/external/images/media/48670”,

    “food”:"false,

    “makeup”:"false,

     }

   },

  “url”:""

}

already looks good, but how do I open the image??
I tried photo lib plus to get the image with this photo id (48670) but without success…seems to be a different id.
(btw…photo lib plus is working fine with id’s coming from photoLibPlus.listImages())

thx

Andreas

I assume  you want to display the image using display.newImage() or display.newImageRect()?

If so, you have to use the file IO functions to open the path to the file: /media/external/images/media/48670 in binary mode, read the data in, write it out to system.TemporaryDirectory (or other appropriate sandbox folder) and then you can use display.newImage() to read the file and make a display object out of it.

Rob

hi rob,

yes…you are right, I want to open the image, but the path seems not to be a path to a file or image. As you can see there is no file extension, also this directory structure does not exist on the device. ???

Andreas

After doing a search on the content URL provided, it seems that it’s a stream of data, not a file. Corona SDK isn’t going to have a way to process this data. 

http://stackoverflow.com/questions/20028319/how-to-convert-content-media-external-images-media-y-to-file-storage-sdc

Looking at that post, it’s possible to use Enterprise to convert the URL provided and convert it to a filename. Since you’re an Enterprise customer, I’d consider going this route.

Rob

Dear all, any chance about this ?

I’m developing an app that only need to share a file for BackUp (I can use the social plugging https://coronalabs.com/blog/2015/04/21/tutorial-social-sharing-on-android/

This allow me to send a file to for example Google Drive, or Dropbox,

But, to get external files, I need to read the stream of data.

Any way to do it? Any chance?

Why is so difficult to get content: stream of data?

Any plugging?

Thanks so much all for your excellent job,

launchArgs isn’t an event, it’s just data passed to the app.

Add this to your main.lua:

local json = require("json")local launchArgs = ... print("### --- Launch Arguments ---") print( json.prettify( launchArgs ) )

And see what data is there you can use.

Rob

Hi Rob,

this is what I get:

{

 “androidIntent”:{

   “url”:"",

   “categories”:[],

   “action”:“android.intent.action.SEND”,
   “extras”:"{

    “android.intent.extra.STREAM”:“content://media/external/images/media/48670”,

    “food”:"false,

    “makeup”:"false,

     }

   },

  “url”:""

}

already looks good, but how do I open the image??
I tried photo lib plus to get the image with this photo id (48670) but without success…seems to be a different id.
(btw…photo lib plus is working fine with id’s coming from photoLibPlus.listImages())

thx

Andreas

I assume  you want to display the image using display.newImage() or display.newImageRect()?

If so, you have to use the file IO functions to open the path to the file: /media/external/images/media/48670 in binary mode, read the data in, write it out to system.TemporaryDirectory (or other appropriate sandbox folder) and then you can use display.newImage() to read the file and make a display object out of it.

Rob

hi rob,

yes…you are right, I want to open the image, but the path seems not to be a path to a file or image. As you can see there is no file extension, also this directory structure does not exist on the device. ???

Andreas

After doing a search on the content URL provided, it seems that it’s a stream of data, not a file. Corona SDK isn’t going to have a way to process this data. 

http://stackoverflow.com/questions/20028319/how-to-convert-content-media-external-images-media-y-to-file-storage-sdc

Looking at that post, it’s possible to use Enterprise to convert the URL provided and convert it to a filename. Since you’re an Enterprise customer, I’d consider going this route.

Rob

I’m so glad to introduce you all my new plugin that can manage Uri in Android.

The plugin (actual version) allow to pick a file using the android dialog.

Also allow to get an external file knowing it’s uri.

And can share a file in a simple way.

It is here:

https://marketplace.coronalabs.com/plugin/android-file-and-uri-manager

I’m preparing some samples to show its functionality. For example, with this plugin it is so easy to get a file (custom extension) that it is open with our app.

Hope it can be useful for the community!

Best regards, and thanks for allow me to be here.

Dear all, any chance about this ?

I’m developing an app that only need to share a file for BackUp (I can use the social plugging https://coronalabs.com/blog/2015/04/21/tutorial-social-sharing-on-android/

This allow me to send a file to for example Google Drive, or Dropbox,

But, to get external files, I need to read the stream of data.

Any way to do it? Any chance?

Why is so difficult to get content: stream of data?

Any plugging?

Thanks so much all for your excellent job,

I’m so glad to introduce you all my new plugin that can manage Uri in Android.

The plugin (actual version) allow to pick a file using the android dialog.

Also allow to get an external file knowing it’s uri.

And can share a file in a simple way.

It is here:

https://marketplace.coronalabs.com/plugin/android-file-and-uri-manager

I’m preparing some samples to show its functionality. For example, with this plugin it is so easy to get a file (custom extension) that it is open with our app.

Hope it can be useful for the community!

Best regards, and thanks for allow me to be here.