I can take a video with an intent now what are the details to create an intent to start the default video trimmer activity? And check if it present on the device?
2 Answers
This solution relies on a version of the AOSP Gallery2 package being installed on the device. You can do it like this:
// The Intent action is not yet published as a constant in the Intent class
// This one is served by the com.android.gallery3d.app.TrimVideo activity
// which relies on having the Gallery2 app or a compatible derivative installed
Intent trimVideoIntent = new Intent("com.android.camera.action.TRIM");
// The key for the extra has been discovered from com.android.gallery3d.app.PhotoPage.KEY_MEDIA_ITEM_PATH
trimVideoIntent.putExtra("media-item-path", getFilePathFromVideoURI(this, videoUri));
trimVideoIntent.setData(videoUri);
// Check if the device can handle the Intent
List<ResolveInfo> list = getPackageManager().queryIntentActivities(trimVideoIntent, 0);
if (null != list && list.size() > 0) {
startActivity(trimVideoIntent); // Fires TrimVideo activity into being active
}
The method getFilePathFromVideURI
is based on the answer of this question: Get filename and path from URI from mediastore
public String getFilePathFromVideoURI(Context context, Uri contentUri) {
Cursor cursor = null;
try {
String[] proj = { MediaStore.Video.Media.DATA };
cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} finally {
if (cursor != null) {
cursor.close();
}
}
}
videoUri
is an Uri
pointing to something like this: content://media/external/video/media/43
. You can gather one by issuing an ACTION_PICK Intent:
Intent pickVideoUriIntent = new Intent(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(pickVideoUriIntent, PICK_VIDEO_REQUEST);
In onActivityResult
get the uri like so:
....
case PICK_VIDEO_REQUEST:
Uri videoUri = data.getData();
...
This solution works on my Galaxy Nexus with Android 4.3 Jelly Bean.
I am not sure if this is available on all Android devices. A more reliable solution may be to fork the Gallery2 app and put the TrimVideo activity together with its dependencies into a library that can be delivered with your app. Hope this helps anyway.

- 1
- 1

- 106
- 2
-
Only wish it would return back to my app after cropping and saving – user1447209 Feb 14 '14 at 12:18
-
hello sir , when i follow your code i got Toast Message "Editing is not support for this image". i am not able to understand what is this please help me. thank you. – Pratik Sanyaja Oct 07 '18 at 05:52
-
@PratikSanyaja The first sentence of this answer explains that this answer requires you have a version of AOSP Gallery2 installed on the device. If you do not, you will get the message you are seeing. – Mira_Cole Jan 18 '19 at 19:31
Try this may it helps
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra("android.intent.extra.durationLimit", 30000);
intent.putExtra("EXTRA_VIDEO_QUALITY", 0);
startActivityForResult(intent, ActivityRequests.REQUEST_TAKE_VIDEO);
This code works well on API >=2.2, but the duration limit does not work on API 2.1

- 1,069
- 1
- 9
- 17
-
1I dont want to take a video I said I can do that already, I want to trim a video that exists already – user1447209 Feb 10 '14 at 12:38