I am Creating an application which records video and uploads it on YouTube and others Social sites.
For upload I use Droid share functionality and it works good.
In e-mail, Facebook, Skype, etc upload works perfect, but when I select YouTube, it does not upload my video.
Here is the code I use for video sharing.
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"SUBJECT_NAME");
sharingIntent.setType("video/*");
File newFile = new File(video_path);
sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM,Uri.fromFile(newFile));
startActivity(Intent.createChooser(sharingIntent,"Where you want to share?"));
Try this code.
ContentValues content = new ContentValues(4);
content.put(Video.VideoColumns.DATE_ADDED,
System.currentTimeMillis() / 1000);
content.put(Video.Media.MIME_TYPE, "video/mp4");
content.put(MediaStore.Video.Media.DATA, "video_path");
ContentResolver resolver = getBaseContext().getContentResolver();
Uri uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, content);
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Title");
sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM,uri);
startActivity(Intent.createChooser(sharingIntent,"share:"));
this code is add in your share button's onClick() method and get result.
pass the value in EXTRA_STREAM as an URI not as file.
I don't have enough reputation to comment, but I lost an hour or so trying to get user2126788's code to work because I forgot to set the type on the intent.
sharingIntent.setType("video/*");
please add this line in android manifest
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:host="www.youtube.com" android:mimeType="text/*" />
</intent-filter>
After several hours of trying to find out how to make it work for uploading and sharing video on facebook, youtube, instagram and whatsapp. this is the code that worked for me.
Uploading recorded video from your application to social media applications
ContentValues content = new ContentValues(4);
content.put(Video.VideoColumns.DATE_ADDED,
System.currentTimeMillis() / 1000);
content.put(Video.Media.MIME_TYPE, "video/mp4");
content.put(MediaStore.Video.Media.DATA, "your_path_to_video");
ContentResolver resolver = getBaseContext().getContentResolver();
Uri uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, content);
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("video/*");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Title");
sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM,uri);
startActivity(Intent.createChooser(sharingIntent,"share:"));
This code is working for me fine.
I try to Implement and get best result.
so,if anyone face this type of problem try this code.
I'm sure It's also works perfect for you.
ContentValues content = new ContentValues(4);
content.put(Video.VideoColumns.DATE_ADDED,
System.currentTimeMillis() / 1000);
content.put(Video.Media.MIME_TYPE, "video/mp4");
content.put(MediaStore.Video.Media.DATA, "path_of_video");
ContentResolver resolver = getBaseContext().getContentResolver();
Uri uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, content);
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Title_text");
//sharingIntent.setType("video/*");
//File newFile = new File(path_var);
sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM,uri);
startActivity(Intent.createChooser(sharingIntent,"Where you want to share?"));
this code is pitting in your share button's onClick() method and get result.
This code is working for me fine.
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Title_text");
//sharingIntent.setType("video/*");
File newFile = new File(path_var);
sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM,uri);
startActivity(Intent.createChooser(sharingIntent,"Where you want to share?"));
Another good solution is to implement your own upload mechanism without leaving your app.
You can use Google Java and Android libraries with YouTube java libraries.
Here's a full app utilizing this: https://github.com/youtube/yt-direct-lite-android
ContentValues content = new ContentValues(4);
content.put(MediaStore.Video.VideoColumns.DATE_ADDED,
System.currentTimeMillis() / 1000);
content.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");
content.put(MediaStore.Video.Media.DATA, path);
ContentResolver resolver = getActivity().getContentResolver();
Uri uri1 = Uri.fromFile(new File(path));
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("video/*");
sharingIntent.setPackage("com.google.android.youtube");
sharingIntent.putExtra(Intent.EXTRA_TITLE, "Title");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Desc");
sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM, uri1);
startActivity(Intent.createChooser(sharingIntent, "Share to"));
Related
In my app there is a feature where the user can share a video with the app of their choice. The code is fairly straightforward (where mediaPath is a variable of type String which is a path to a valid video):
File media = new File(mediaPath);
Uri uri = FileProvider.getUriForFile(context, getString(R.string.file_provider_authority), media);
Intent share = new Intent(Intent.ACTION_SEND);
share.putExtra(Intent.EXTRA_STREAM, uri);
share.setType("video/*");
String title = getString(R.string.share_video_title);
Intent chooser = Intent.createChooser(share, title);
if (share.resolveActivity(context.getPackageManager()) != null) {
startActivity(chooser);
}
Sharing works perfectly on gmail (for example) and seems to work fine on whatsapp as well. It compresses the video and uploads it. The recipient gets the video and is able to see a thumbnail and download it. However they cannot play the video.
I finally found the solution is here
public void shareVideoWhatsApp() {
Uri uri = Uri.fromFile(v);
Intent videoshare = new Intent(Intent.ACTION_SEND);
videoshare.setType("*/*");
videoshare.setPackage("com.whatsapp");
videoshare.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
videoshare.putExtra(Intent.EXTRA_STREAM,uri);
startActivity(videoshare);
}
Refrence
Are you try this:
String path = ""; //should be local path of downloaded video
ContentValues content = new ContentValues(4);
content.put(MediaStore.Video.VideoColumns.DATE_ADDED,
System.currentTimeMillis() / 1000);
content.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");
content.put(MediaStore.Video.Media.DATA, path);
ContentResolver resolver = getApplicationContext().getContentResolver();
Uri uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, content);
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("video/*");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "Hey this is the video subject");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Hey this is the video text");
sharingIntent.putExtra(Intent.EXTRA_STREAM,uri);
startActivity(Intent.createChooser(sharingIntent,"Share Video");
I want to upload video on you-tube and i am uploading video using this code but the problem is that whenever i click the button from my app then i have to select you-tube from list view of email,Bluetooth,you-tube,etc..
So i want the permanent solution for this that whenever i click a button from my app it automatically moves to you-tube without showing list view.
So, this is my code which i used to upload video over you-tube.
**ContentValues content = new ContentValues(4);
content.put(Video.VideoColumns.TITLE, "My Test");
content.put(Video.VideoColumns.DATE_ADDED,
System.currentTimeMillis() / 1000);
content.put(Video.Media.MIME_TYPE, "video/mp4");
content.put(MediaStore.Video.Media.DATA, outputFile);
ContentResolver resolver = getContentResolver();
Uri uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,content);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("video/*");
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Share using"));**
This might help you,
String url = "http://youtu.be/mo1DmO9JH3Y"; // Your Url here..
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube://"+url));
activity.startActivity(intent);
I'm use this code to share on google+:
ShareCompat.IntentBuilder builder = ShareCompat.IntentBuilder.from(activity);
builder.setType("text/plain");
builder.setText(text);
if (imageURI != null) {
builder.setStream(imageURI)
.setType("image/png");
}
Intent shareIntent = builder.getIntent()
.setPackage("com.google.android.apps.plus");
activity.startActivity(shareIntent);
And if there is an image - it share image without text, if there is no image - it share text successfully.
How can I post text and images together?
I have been trying to solve this today and I think I got it - I hope you have solved it in the meantime, but still somebody else may find this useful.
File f = new File(your_file_path);
ContentValues values = new ContentValues(2);
values.put(MediaStore.Images.Media.MIME_TYPE, "image/png"); //or /jpeg or whatever
values.put(MediaStore.Images.Media.DATA, f.getAbsolutePath());
Uri uri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/png");
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.putExtra(Intent.EXTRA_TEXT, "blahblah");
intent.setPackage("com.google.android.apps.plus");
startActivity(intent);
I think the problem with your code might be that you "override" the text type with the image. I haven't used IntentBuilders, though, so feel free to correct me on that.
I am trying to upload a video to youtube using the intent.
The way I have it set is described here
Here's snippet:
ContentValues content = new ContentValues(4);
content.put(Video.VideoColumns.TITLE, "My Test");
content.put(Video.VideoColumns.DATE_ADDED,
System.currentTimeMillis() / 1000);
content.put(Video.Media.MIME_TYPE, "video/mp4");
content.put(MediaStore.Video.Media.DATA, outputFile);
ContentResolver resolver = getContentResolver();
Uri uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
content);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("video/*");
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Share using"));
I would like to have the title field already set.
Otherwise, if the user does not manually set the title field the video uploaded will have the title of the video filename.
Go through the following link
http://diablo-urban-o.com/post/9929911420/uploading-videos-to-youtube-from-android-part-ii
and try the following code too.
ContentValues content = new ContentValues(4);
content.put(Video.VideoColumns.TITLE, "Test");
content.put(Video.VideoColumns.DATE_ADDED,
System.currentTimeMillis() / 1000);
content.put(Video.Media.MIME_TYPE, "video/mp4");
content.put(MediaStore.Video.Media.DATA, "/sdcard/myvideo.mp4");
ContentResolver resolver = getContext().getContentResolver();
Uri uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, content);
Hope this will help you...
Here is a demo application that does want you want . Use the ytUploader.setTitle("Android Test"); to set whatever title you want.
Intent intent1 = new Intent(
android.provider.MediaStore.INTENT_ACTION_MUSIC_PLAYER)
.setData(selectedImageUri);
i want to play a media file using android default media player but its not working in devices showing
ActivityNotFoundException
.can any one help me to correct it.i am stuck here
String extension = MimeTypeMap
.getFileExtensionFromUrl(selectedImagePath);
String mimeType = MimeTypeMap.getSingleton()
.getMimeTypeFromExtension(extension);
Intent mediaIntent = new Intent(Intent.ACTION_VIEW);
mediaIntent.setDataAndType(Uri.parse(selectedImagePath),
mimeType);
startActivity(mediaIntent);
I used this code and i got my output.
Maybe this will help you. The following is the piece which I use and it works fine. Pass the url to your default media Player and from there it will take care of it.
Uri myUri = Uri.parse( //your url);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(myUri, "audio/*");
startActivity(intent);