Domanda

I am using this method to get an image:

protected void openImageSelection(int intentCode, Uri fileUri) {
    // 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);
        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, 
                        getResources().getString(R.string.magafy_replace_image_tankboon_chooser));

    // Add the camera options.
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[]{}));

    startActivityForResult(chooserIntent, intentCode);
}

which I found here at SO, credits when due I just dont remember from which post (sorry).

I am trying to detect if the image resulted with this intent originated from a camera app or the gallery. Currently I am using this:

private boolean isTakenByCam(Intent data) {
        boolean isCamera;
        if(data == null){
            isCamera = true;
        } else {
            isCamera = MediaStore.ACTION_IMAGE_CAPTURE.equals(data.getAction());
        }
        return isCamera;
}

also from that same post i think.

The problem I have is that using the stock cam everything works fine (detecting from all kinda galleries apps ive seen works fine), but when taking the picture at a non-stock cam it the data.getAction() returns null sometimes, and sometimes something else entirely.

Is there another way of knowing the source of the image?

Thanks

È stato utile?

Soluzione

Its not much of an answer, but I solved it passing the camera intent a Uri as an extra and just regarded my result as Uri based instead of using getExtras().get("data").

Should try and find another way as I saw that using intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); is not recommended.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top