android


What is required to get onActivityResult to fire from a camera selection?


I have the following code which creates an intent to either choose a photo from a gallery of the camera:
public void onPhotoButtonClick(View view) {
File root = new File(Environment.getExternalStorageDirectory() + File.separator + "photos" + File.separator);
root.mkdirs();
String fileName = String.format("photo_%s.jpg", System.currentTimeMillis());
File sdImageMainDirectory = new File(root, fileName);
photoUri = Uri.fromFile(sdImageMainDirectory);
List<Intent> cameraIntents = new ArrayList<Intent>();
Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
PackageManager packageManager = getPackageManager();
List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
for(ResolveInfo resolvedInfo : listCam) {
String packageName = resolvedInfo.activityInfo.packageName;
Intent intent = new Intent(captureIntent);
intent.setComponent(new ComponentName(packageName, resolvedInfo.activityInfo.name));
intent.setPackage(packageName);
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
cameraIntents.add(intent);
}
Intent galleryIntent = new Intent();
galleryIntent.setType("image/*");
galleryIntent.setAction(Intent.ACTION_PICK);
Intent chooserIntent = Intent.createChooser(galleryIntent, "Select source");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[cameraIntents.size()]));
startActivityForResult(chooserIntent, SELECT_PHOTO);
}
The issue is when I take a photo with the camera it is not activating the onActivityResult which is below:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG, String.valueOf(requestCode));
Log.d(TAG, String.valueOf(resultCode));
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PHOTO) {
final boolean isCamera;
if (data == null) {
isCamera = true;
} else {
final String action = data.getAction();
isCamera = MediaStore.ACTION_IMAGE_CAPTURE.equals(data.getAction());
}
Uri selectedImageUri;
if (isCamera) {
selectedImageUri = photoUri;
} else {
selectedImageUri = data == null ? null : data.getData();
}
photoText.setText(selectedImageUri.toString());
Log.d(TAG, selectedImageUri.toString());
}
}
}
I have the below in my manifest:
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Am I missing something?

Related Links

android 4.0.3 ImageSpans overlapping
Delete copy of an image in sdcard
How to disable dictionary mode in android phonegap? [duplicate]
Android is there any way to lock socket with only one device?
String dateTime to Date -> check if is today
Android Facebook SDK hide login view
Multiple handlers reusable code
Android Camera Touch Focus
How to determine which resource file is being used and why?
Exporting APK from eclipse (ADT) silently crashes
where can I register Android app on google for xoauth for consumer key and consumer secret
textview with button in gallery [closed]
Instant messaging on android? [closed]
Nexus 7 Support for Android Application Manifest Assembly
Stroke cap for custom PathEffect
Best way to create a week or day view for a calendar using GridView while getting the times right as well?

Categories

HOME
android
checkstyle
character-encoding
swt
toolbox
socket.io
owl-carousel
javacc
soa
switch-statement
3d-reconstruction
google-cloud-datalab
missing-data
nfs
computer-science
owin
why3
x-cart
jsonpath
nancy
intercom
esoteric-languages
job-scheduling
dimensional-modeling
production
asp.net-core-webapi
dynamically-generated
mount
ckfinder
pic32
corpus
fragment-backstack
genexus-sd
spotipy
constexpr
xbox
kudu
deltaspike
kodi
jmockit
turfjs
memory-address
github3.py
hunspell
sql-server-ce
git-rewrite-history
password-protection
news
xv6
vmware-fusion
dcmtk
angular-http
file-sharing
memory-mapping
jboss-4.2.x
openresty
geotiff
semantic-logging
excel-dna
rsa-archer-grc
pure-css
qtplugin
windows-azure-queues
dup
vorpal.js
beanstalk
linklabel
tfs-workitem
rate-limiting
doctype
uncompress
airbrake
mirror
telepat
ms-access-2000
matlab-deployment
code-documentation
ejb-2.x
administration
sonarqube-5.0
insight.database
ora-00904
winginx
fpdi
xmltodict
windows-embedded-standard
solace-mq
embedded-fonts
c++builder-xe5
modular
extreme-programming
stress
virtualpathprovider
apache-commons-dbutils
cloudfiles
isapi-extension
opml
request-headers
lalr
perl5.12
firefox-3
httpcookie
change-management
idatareader

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App