I have the following code to display an imagepicker.
After user picks an image onActivityResult gets called, to return me the data for the selected image.
On kindle however, I get a resultCode of 0, and data as null.
Anyone else has noticed this problem before?
This problem happens only on kindle fire.
startActivityForResult(new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), SELECT_PICTURE);
I'm running into this exact same issue. Prior to the recent Kindle Fire update, which happened a few days ago for me, picking images from the gallery worked fine for me.
So the most recent Kindle Fire update must have introduced this bug.
You can get data back from such calls in two ways: either in the actual intent data, or in Intent.EXTRA_STREAM. If you get something back in EXTRA_STREAM it will be a mediastore content:// URL which you'd use a Cursor to look up.
Related
I recently updated my Poco X3 NFC 64GB test device to Android 11:
MIUI Global 12.0.8(RJGEUXM)
Android 11 RKQ1.200826.002
Ever since I am unable to take or pick photos in my app. On other Android 11 devices (and emulator) everything works fine. The app is compiled to API level 30.
I start the photo picker chooser like this:
private void pickPhoto() {
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivityForResult(intent, 100);
}
}
This works fine, but after I have picked a photo it returns to the app, triggering onActivityResult with resultCode 0 (RESULT_CANCELED) and data is null too. On other Android 11 devices I can retrieve the photo from the data, but not on my Poco. Yes I did add the necessary query to the manifest file (else I wouldn't be able to open the picker in the first place).
When I try to fetch a photo from the camera I have exactly the same issue. Again on other Android 11 devices this works fine. So yes I did add and use the necessary file provider.
Sometimes a toast pops up about not having granted the right permissions. Do any of you guys have a Poco phone and like to try it out? I wonder if the Poco rom is just broken or something.
UPDATE
I've narrowed down the problem. It turns out that if startActivity() starts a camera/gallery activity directly it works fine. However if you're prompted a chooser first (e.g. because you have multiple gallery apps) it goes wrong.
So if you pick a gallery app and say to always use it in the future, the next time it will open that gallery app directly and then it works correctly.
If you use Intent.createChooser() it never works right. Even if it contains only one intent that is launched directly without prompting a chooser it fails to return a photo.
Can we agree that this is a MIUI bug?
I want to use ACTION_OPEN_DOCUMENT on my Xiaomi Device. I tried
this google sample, but it also not working. With code below i can normally run on Samsung galaxy s4.
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
startActivityForResult(intent, 42);
Im getting "android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.OPEN_DOCUMENT_TREE }" error.
Xiaomi screwed up, apparently. AFAIK, they're not Google Play certified, so they do not need to pass the CTS. There is nothing you can really do about it, other than to detect this case (e.g., use PackageManager and queryIntentActivities(), or catch the ActivityNotFoundException) and fall back to whatever you do on pre-Android 4.4 devices.
I saw the same error occur on Xiaomi MI 6X with Android 10.
Upon some digging I realized that some devices allow the user to disable the "Files" app from Google Play Services (or might even do that by default). Thus, I would recommend first prompting user for enabling "Files" app and/or updating the Google Play Services. Please note, that on most devices the "Files" app is hidden from the user, thus it will not be present on app list in preferences.
I have a simple Android app that tries to take a picture and send it to a server as HTTP POST with multipart data. The problem is that the the behavior of Androids Intent is different on some phones. When I run
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
on HTC One (Android 4.1.1) and Sony Xperia Z1 (Android 4.4.4), it stores the image in the gallery and calls like the one below works:
data.getData().getPath();
(data is an instance of Intent), whereas when I run the same code on LG Nexus 5 (Android 4.4.4), the image is not stored, and
data.getData();
returns null.
What I need is a way to store the image (temporally), so I can transfer it to the server.
Looks like there could be a bug in the recent android stock camera, please see this issue report on android. According to the bug, the data field returned by the camera intent could come back null in default behavior. (MediaStore.EXTRA_OUTPUT is not used).
To guarantee you always get image, allocate a file yourself and pass that uri in camera intent extras as MediaStore.EXTRA_OUTPUT
The best practice in allocating a temporary image file is to ensure the underlying media is mounted, see this sample code snippet on android developer site. On a successful completion of camera intent, just use the file uri you allocated...do not use getData (could be null).
This problem occurs with android version 4.0.3. I am adding contacts with a custom RawContacts.ACCOUNT_TYPE using the Android Contacts 2.0 API. As a second step I want to use Intent.ACTION_EDIT to edit those contacts using the following code:
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setData(contactUri);
startActivityForResult(intent, EDIT_CONTACT_RESULT);
The Intent is opening up the android built in edit contact activity. But when I press done, it is forwarding me to a contact view activity of the currently edited contact. If I then hit the back button, I get forwarded back to my application. The Problem is that onActivityResult(); always returns RESULT_CANCELED as a result code. Any ideas how to solve this problem?
Thanks.
This happens even on "stock Android" (JB, Galaxy Nexus). It seems the only way around it is to ignore the result code and to reread the contact again regardless of it (note that the Intent data will also be null, so you'd have to the contact Uri you had used when opening the Edit Activity).
Unfortunately, a lot of manufacturers tweak their SDKs, and a lot off apps fail to implement properly this, let call it "Android Pattern" where you should return the proper RESTULT_CODE. I have also encountered a lot of similar behaviours in the Facebook,Twitter, etc applications, and even them fail to return a proper result code if the user has shared/ or cancelled the action.
I don't think there is a problem with your code, it is very likely, that the problem is in the application that you are starting, which fails in returning a proper result.
Adding the following solved a similar problem for me:
intent.putExtra("finishActivityOnSaveCompleted", true);
On low memory device I've got a problem after calling camera intent. When activity result should be received Android restart the whole app.
Have anybody faced same problem? Is there any solution?
I faced the same issue a while ago:
Android system stops application when launching Media Intent
Apparently there is no solution, so you have to make sure that you save and restore the application state.
Well i think, the problem could be: Image byte array is too big such that it touches the limit and android restarts the application so following is what will i do:
Calling the intent with some parameter telling to downsample the bytes it gonna send back.
OR
Implement your camera using surfaceview and then when user takes some picture, save it temporarily on sdcard and return only the path... then get the path in onActivityResult and use the picture.
Hope it helps.