Permission denied, but nothing fails - android

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?

Related

Android how can I pick image from camera or gallery at the same time with one Intent

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.

Intent createChooser stop code not working in Marshmallow

I had a code in pre-Marshmallow application that selected only some of the installed applications that implement the Intent.ACTION_SEND and the show a Intent.createChooser with only those. This is the full code:
Intent actionSendIntent = new Intent();
actionSendIntent.setAction(Intent.ACTION_SEND);
actionSendIntent.setType("text/plain");
List<ResolveInfo> resInfos = getPackageManager().queryIntentActivities(actionSendIntent, 0);
List<Intent> shareIntents = new ArrayList<Intent>();
if(!resInfos.isEmpty()){
for(ResolveInfo res : resInfos){
final String packageName = res.activityInfo.packageName;
if (packageName.contains("com.twitter.android") ||
packageName.contains("com.facebook.katana") ||
packageName.contains("com.facebook.lite") ||
packageName.contains("com.whatsapp")) {
final Intent intent = new Intent();
intent.setComponent(new ComponentName(packageName, res.activityInfo.name));
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "text");
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
intent.setPackage(packageName);
shareIntents.add(intent);
}
}
}
Intent chooserIntent = Intent.createChooser(shareIntents.remove(0), shareText);
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, shareIntents.toArray(new Parcelable[]{}));
startActivity(Intent.createChooser(chooserIntent, shareText));
This code does not work in Marshmallow and show Android System as the only available option... does anyone know why?

Android Intent.createChooser doesn't open camera activity on click

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.

Intent is null in onActivityResult when taking a photo [duplicate]

I am using following code to get picture from camera. Except samsung it is working fine in other mobiles. please let me know what i am doing wrong.
final File root = new File(Environment.getExternalStorageDirectory() + File.separator + "temp" + File.separator);
root.mkdir();
final String fname = "img_" + System.currentTimeMillis() + ".jpg";
final File sdImageMainDirectory = new File(root, fname);
outputFileUri = Uri.fromFile(sdImageMainDirectory);
// Camera.
final List<Intent> cameraIntents = new ArrayList<Intent>();
final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
final PackageManager packageManager = cordova.getActivity().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/jpeg");
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
// Chooser of filesystem options.
final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Image Source");
// Add the camera options.
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[]{}));
startActivityForResult(chooserIntent, PICK_FILE_REQUEST);
And onActivityResult
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PICK_FILE_REQUEST) {
if(data!=null){
Logv("Data","got some data");
}
}
}
Except samsung it is working fine in other mobiles
No, it is only working with the camera apps on the devices that you have tried. It generally will not work for ACTION_IMAGE_CAPTURE.
please let me know what i am doing wrong
You are assuming that ACTION_IMAGE_CAPTURE is supposed to return a result Intent. It is not required when you provide EXTRA_OUTPUT. You know where you asked for the image to be saved (the value you supplied to EXTRA_OUTPUT, so go look there for the image.
Note that there are some buggy camera apps that will ignore EXTRA_OUTPUT (storing the image where they want), so if the image from your ACTION_IMAGE_CAPTURE request is not in EXTRA_OUTPUT, you are out of luck.

android how to take picture only use system camera

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);
}

Categories

Resources