AP257
AP257

Reputation: 93793

Android: Youtube and ACTION_SENDTO?

I'm writing an Android app where users can upload video to Youtube. I'd like the Youtube tag field to be pre-filled with a tag that I set.

I'd also like the UI to work like this: user clicks on an Upload button, user goes straight to Youtube upload intent (rather than picking from a Chooser), tag field is pre-filled for them.

Is this possible using ACTION_SENDTO?

Currently I have this code, which just launches a Chooser, which really isn't what I want:

    btnUpload.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            //uploadToYouTube();
            //videoUpload();
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_SEND);
            intent.setType("video/3gpp");
            intent.putExtra(Intent.EXTRA_STREAM, videoURI);
            try {
                         startActivity(Intent.createChooser(intent,
                                 "Upload video via:"));
            } catch (android.content.ActivityNotFoundException ex) {
                         Toast.makeText(Recorder.this, "No way to share!",
                                 Toast.LENGTH_SHORT).show();
            }
        }
    });

Upvotes: 1

Views: 5455

Answers (4)

PLG
PLG

Reputation: 468

So, actually this is the undocumented code... BIG THANKS to Andrew Koester for your clues!

          Intent intent = new Intent(Intent.ACTION_SEND,uri);
          intent.setType("video/3gpp");
          intent.setComponent(new ComponentName(
                  "com.google.android.apps.uploader",
                  "com.google.android.apps.uploader.youtube.YouTubeSettingsActivity")

              );
          intent.setFlags(0x3000000); // ParcelFileDescriptor.MODE_READ_WRITE ?!?
          intent.putExtra(Intent.EXTRA_STREAM,uri);

          try {
              startActivity(intent); //              
              // startActivityForResult(intent,23); //only returns OK... how to get URL?!
          } 
          catch (android.content.ActivityNotFoundException ex) {
              Toast.makeText(getApplicationContext(),"No way to share",Toast.LENGTH_SHORT).show();
          }

Upvotes: 1

AP257
AP257

Reputation: 93793

Turned out the best way to do it was to upload to my own site via an ordinary POST request, and then upload to YouTube from there, server-side.

Upvotes: 2

Jess
Jess

Reputation: 42928

It's launching a chooser because you're telling it to with Intent.createChooser. You need to specify YouTube's Activity directly.

Upon investigation, it looks like MediaUploader handles YouTube uploading. I looked into it's AndroidManifest.xml and I'm guessing the Intent you want to fire is this:

com.google.android.apps.uploader.UploaderApplication.youtube.YouTubeSettingsActivity

Here is the interesting parts of the AndroidManifest.xml.

<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:versionCode="com.google.android.googleapps.permission.GOOGLE_AUTH.YouTubeUser"
    android:versionName="1.4.13"
    package="com.google.android.apps.uploader">
    <uses-sdk android:minSdkVersion="com.google.android.googleapps.permission.GOOGLE_AUTH.YouTubeUser" />
    <application
        android:label="com.google.android.googleapps.permission.GOOGLE_AUTH.YouTubeUser"
        android:name=".UploaderApplication"
        android:debuggable="com.google.android.googleapps.permission.GOOGLE_AUTH.YouTubeUser">
        <activity
            android:theme="com.google.android.googleapps.permission.GOOGLE_AUTH.YouTubeUser"
            android:name=".youtube.YouTubeSettingsActivity"
            android:excludeFromRecents="com.google.android.googleapps.permission.GOOGLE_AUTH.YouTubeUser"
            android:configChanges="com.google.android.googleapps.permission.GOOGLE_AUTH.YouTubeUser">
            <intent-filter
                android:label="com.google.android.googleapps.permission.GOOGLE_AUTH.YouTubeUser"
                android:icon="com.google.android.googleapps.permission.GOOGLE_AUTH.YouTubeUser">
                <data android:mimeType="video/*" />
                <action android:name="android.intent.action.SEND" />
                <action android:name="android.intent.action.SEND_MULTIPLE" />
                <category android:name="android.intent.category.ALTERNATIVE" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

You'll notice that the intent-filter for the YouTubeSettingsActivity is receiving the SEND action, so that's likely the intent we want.

As CommonsWare said, however, this is dependent on the phone having YouTube support, and can break. This was taken from my system image of 2.0.1. Make sure you check to see that the intent works before firing it.

Upvotes: 2

CommonsWare
CommonsWare

Reputation: 1006674

Personally, I think the current implementation is the right answer -- just because you want YouTube doesn't mean that the user wants YouTube.

Upvotes: 0

Related Questions