Upload video from Android app to Youtube, Facebook, Gmail using SEND intent - android

[EDIT] I'm working on Android Lollipop. I want to share (upload) my video (.mp4) from sdcard to Facebook, Youtube,... using intent SEND. My problem is that: when I upload video first time, everything works perfectly. But if I try to upload this video again, nothing is attached. (For example: first time: I upload video to Facebook successfully. Then I try to upload it to Facebook again, video is not attached). Here is my code now:
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, "/sdcard/rec5.mp4");
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);
intent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Title");
startActivity(Intent.createChooser(intent, "Share using"));
Can anybody tell me what did I miss in my code?

Related

Share video to WhatsApp and other apps using Android Intent (Java)

I want to implement share video to whatsApp and other app feature using Android Intent system.
I have been looking for it for last 2 days but I did not get proper solution and some solutions I found on StackOverFlow, they no longer work I guess.
Whenever share Intent opens and I click on whatsApp and choose contact to share then it says file format is not supported
Below is my code:
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, "/storage/emulated/0/WhatsApp/Media/WhatsApp Video/VID-20210822-WA0002.mp4");
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:"));

Share Audio File (MP3) android with Whatsapp trigger this error: "The file format is not supported"

I am trying to share an mp3 file with with an intent on Android.
The code that I am using is the following:
// uri creation
audioFile=Uri.parse("android.resource://" + getPackageName() + "/raw/audio" + albumArtResId);
// intent creation
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/mp3");
share.putExtra(Intent.EXTRA_STREAM, audioFile);
startActivity(Intent.createChooser(share, "Share Sound File"));
But after the selection of a specific contact in whatsapp a toast notification appears with the following message:"the file format is not supported".
I am quite sure that the problem is given by the URI creation but I have no ideas about how to solve it.

Android Sharing Intent cannot start

I am writing an Android application to upload a mp4 format video from sdcard to youtube using sharing Intent. It ran perfectly at the first time when I installed to my phone. However, after I restart the app, I cannot share it again. If i share to whatsapp, "sharing fail" apear. If I click youtube, I got "no media uri(s)" message on logcat. Reinstalling on same phone or restarting the phone cannot solve the problem.
Even when I install the app in same code to other android device, it only runs perfectly once. When i restart the app, same problem happened.
I got the code from this website:
Trouble with youtube upload
And this is my code:
findViewById(R.id.button2).setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("video/*");
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, Environment.getExternalStorageDirectory().getAbsolutePath()+"/myVideo/myVideoTemp.mp4");
ContentResolver resolver = getBaseContext().getContentResolver();
Uri uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, content);
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,"");
sharingIntent.putExtra(android.content.Intent.EXTRA_TITLE,"");
sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM,uri);
startActivity(Intent.createChooser(sharingIntent,"Share video"));
}
});
p.s. there is no error in red color on logcat
Problem solved after adding sharingIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
Try the following to invoke the "share" applications:
//Use the URI that points to the video file, in my case, the video file is in local storage (sd card)
Uri fileUri = Uri.fromFile(videoFile);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
//Use the setDataAndType method to provide the URI and MIME type to the file
//Please note, you need to use setDataAndType method to make it work
intent.setDataAndType(fileUri,URLConnection.guessContentTypeFromName(fileUri.toString()));
startActivity(intent);
I have a blog to show how you can invoke video players from your app with a video file stored locally. It may help:
http://software.intel.com/en-us/blogs/2014/03/20/video-playing-with-android-media-player

How can I send the user to a video player in Android?

I have read this article:
Sending the User to Another App
If user click on a button, and they should be sent to a video player to watch the video, could anyone please tell me what I should put in the Intent's constructor? I have the path of an mp4 file as String.
try following code
File file=new File(filepath);
Uri uriToFile=Uri.fromFile(file);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToFile);
shareIntent.setType("*/mp4");
startActivity(Intent.createChooser(shareIntent,"Send to"));

Share audio file (.mp3) via Facebook, email, and SMS/MMS

I have an audio file (.mp3) and some information related to it. I want to share with Facebook, E-mail, SMS/MMS, etc..
What I have done is: when user clicks on the share button, it pops up list of all supported applications that can handle this Intent. But this does not show Facebook and SMS/MMS options.
Here is my code..
public void shareWithFriends(int resId)
{
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/mp3");
share.putExtra(Intent.EXTRA_SUBJECT,"Ringtone File : "+ getResources().getResourceEntryName(resId)+".mp3");
share.putExtra(Intent.EXTRA_TEXT,"Ringtone File : "+getResources().getResourceEntryName(resId)+".mp3");
share.putExtra(Intent.EXTRA_STREAM,Uri.parse("android.resource://com.my.android.soundfiles/"+resId));
share.putExtra("sms_body","Ringtone File : "+ getResources().getResourceEntryName(resId)+".mp3");
startActivity(Intent.createChooser(share, "Share Sound File"));
}
Here are some results:
When I use MIME type audio/mp3, only the email options pops up. No Facebook and SMS/MMS share.
When I use MIME type */*, Email and SMS options pops up. No Facebook option is there.
Here it is interesting to note that when I click on the SMS option, only text appears. I don't see any MP3 file attached (the same thing happens in Whatsapp (as I have Whatsapp installed on my phone). However, when I click on any mail application (for example, Gmail or Yahoo mail) it shows me the MP3 file attached.
Where am I going wrong?
There is no option for Facebook, but you can share email and MMS with Bluetooth. Here is my code. Take a look if it helps you:
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/*");
share.putExtra(Intent.EXTRA_STREAM,Uri.parse("file:///"+mypath));
startActivity(Intent.createChooser(share, "Share Sound File"));
break;
Here my path is the path of the sound file on the SD card.
You are trying to share an mp3 over services that don't support it.
Facebook supports text, pictures and videos.
SMS is plain text (and only very short plain text)
MMS does support audio, but (as far as I can tell from observation (i.e. without reading the spec)) only very low bit rate audio in some format that usually comes in a file with a .3g extension
The apps do not show up in the list of supported apps for mp3 because they are not supported.
File f=new File("full audio path");
Uri uri = Uri.parse("file://"+f.getAbsolutePath());
Intent share = new Intent(Intent.ACTION_SEND);
share.putExtra(Intent.EXTRA_STREAM, uri);
share.setType("audio/*");
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(Intent.createChooser(share, "Share audio File"));
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("audio/*");
sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM,
Uri.fromFile(new File("filepath")));
startActivity(Intent.createChooser(sharingIntent,"Share using"));
You are try this.
final Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra("sms_body", "bod of sms");
sendIntent.setType("*/*");
sendIntent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
final File file1 = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),"test.amr");
Uri uri = Uri.fromFile(file1);
Log.e("Path", "" + uri);
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(sendIntent, ""));
Use following code its working for me to share audio via intent.
String path = Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/abc.mp3";
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/*");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///" + path));
startActivity(Intent.createChooser(share, "Share Sound File"));
String sharePath = Environment.getExternalStorageDirectory().getPath()
+ "/Soundboard/Ringtones/custom_ringtone.ogg";
Uri uri = Uri.parse(sharePath);
Intent share = new Intent(Intent.ACTION_SEND);share.setType("audio/*");
share.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(share, "Share Sound File"));

Categories

Resources