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:"));
Related
How to share video URL to all apps in android (Whats app, Facebook etc)?
By applying below code, I am facing "File Format not supported error"?
enter code here
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, "http://www.demonuts.com/Demonuts/smallvideo.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:"));
First, the documentation states that the value for EXTRA_STREAM is supposed to be a Uri with a content: scheme, which means it points to a ContentProvider. Apps implementing ACTION_SEND might support other schemes, but they do not have to, and in particular they do not have to support http.
Second, use a real MIME type, not a wildcard. You are supplying the content; you should know its MIME type.
Third, as others pointed out in comments, http://www.demonuts.com/Demonuts/smallvideo.mp4 is not a filesystem path. It is a URL. Use Uri.parse("http://www.demonuts.com/Demonuts/smallvideo.mp4") to get that in the form of a Uri.
I have to share an image from my application to instagram. I have gone through Instagram developer documentation and there they mentioning only about sharing via Intent method, but what I need is I have to get a callback after posting successfully.
private void createInstagramIntent(String type, String mediaPath){
// Create the new Intent using the 'Send' action.
Intent share = new Intent(Intent.ACTION_SEND);
// Set the MIME type
share.setType(type);
// Create the URI from the media
File media = new File(mediaPath);
Uri uri = Uri.fromFile(media);
// Add the URI to the Intent.
share.putExtra(Intent.EXTRA_STREAM, uri);
// Broadcast the Intent.
startActivity(Intent.createChooser(share, "Share to"));
}
is there any way to do this ?
There are several options depending on their API. At first referring their Android Intents, that is a bad example IMHO, this is more or less the default way in Android how to share data. What you want is something more like to open just their app. For such cases is there the setPackage() option:
// Create the new Intent using the 'Send' action.
Intent share = new Intent(Intent.ACTION_SEND);
// Limit this call to instagram
share.setPackage("com.instagram.android");
// Set the MIME type
share.setType(type);
// Create the URI from the media
File media = new File(mediaPath);
Uri uri = Uri.fromFile(media);
// Add the URI to the Intent.
share.putExtra(Intent.EXTRA_STREAM, uri);
try {
// Fire the Intent.
startActivityForResult(share, REQUEST_CODE);
} catch(ActivityNotFoundException e) {
// instagram not installed
}
Now for the case that instagram is not installed you are almost lost. If there is no other SDK there is nothing you can do.
A very complex workaround might be to upload the file to your own backend. Then open the browser to gain access to an oauth token to upload the image via your backend. However this is a quiet expensive solution which I would avoid.
[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?
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
So, I have the file path of a file in an application & I want to give the user the ability to select from all applications on the phone that can handle/open that file type and then open the file in that applicaton. How do I do this? - performs a similar function to a file manager.
First you have to pick the type of Intent you want. This code picks applications that can send the data through SMS/email/etc utilizing ACTION_SEND.
Intent intent = new Intent(Intent.ACTION_SEND);
Next you need to use putExtra to get the file/message to the Intent.
Uri uri = Uri.fromFile(new File(myFile));
intent.putExtra(Intent.EXTRA_STREAM, uri);
Finally you create a chooser.
Intent chooser = Intent.createChooser(intent, "A Custom Message");
startActivity(chooser);