Languages

Menu
Sites
Language
How to launch gallery app and retrieve which file is selected?

Hello, Everybody.

 

I have a soild experience in Android field but I'm pretty new to Tizen platform and I think I need your professional help.

I'm going to launch the Tizen standard Gallery app and get which file is selected by user.

 

I read how to launch the Tizen Gallery app:

You can launch the (native) gallery application for example using the following code:
tizen.application.launch("org.tizen.gallery", onLaunchSuccess, onError);

But how to get the path of selected file?

 

Thanks.

Christian.

Edited by: Brock Boland on 17 Mar, 2014 Reason: Paragraph tags added automatically from tizen_format_fix module.

Responses

18 Replies
Raghavendra Reddy Shiva
Hi, Application manager interface "launchAppControl" can be used to launch and perform particular action on a newly launched application. The application control request is passed to the newly launched application and it can be accessed by "getRequestedAppControl()" method. The launched application sends the result to the caller application with the replyResult() method of RequestedApplicationControl interface. Please refer to the below links for more details. https://developer.tizen.org/help/topic/org.tizen.web.appprogramming/html/guide/app_guide/application.htm https://developer.tizen.org/help/topic/org.tizen.web.device.apireference/index.html#Application Thanks,
Christian Soe
Hi, Thank you very much for your reply. I checked the URLs but I can't do what I wanted to do. I think I need to know what parameters the callee app accepts. Can we please just get into more detail? I want to have a feature in my app let users choose a file in file system. In order to implement it, can I use the system standard file manager app "My Files"? And what if I limit users to choose image files? In android, we just send an Intent to launch the gallery app and receive result from the gallery app. Is there any way to do so? I saw there is "File Manager" sample app, should I include this app into my app? Thanks again. Christian.
Michelle Somerville
Hi Christian, The scenario you have described is partially demonstrated in a tutorial available at: https://developer.tizen.org/help/topic/org.tizen.web.appprogramming/html/tutorials/app_tutorial/application_tutorial.htm You need to create an ApplicationControl object with the pick operation and specify image in the MIME type. e.g. var appControl = new tizen.ApplicationControl("http://tizen.org/appcontrol/operation/pick", null, "image/*"); You can also specify a specific image type by replacing “image/*” with “image/jpg” etc. You can launch the gallery application using the launchAppControl() method – but before you do this you need to define and implement the two ApplicationControlDataArrayReplyCallback methods: onsuccess() to get the location of the selected image and onfailure() to handle the fail case. In the onsuccess() method, an array of ApplicationControlData objects is returned, which contain key value pairs with your data. The key for a successful pick operation is “http://tizen.org/appcontrol/data/selected” - so if the key parameter contains this string the corresponding value parameter will contain the path to the selected image. e.g. var appControlReplyCB = { onsuccess: function(data) { for (var i=0; i
Michelle Somerville
var appControlReplyCB = { onsuccess: function(data) { for (var i=0; i < data.length; i++) { if(data[i].key == "http://tizen.org/appcontrol/data/selected") { console.log("Stored at: " + data[i].value[0]); } } }, onfailure: function() { console.log('Service returned with failure'); } }; So to launch the gallery you use: tizen.application.launchAppControl(appControl, null, function(){console.log("launch appControl succeeded");}, function(e){console.log("launch appControl failed. Reason: " + e.name);}, appControlReplyCB); It will launch the gallery application, and when the user selects an image the gallery application will return the path to the selected image in the ApplicationControlDataArrayReplyCallback onsuccess() method. Currently, the gallery application only allows the user to select one image. Regards, Michelle
Christian Soe
Hello, Michelle. I've an issue following your tutorial..... When I launch the Gallery app using the code var appControl = new tizen.ApplicationControl("http://tizen.org/appcontrol/operation/pick", null, "image/*"); ... tizen.application.launchAppControl(appControl, null, function(){console.log("launch appControl succeeded");}, function(e){console.log("launch appControl failed. Reason: " + e.name);}, appControlReplyCB); The Gallery app shows but it constantly shows "No Images" text. When I launch the gallery app in the home screen in the Tizen Emulator, I can see dozens of images and also can browse them.. Can you please tell me what went wrong? with my code or there is some other configuration? I added "http://tizen.org/privilege/application.launch permission" in config.xml Thanks. Christian.
Michelle Somerville
Hi Christian, I'm sorry this looks like it's a bug in the emulator implementation. I was testing on a device and that works fine. When I tried on the emulator I had a similar issue. I'll raise a bug report. Do you have access to a device? Regards, Michelle
Christian Soe
Hello, Michelle. Thanks for your reply. Unfortunately, I don't have any device. Can you please tell me how to purchase or get one? I really want to have one as the Tizen Emulater is very slow in my MAC. Thanks. Christian.
Michelle Somerville
Hi Christian, Sorry, reference devices are not available to buy. There was a developer program at https://developer.tizen.org/support/development-unit-program, but I don't think there are any devices available at the moment. Regards, Michelle
Christian Soe
Thank you very much! I should have look at the dev guideline more carefully before. Those stuff like "http://tizen.org/appcontrol/operation/pick", “image/*”, “http://tizen.org/appcontrol/data/selected” were the keys! Thanks again. Christian.
dhirku
I am trying to view a video in using appcontrol ...... here is my testing code function myFunction() { var documentsDir; var appControlReplyCallback = { onsuccess: function(data) { console.log('launch application control is success'); }, onfailure: function() { console.log('The launch application control failed'); } } function onsuccess(files){ for(var i = 0; i < files.length; i++){ alert("File Name is " + files[i].name); // displays file name } var filepath = documentsDir + "/sampleMP4.mp4"; alert(filepath); var appControl = new tizen.ApplicationControl( "http://tizen.org/appcontrol/operation/view", filepath, "video/mp4", null); tizen.application.launchAppControl(appControl, null, function() {console.log("launch application control succeed"); }, function(e) {console.log("launch application control failed. reason: " + e.message); }, appControlReplyCallback); } function onerror(error) { console.log("The error " + error.message + " occurred when listing the files in the selected folder"); } tizen.filesystem.resolve( 'videos', function(dir){ documentsDir = dir.path; dir.listFiles(onsuccess,onerror); }, function(e){ console.log("Error" + e.message); }, "r" ); } After running this I get error in the console saying "launch application control failed. reason: given package is not found" ..... any clue I am not sure what is going wrong ...... The video file sampleMP4.mp4 exists in the Videos folder of emulator
Michelle Somerville
Hi dhirku, You code is correct - although you don't need an appControlReplyCallback() for this case as the video player does not return any data to the calling app. You get the "launch application control failed. reason: given package is not found" error when it can't find the media - so your filepath variable must be wrong. Try hard-coding the path and test that to make sure the appControl code works e.g. var filepath = "/opt/media/Videos/sampleMP4.mp4"; Regards, Michelle
dhirku
Thanks Michelle It works after hard coding the path .... good for demo ..... but in release version it may cause problem. Also tried with documentsDir = dir.fullPath ; but did not get proper path .... it gives "undefined" and documentsDir = dir.toURI(); returns file path starting with "file://" Which again is not good as this is Video directory.
Michelle Somerville
Of course don't hard-code in your release version - just try it to test the code works. Why can't you use the documentsDir = dir.toURI(); method? This gives you the full directory path to your file and you can use a URI starting with "file://" in your appControl.
Gopi Krishna V
Hi Michelle, I am also trying to the same.... but after launching the video player... the video playback is not happening... Either the program stalls or closes given out error message....
Michelle Somerville
Hi Gopi, What's the error message? Are you testing on the device or the emulator? Are you sure the filesystem path to the content is correct?
Gopi Krishna V
on RD-210 Path is correct... but the video playback is not happening... it plays only the frame of the video and the programs get stalled or closes with an error msg...
Michelle Somerville
Video playback works fine for me on RD-210 device - what is the error message?
Gopi Krishna V
It says videoplayer has closed unexpectedly... or its just plays the first frame and the program gets stalled.... i am having 19.04 image on device....