Video Picker - exception in Nougat - android

This is our code for video picker, pretty much standard code. This code works in Android version before Nougat, however, it raises an exception in nougat.
private void pickVideoFromGallery(Activity activity){
Intent intent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
intent.setType("video/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
activity.startActivityForResult(intent, MediaPicker.TYPE_FILEVIDEO);
}
And the exception is
android.content.ActivityNotFoundException: No Activity found to handle
Intent { act=android.intent.action.PICK cat=[android.intent.category.OPENABLE]
typ=video/* launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 } }
However if I uncomment following line, it starts working but that's not the solution as we are looking to select only openable videos
intent.addCategory(Intent.CATEGORY_OPENABLE);
Any idea?

Launch default file picker with videos.
Intent intent = new Intent();
intent.setType("video/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, 1);

Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT);
galleryIntent.addCategory(Intent.CATEGORY_OPENABLE);
galleryIntent.setType("video/*");
Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
chooserIntent.putExtra(Intent.EXTRA_INTENT, galleryIntent);
chooserIntent.putExtra(Intent.EXTRA_TITLE, "File Chooser");

Related

No Activity found to handle Intent android.intent.action.OPEN_DOCUMENT_TREE on Nokia 6.2 Android 9

it works perfectly on other phones, the problem is only with Nokia
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
activity.startActivityForResult(intent, CODE_REQUEST_OPEN_DOCUMENT_TREE);
it shows because your device hase no application for reading documents
put code as below for checking it
intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
try {
activity.startActivityForResult(intent, requestCode);
return;
} catch (ActivityNotFoundException anfe) {
Log.w(TAG, "couldn't complete ACTION_OPEN_DOCUMENT, no activity found. falling back.");
}
you can check more clearly by link2
Check if at least one activity exists to handle that Intent:
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
if (intent.resolveActivity(context.getPackageManager()) != null) {
activity.startActivityForResult(intent, CODE_REQUEST_OPEN_DOCUMENT_TREE);
}
Using Different type of Chooser to select document type. It is easy to use in android check Below code.
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
String[] mimetypes = {"application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/msword"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
startActivityForResult(intent, REQUEST_CODE_OPEN);

How to combine ACTION_IMAGE_CAPTURE and ACTION_VIDEO_CAPTURE together

I need to call Intent for image and video both at same time . It seems impossible similar to this . So a alternate way to do this is createChooser() . But i am kinda stuck with the code below .
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, file.getAbsolutePath());
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, file.getAbsolutePath());
Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
Intent[] intentArray = new Intent[]{takePictureIntent};
chooserIntent.putExtra(Intent.EXTRA_INTENT, takeVideoIntent);
chooserIntent.putExtra(Intent.EXTRA_TITLE, "Choose an action");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
startActivityForResult(chooserIntent, 1);
MediaStore.EXTRA_OUTPUT not working . The file is empty after returning from camera . However it does open a chooser as below but file is empty .
Questions:-
1.How to can i combine both intents and provide separate files as MediaStore.EXTRA_OUTPUT?
2. As we all know there are hundreds of camera apps in android so is this a good way to open such intent(Will it work in all devices regardless of manufacturer and API Level) ? Or i should move with an AlertDialog to open intent for each action seperatly .
Try this below code :
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
Intent chooserIntent = Intent.createChooser(takePictureIntent, "Capture Image or Video");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{takeVideoIntent});
startActivityForResult(chooserIntent, CAMERA_IMAGES_REQUEST);

Getting both Photos and Videos from the new Google Photos app on Android

I'd like the user to import a bunch of videos/photos into my app. This is the code I was using before:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setType("image/*,video/*");
activity.startActivityForResult(intent, REQUEST_CODE_PICK_MEDIA);
The problem I'm having is that the above returns only Photos from the new Google Photos app. If I change the data type to 'video/*' only, the Photos app returns videos. This is for KitKat+
EDIT:
I've tried the following code - it works on some galleries but not with most and not Google Photos:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
if (AndroidHelper.isKitKatAndAbove()) {
Log.d(TAG, "Pick from gallery (KitKat+)");
String[] mimeTypes = {"image/*", "video/*"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
activity.startActivityForResult(intent, REQUEST_CODE_PICK_MEDIA);
} else {
Log.d(TAG, "Pick from gallery (Compatibility)");
activity.startActivityForResult(intent, REQUEST_CODE_PICK_MEDIA);
}
This is what I ended up doing:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
if (AndroidHelper.isKitKatAndAbove()) {
Log.d(TAG, "Pick from gallery (KitKat+)");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
activity.startActivityForResult(intent, REQUEST_CODE_PICK_MEDIA);
} else {
Log.d(TAG, "Pick from gallery (Compatibility)");
activity.startActivityForResult(intent, REQUEST_CODE_PICK_MEDIA);
}
Then when I get results, I check the type of the file. Seems to be working fine.

why file picker intent is returning null path on android 4.4?

so I have the code below working fine until android 4.4. I was able to get the path from the uri by intent.getData() in onActivityResult then do something special about the uri to get the path of the photo that was selected.
private Intent createPhotoIntent() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
Intent chooser = createPhotoChooserIntent(createPhotoFromCameraIntent());
chooser.putExtra(Intent.EXTRA_INTENT, intent);
return chooser;
}
private Intent createPhotoChooserIntent(Intent... intents) {
Intent chooser = new Intent(Intent.ACTION_CHOOSER);
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intents);
chooser.putExtra(Intent.EXTRA_TITLE, "Please Choose Your Image");
return chooser;
}
private Intent createPhotoFromCameraIntent() {
return new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
}
what I dont understand is why I'm not able to get anything from intent.getData() now?? I also insert a line break to check what I received from the intent in onActivityResult, and I see nothing related to the path. I was able to see content://media/external/images/media/1249 but not anymore now....what happen to android 4.4!!??
please help.

call android gallery for both image and video

when i have to get some image or video
i did like this
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("video/*");
startActivityForResult(intent , ActNetwork.EXTRA_FLAG_SEARCH_LOCAL_VOD);
and
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent , ActNetwork.EXTRA_FLAG_SEARCH_LOCAL_VOD);
i try to
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/* , video/*");
but in occured error
how can i solve that problem..
thanks your reply
Try this
final Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT);
galleryIntent.setType("image/* video/*");
startActivityForResult(galleryIntent, REQUEST_CODE);
have you tried with
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("media/*");
startActivityForResult(intent , ActNetwork.EXTRA_FLAG_SEARCH_LOCAL_VOD);
Try this
intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 1);
Works on 2.1
I was also having the same issue and I found the solution.
Intent pickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
pickerIntent.setType("image/*, video/*");
pickerIntent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] {"image/*", "video/*"});
startActivityForResult(pickerIntent, REQUEST_CODE_FOR_MEDIA);
The key here is pickerIntent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] {"image/*", "video/*"});
Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
photoPickerIntent.setType("*/*");
photoPickerIntent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] { "video/* images/*"});
startActivityForResult(photoPickerIntent, REQUEST_GALLERY);

Categories

Resources