I made an application where the user can open and upload a video file. It worked well but some weeks ago someone reported that his Samsung phone (Android 7) opens the video in 3gpp format. But in the file explorer the video says its format is mp4 and for example the Gmail also opens it in mp4 format.
I had limited debug possibilities because I have only a ZTE v5 Redbull (Android 4.4.2), so I used the Samsung remote test lab (http://developer.samsung.com/remotetestlab/rtlDeviceList.action). In my device, I cannot reproduce this issue.
I followed this description about how to get the content URI of the chosen file and how to open them. https://developer.android.com/guide/topics/providers/document-provider.html
As I know, it's not recommended to convert the content URI (content://...) to the real file path (file://...), but I also tried out this solution based on this: https://stackoverflow.com/a/27271131/7539161 It worked sometimes but not in all cases. The application sometimes didn't find the path. But when it found the path, the file had mp4 format and everything was fine. It seems the recommended Storage Access Framework doesn't open the videos in mp4 format on Samsung phones.
Based on the previous idea, I tried to rename the file from 3gpp to mp4 but it didn't work.
This is how it starts the file chooser intent:
public void startContentChooserIntent(){
if (Build.VERSION.SDK_INT < 19){
Intent intent = new Intent();
intent.setType("*/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, CHOOSE_CONTENT_ACTIVITY_REQUEST_CODE);
} else {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(intent, CHOOSE_CONTENT_ACTIVITY_REQUEST_CODE);
}
}
This is how it gets the content URI and the extension:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode){
case CHOOSE_CONTENT_ACTIVITY_REQUEST_CODE: {
if (resultCode == RESULT_OK) {
contentUri = data.getData();
ContentResolver contentResolver = getContentResolver();
MimeTypeMap mime = MimeTypeMap.getSingleton();
String extension = mime.getExtensionFromMimeType(contentResolver.getType(contentUri)); // 3gpp instead of mp4
}
}
}
}
It also requests for permission to read external storage before starting the intent:
public void chooseContent(){
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
CONTENT_CHOOSER_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE );
} else {
startContentChooserIntent();
}
}
I ran out of ideas, so I hope someone have a solution. There is a similar question, but no answers: 3gpp and mp4 on android
Update
I made two screenshots about the videos' properties what I tried to open with the samsung phones. Please check the comments below for the links.
In the application, the MIME type of the opened videos was video/3gpp.