Weird Error With Video Intent On Jelly Bean
I'm experiencing a weird error with video Intents that I haven't experienced until Android 4.1. Here's my code for launching the Intent. I've tried with other MIME types as well, i
Solution 1:
I managed to find a solution with a bit of help from someone else. It seems that the setType()
call clears any previously attached data, including the setData()
call. Per the documentation:
This method automatically clears any data that was previously set (for example by setData(Uri)).
When I changed it to setDataAndType()
instead, it worked. It appears that it wasn't an issue with Jelly Bean after all, thankfully :-)
Here's the final code for creating the video intent:
publicstaticIntentgetVideoIntent(String fileUrl) {
Intent videoIntent = newIntent(Intent.ACTION_VIEW);
videoIntent.setDataAndType(Uri.fromFile(newFile(fileUrl)), getMimeType(fileUrl));
return videoIntent;
}
publicstaticStringgetMimeType(String url) {
Stringtype = null;
String extension = MimeTypeMap.getFileExtensionFromUrl(url);
if (extension != null) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extension);
if (TextUtils.isEmpty(type))
type = "video/*"; // No MIME type found, so use the video wildcard
}
returntype;
}
Post a Comment for "Weird Error With Video Intent On Jelly Bean"