File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Android and the fly likes how to get URL of a image in sd card Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "how to get URL of a image in sd card" Watch "how to get URL of a image in sd card" New topic
Author

how to get URL of a image in sd card

Ciaran Mooney
Ranch Hand

Joined: Jan 21, 2013
Posts: 72


I am trying to get the URL of a image I have saved to a SD card/ external storage of device. I need the string of URL to pass to setPicture(string url) of facebook share dialog SDK so I can upload this image to FB from device.

So far have tried getting the URL from URI of a file path to string:

File imagePathFile = new File(savedImagePath);
try{
userImageURL = imagePathFile.toURI().toURL();
Log.d(TAG, "File URL for saved image on FB: " + userImageURL);
}catch(MalformedURLException ex)
{ //ex.printStackTrace();
}
userImageURLString = userImageURL.toString(); setPicture(userImageURLString)

//userImageURLString = "file:/storage/emulated/0/dive_photos/image4373.png";

But keep getting error:

(#100) picture url not properly formed

any input much appreciated.
Ciaran


I love deadlines, I love the whooshing sound they make as they fly by...
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

You share pictures that are already on the internet, you upload pictures that aren't. So you need to upload the picture from the phone to Facebook (via a Request call: https://developers.facebook.com/docs/reference/android/current/class/Request/). I am not sure you will need to share the image after that or not, but if you do need a separate share action then you could get the ID for the image you upload (provided in a callback) and then do the share dialog with the URL of the image (which will be "https://www.facebook.com/photo.php?fbid=" + photoID).


Steve
Ciaran Mooney
Ranch Hand

Joined: Jan 21, 2013
Posts: 72

@Steve thanks allot, I've been at this for a couple weeks and was barking up the wrong tree till now.

So I have an idea how to post the image to the users photo album (I've read the method does this by default).
So I have two questions:
1. How do I pass a File to a Bundle which then needs to be passed to a Request object?
2. How do I get the URL of a image posted on the callback?

I have this code to date:

Request request = new Request();


And the call-back method:

Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Ciaran Mooney wrote:So I have two questions:
1. How do I pass a File to a Bundle which then needs to be passed to a Request object?

You already have filled out the Request.newUploadPhotoRequest() parameters with the imagePathFile. That method fills in the parameters bundle for you, no need to add it yourself, just execute it.
Ciaran Mooney wrote:2. How do I get the URL of a image posted on the callback?

The callback gets a Response, the Response lets you get a GraphObject, and the GraphObject lets you get properties for the object just uploaded. The important property is "id" and you would add the result to the end of the URL I posted in the previous post. Something like this:
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

p.s. The SDK for Facebook's Android API is here: https://developers.facebook.com/docs/reference/android/current. In my experience it is poorly formatted and not well documented, but it is, at least, a place to look for what objects and methods are available.
Ciaran Mooney
Ranch Hand

Joined: Jan 21, 2013
Posts: 72

Hey thanks again.

I am almost there, the photo will upload into a album specified in the file path, in the users profile BUT I cannot use the URL until the user manually accepts the photo in the photo album which kinda makes the exercise pointless...

Instead FB uses a really odd default blank to upload until the photo is accepted.



Looked around SDK (which i fns v awkward) and can't find anything.



Code to date is:

//open a session accord to FB share dialog instructions

//start a session
Session.openActiveSession(this, true, new Session.StatusCallback() {



@Override
public void call(final Session session, SessionState state, Exception exception) {
//callback when session changes state


Ciaran Mooney
Ranch Hand

Joined: Jan 21, 2013
Posts: 72

Message i get on Facebook:
Would you like to add these photos to your album?
The photos below were uploaded from another application, you'll need to approve them.

Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Not sure the answer to this one, I only played with it a tiny bit a while ago (before deciding I didn't want to contribute to the Facebook Spam). But this could be because you need to request more permissions to for your application (so the user gives permission on the phone rather than the site). Look here: https://developers.facebook.com/docs/android/login-with-facebook. The publish permissions are at the bottom.
Ciaran Mooney
Ranch Hand

Joined: Jan 21, 2013
Posts: 72

Thanks I finally got form the link you sent.




FB developers site is awful, I found it very hard to find info I was looking for.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Awesome, glad you got it working! I agree, their site is not well organized and the documentation is not much more than re-starting the method name and parameter names. They could use a significant amount of re-work to explain what happens, required permissions, what the expected input is, what likely use-cases are, etc... The fact that references to other classes in their API are not hyperlinked is also a poor decision. We should take this into consideration when we write our documentation: do it better than FB!
Ciaran Mooney
Ranch Hand

Joined: Jan 21, 2013
Posts: 72

Couldn't be too hard! I have a headache thinking about it........again thanks for your help couldn't of done it otherwise.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to get URL of a image in sd card