Languages

Menu
Sites
Language
How to get image from mobile Galery on button click

Hi,

I am developing an application in which i want to get images from mobile galery.when user click on the button the he should get the galery image.

The selected image should be displayed on the page.

 

 

Please help me.

 

 

Thanks and regards

Mohit Kumar

 

Responses

4 Replies
Palitsyna

Hello,

you can use this code to open Gallery app and pick image from there to your application and display it. 

document.getElementById('button').addEventListener("click", function() {
	try {
		var appControl = new tizen.ApplicationControl(
			"http://tizen.org/appcontrol/operation/pick",
			null,
			"image/*",
			null,
			[new tizen.ApplicationControlData("http://tizen.org/appcontrol/data/selection_mode", ["single"])]);

		var appControlReplyCallback = {
			onsuccess: function(reply) {
				var path = reply[1].value[0];
				path = "file://" + path;	
			        document.getElementById('img').setAttribute("src", path);
			},
			onfailure: function() {
				console.log("The launch application control failed");
			}
		};

		tizen.application.launchAppControl(
			appControl,
			null,
			function() {console.log("launch application control succeed"); },
			function(e) {console.log("launch application control failed. reason: " + e.message); },
			appControlReplyCallback 
		);
    } catch (e) {
        alert("Error " + e.name + " : " + e.message);
    }
});

 

ashish kumar

hi Palitsyna,

 

Can you describe more. how can i use this code..

mohit kumar

Hi Palitsyna,

Here i am faceing one problem.Once image is selected it get rotated.How can i upload image without rotating it.Some time some images are rotated at 90 degree or 180 degree.

 

 

please help me

 

Thanks and regards

Mohit Kumar

Palitsyna

Hello,

this code works as described below:
when you press button, the gallery application is launched. As soon as you choose one image, you will return to your app and the path of this image will be returned to appControlReplyCallback. And then you set this path as your image "src" attribute, so the image will be displayed in your application.

 

You need to add http://tizen.org/privilege/application.launch privilege to your config.xml file.

Here you can reed more about Application Control:

Guide: https://developer.tizen.org/development/guides/web-application/tizen-features/application/application-0

API Reference: https://developer.tizen.org/development/api-references/web-application?langswitch=en

Tutorial: https://developer.tizen.org/development/tutorials/web-application/tizen-features/application/application-0