Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE )
this intent will show a list of cameras to choose if i've installed other camera apps, so my question is how to directly call system camera, not to choose others.
You can try this,
Intent camIntent = new Intent("android.media.action.IMAGE_CAPTURE");
Intent systemCamIntent = new Intent(camIntent);
systemCamIntent.setComponent(new ComponentName("com.sec.android.app.camera", "com.sec.android.app.camera.Camera"));
startActivity(systemCamIntent);
You can get list of camera by using the code below, then you should create a logic to understand which is system camera for different rooms.
List<Intent> yourIntentsList = new ArrayList<Intent>();
List<ResolveInfo> listCam = packageManager.queryIntentActivities(camIntent, 0);
for (ResolveInfo res : listCam) {
finalIntent = new Intent(camIntent);
finalIntent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
yourIntentsList.add(finalIntent);
}
Related
Here's a implementation I found in a app named Pawoo. I can choose take photo or pick a image from system built-in gallery or third-party gallery at the same time.
I wonder how to achieve it with just one Intent. Because it seems not implements by third-party library.
I already know how to achieve it. Inspired by Intent to choose between the camera or the gallery in Android
The answer of qustion is not just one Intent. Simply, in my question screentshot, there's 3 actions, that's means 3 Intents. The key method is Intent.createChooser()
Here's my complete code:
public void click(View view) {
File file = getExternalFilesDir(Environment.DIRECTORY_DCIM);
Uri cameraOutputUri = Uri.fromFile(file);
Intent intent = getPickIntent(cameraOutputUri);
startActivityForResult(intent, -1);
}
private Intent getPickIntent(Uri cameraOutputUri) {
final List<Intent> intents = new ArrayList<Intent>();
if (true) {
intents.add(new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI));
}
if (true) {
setCameraIntents(intents, cameraOutputUri);
}
if (intents.isEmpty()) return null;
Intent result = Intent.createChooser(intents.remove(0), null);
if (!intents.isEmpty()) {
result.putExtra(Intent.EXTRA_INITIAL_INTENTS, intents.toArray(new Parcelable[] {}));
}
return result;
}
private void setCameraIntents(List<Intent> cameraIntents, Uri output) {
final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
final PackageManager packageManager = getPackageManager();
final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
for (ResolveInfo res : listCam) {
final String packageName = res.activityInfo.packageName;
final Intent intent = new Intent(captureIntent);
intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
intent.setPackage(packageName);
intent.putExtra(MediaStore.EXTRA_OUTPUT, output);
cameraIntents.add(intent);
}
}
Here's the my demo:
It's not one Intent. This dialog is a bottom sheet.
I've successfully created an intent chooser which lists Gallery, Documents and Camera. But when I try to select Camera from the chooser, nothing happens on clicking it.
I tried creating a chooser with just Camera Intent, even then the result was the same.
This exact code was working before the Marshmallow update. I suspect it has something to do with it. Have you come across a similar problem? And How did you solve it?
Following is my code to create an intent chooser.
public Intent getPickImageChooserIntent() {
// Determine Uri of camera image to save.
fileUri = getCaptureImageOutputUri();
List<Intent> allIntents = new ArrayList<>();
PackageManager packageManager = getPackageManager();
// collect all camera intents
Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
for (ResolveInfo res : listCam) {
Intent intent = new Intent(captureIntent);
intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
intent.setPackage(res.activityInfo.packageName);
if (fileUri != null) {
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
}
allIntents.add(intent);
}
// collect all gallery intents
Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT);
galleryIntent.setType("image/*");
List<ResolveInfo> listGallery = packageManager.queryIntentActivities(galleryIntent, 0);
for (ResolveInfo res : listGallery) {
Intent intent = new Intent(galleryIntent);
intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
intent.setPackage(res.activityInfo.packageName);
allIntents.add(intent);
}
// the main intent is the last in the list (fucking android) so pickup the useless one
Intent mainIntent = allIntents.get(allIntents.size() - 1);
for (Intent intent : allIntents) {
if (intent.getComponent().getClassName().equals("com.android.documentsui.DocumentsActivity")) {
mainIntent = intent;
break;
}
}
allIntents.remove(mainIntent);
// Create a chooser from the main intent
Intent chooserIntent = Intent.createChooser(mainIntent, "Select source");
// Add all other intents
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, allIntents.toArray(new Parcelable[allIntents.size()]));
return chooserIntent;
}
As #Tynn pointed out, The problem is because of the new Permission Model. I had to setup runtime checks for the permission status for each of the permissions.
I have a problem with sharing on Android M and exactly with creating intent chooser with filter. I've create a standard text share intent:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, getSharingText());
return intent;
Then I've applied the filter for chooser:
List<Intent> targetedShareIntents = new ArrayList<>();
List<ResolveInfo> resolves = getActivity().getPackageManager().queryIntentActivities(intent, 0);
for (ResolveInfo resolveInfo : resolves) {
String packageName = resolveInfo.activityInfo.packageName;
Intent targetedShareIntent = new Intent(mPromoIntent);
if (!packageName.equals("com.facebook.katana")
&& !packageName.equals("com.vkontakte.android")) {
ComponentName componentName = new ComponentName(packageName, resolveInfo.activityInfo.name);
targetedShareIntents.add(targetedShareIntent.setComponent(componentName));
}
}
if (targetedShareIntents.isEmpty()) {
return null;
}
Intent chooser = targetedShareIntents.remove(0);
return Intent.createChooser(chooser, chooserText)
.putExtra(Intent.EXTRA_INITIAL_INTENTS,
targetedShareIntents.toArray(new Parcelable[targetedShareIntents.size()]));
And the I've started the standard chooser ChooserActivity using chooser intent
startActivity(mAppsChooserIntent);
But on Android M it doesn't show chooser, it takes the first intent (in my case bluetooth) and shares with it.
I've looked through the ChooserActivity class, which in Android MNC is much bigger than in Android L and didn't find a solution where.
Does somebody know the answer or it's Android M preview bug?
Hi i am new android developer and i am working on an android app in which i want to show a dialog to user to select image from camera or gallery and after user selects image i want to store it in SD Card.i have already done it for OS versions less than 4.4 but i want to do this for 4.4 and above versions.i have already visited link
Android kitkat Image Selection From Gallery Issue
Please give some code examples as well as guidance.
Thanks in advance
create the final list of possible Intents with one new Intent for each retrieved activity like this:
List<Intent> yourIntentsList = new ArrayList<Intent>();
List<ResolveInfo> listCam = packageManager.queryIntentActivities(camIntent, 0);
for (ResolveInfo res : listCam) {
final Intent finalIntent = new Intent(camIntent);
finalIntent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
yourIntentsList.add(finalIntent);
}
List<ResolveInfo> listGall = packageManager.queryIntentActivities(gallIntent, 0);
for (ResolveInfo res : listGall) {
final Intent finalIntent = new Intent(gallIntent);
finalIntent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
yourIntentsList.add(finalIntent);
}
Every time a i startActivityForResult() , I get this line in logcat:
07-30 00:18:07.013: W/ActivityManager(2889): Permission denied: checkComponentPermission() owningUid=10095
But nothing actually fails, i don't get exceptions, everything works as it should.
I don't know what should i do about it, or if this can cause problems on other devices.
Here is the full code for the intent that i use:
// Determine Uri of camera image to save.
final File sdImageMainDirectory = getTempFile();
outputFileUri = Uri.fromFile(sdImageMainDirectory);
// Camera.
final List<Intent> cameraIntents = new ArrayList<Intent>();
final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
final PackageManager packageManager = getPackageManager();
final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
for (ResolveInfo res : listCam) {
final String packageName = res.activityInfo.packageName;
final Intent intent = new Intent(captureIntent);
intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
intent.setPackage(packageName);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
cameraIntents.add(intent);
}
// Filesystem.
final Intent galleryIntent = new Intent();
galleryIntent.setType("image/*");
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
// Chooser of filesystem options.
final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source");
// Add the camera options.
chooserIntent
.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[] {}));
startActivityForResult(chooserIntent, SELECT_PHOTO);`
Why is this happening and what can i do against it, how can i find out why do i get this message?