5

I am new to Android, and I'm struggling to figure out exactly what tools are available to me. I am developing for Android 2.0.1 for now, just because that is what my device runs.

Specifically, I am writing an app that I would like to upload images to a Picasa album. I am almost sure this is supported; for example, the built in (Google?) photo viewer has a 'share' button with a Picasa option, and even a small bit of sample code, including the snippet

[borrowed code! apologies if this is against the rules..]

temp.setComponent(new ComponentName 
("com.google.android.apps.uploader", 
"com.google.android.apps.uploader.picasa.PicasaUploadActivity")); 
startActivityForResult(temp, PICASA_INTENT) 

which looks like exactly what I want.

But I can't find any documentation anywhere. I am in fact quite unclear how to use this type of resource. From within Eclipse, do I need to include another project, com.google.android.apps.uploader? If so, how do I get it? How do I include it? Is there any working sample code provided for me to peek at?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131

2 Answers2

2

video Google I/O 2011 - Best practices for Accessing Google APIs on Android (40th min.)

public class PostPhotoActivity extends Activity
{

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    try
    {
        HttpRequestFactory requestFactory = new NetHttpTransport().createRequestFactory();
        Intent intent = getIntent();
        Bundle extras = intent.getExtras();
        InputStreamContent content = new InputStreamContent();
        ContentResolver contentResolver = getContentResolver();
        Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
        content.inputStream = contentResolver.openInputStream(uri);
        Cursor cursor = contentResolver.query(uri, null, null, null, null);
        cursor.moveToFirst();
        content.type = intent.getType();
        content.length = cursor.getLong(cursor.getColumnIndexOrThrow(Images.Media.SIZE));
        HttpRequest request = requestFactory.buildPostRequest(new GenericUrl(
            "https://picasaweb.google.com/data/feed/api/user/default/albumid/default"), content);
        GoogleHeaders headers = new GoogleHeaders();
        request.headers = headers;
        String fileName = cursor.getString(cursor.getColumnIndexOrThrow(Images.Media.DISPLAY_NAME));
        headers.setSlugFromFileName(fileName);
        request.execute().ignore();
    }
    catch (IOException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}
bivy
  • 216
  • 2
  • 10
  • 1
    This will return error 403:Unauthorized. To make it work, you will have to obtain google auth token and then add `headers.setAuthorization("OAuth " + authToken);` This code can help you implement the authorization part `http://code.google.com/p/google-plus-java-starter/source/browse/android/src/com/example/android/auth/AuthUtils.java` and instead of `PLUS_ME_SCOPE`, use `String AUTH_TOKEN_TYPE = "oauth2:https://picasaweb.google.com/data/"` – Bojan Radivojevic Jun 21 '12 at 12:32
0

see android-developers: picasa:

I havent found any docs, but u can make use of the built-in picasa app (if u r workin in 1.5) to upload ur photos to picasa web albums, but one limitation is that u dont hv the control of signing in and signing out... it uses the google account registered with the phone curently... if ur interested i can give u sm sample codes...

So there is no docs, you just Re-using an Activity of existing app.

Maksym Gontar
  • 22,765
  • 10
  • 78
  • 114