android


Android taking camera return empty intent


I am developing android app and my app have button to take camera. Previously i had fallen into a state where return data in onActivityResult after taking picture being null. This is camera expected behaviour whereby if we put EXTRA_OUTPUT in intent , it would return null. For that reason , I did null checking code and it went fine .
Now again after a few days and i tested . I still fallen into same issue again. But this time data is not null. data has empty intent such as intent and data.getData() become null.I fixed this by checking data.getData() == null and it works again. I don't why it is like that. Just curious about what was going on. For that reason i have to re-upload to production again. :-(
//camera intent
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureIntent.putExtra("requestCode", Constants.REQUEST_IMAGE_CAPTURE);
Intent chooseImageIntent = new Intent(Intent.ACTION_PICK,MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
chooseImageIntent.setType("image/* video/*");
chooseImageIntent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
chooseImageIntent.putExtra("requestCode", Constants.REQUEST_CHOOSE_FROM);
//app can use camera
if (takePictureIntent.resolveActivity(mContext.getPackageManager()) != null) {
//add output file path which camera will save image to
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Helpers.getOutputMediaFileUri());
//create choose
Intent chooser = Intent.createChooser(chooseImageIntent, "Select From");
//add take camera intent as first intent
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS,new Intent[]{takePictureIntent});
//open up dialog
((Activity) mContext).startActivityForResult(chooser, Constants.REQUEST_CHOOSE_FROM);
} else {
((Activity) mContext).startActivityForResult(chooseImageIntent, Constants.REQUEST_IMAGE_GALLERY);
}
EDITED
I know I how to fix the problem. What i don't understand is return data must be null if i put in EXTRA_OUTPUT. Mostly importantly the code I implemented few weeks back , i am quite sure that data return null and suddenly it is non null value again.
Actually the camera intent doesnot return the data in intent because after getting image it kill the activity.
so try this
void opencameraForPicture(int requestCode, Uri fileUri) {
checkPermissionForMarshMello(Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.READ_EXTERNAL_STORAGE);
Intent intent = new Intent(Constants.CAMERA_INTERNAL_CLASS);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
/* start activity for result pass intent as argument and request code */
startActivityForResult(intent, requestCode);
}
/**
* This method set the path for the captured image from camera for adding
* the new picture in the list
*/
private Uri getOutputMediaFile() {
File mediaStorageDir = new File(
Environment.getExternalStorageDirectory(), "."
+ Constants.CONTAINER);
// Create the storage directory if it does not exist
if (!mediaStorageDir.exists()) {
mediaStorageDir.mkdirs();
}
File mediaFile = new File(mediaStorageDir.getPath() + File.separator
+ "IMG_" + System.currentTimeMillis() + ".png");
Uri uri = null;
if (mediaFile != null) {
uri = Uri.fromFile(mediaFile);
}
return uri;
}
in #Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
String imagePath = fileUri.getPath();
//you can decode this path as bitmap
}

Related Links

Multi-table database in Android app
add image to surface view in android
Android - Radio Button in listView?
How to create custom api for tabhost and tabwidget?
How to draw a dynamic line graph in Android ?
vertically center text in tabs
Strategy for loading SQLite DB's into Android App
Android + Use LoaderManager with an ArrayAdapter?
Use application or activity context in CookieSyncManager.createInstance
Architecture for Phone to Cloud to Tablet
Android ListAdapter or Possibly ListView Updating Text at Runtime
Confused about initialization of SQLite database in Android
How can I get Android Marketplace to recognize my updates?
Bluetooth: program stuck at connect() method
Retrieving contact info in Android fails with exception
how to get menu label in monkeyrunner.?

Categories

HOME
service-worker
sonarqube
url-redirection
eclipse
cheerio
forms
character-encoding
sitecore
x264
fosrestbundle
project
categorical-data
appcelerator-studio
windows-ce
rtf
dynatrace
flatpak
gruntfile
glyphicons
forgot-password
sencha-touch
ksh
ember-cli
exploit
zxing
dynamically-generated
moses
underscore.js
angular-translate
bringtofront
user-defined-functions
magento-1.8
boost-asio
recurring-events
glib
git-squash
code-snippets
hreflang
vue-chartjs
joomla2.5
baidu-map
fiware-cygnus
amazon-ses
apache-stanbol
ogc
resolution
xv6
dcmtk
apache-spark-dataset
identification
arq
scalding
edit
gpg-signature
choice
materialized-path-pattern
gets
taocp
visual-studio-2008-sp1
docpad
omxplayer
preprocessor
spring-cloud-feign
synonym
dup
aurora
turbo-prolog
createprocess
fink
nupic
pushbots
wiredep
fuelcms
text-search
sony-lifelog-api
dulwich
google-refine
snackbar
shopizer
mmwormhole
cosine-similarity
machine-instruction
genymotion-call
strawberry-perl
angular-carousel
verold
winginx
cocoalibspotify-2.0
flex++
merb
abstract-data-type
mantle
stress
massive
qglwidget
data-mapping
skype4java
cuda.net
int64
lemmatization
mathematical-typesetting

Resources

Encrypt Message