android


How to receive and save image shared from another application


if(intent.getType().startsWith("image/")){
Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
imageView.setImageUri(imageUri);
}
Need to save this image in my applications data directory. Querying on content resolver returns path to only those image files which are already saved in the device. like,
private String getPathFromURI(Uri contentURI) {
String result = null;
Cursor cursor = null;
try {
cursor = getContentResolver().query(contentURI, null, null, null, null);
cursor.moveToFirst();
int idx = cursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.DATA);
result = cursor.getString(idx);
} finally {
if (cursor != null) {
cursor.close();
}
}
return result;
}
but this does not works all the times because some of those image files are in private directories of the apps.
What to do to get read access to such files, so that copies of shared files can be written/saved for my application?
is there something wrong, that I should do some other way? kindly help, thank you.
Queering on content resolver returns path to only those image files which are already saved in the device
It is far worse than that. This only works for a Uri from the MediaStore, and even then only in certain situations.
What to do to get read access to such files, so that i can write copies of them for my application?
Step #1: Use getContentResolver().openInputStream() to get an InputStream on the content represented by the Uri
Step #2: Create a FileOutputStream for your desired copy
Step #3: Copy the bytes from the InputStream to the FileOutputStream using standard Java file I/O
IOW, this is not significantly different than using HttpURLConnection to download a file from a URL.

Related Links

hash key invalid for Facebook after app put on play store
How to refresh horizontal layout when click different letter with respective data in android
send gcm messages FROM mobile devices
Action Item acts as drop down menu
the result code returned from sub activity is not OK
How to get object boolean type in an if statement
Determine if signal strength is enough to send SMS
Android OpenGL ES 2.0 - Textures not showing on some devices
Android - GCM receive notification from gcm when open app
Android GPUImageView upside down
How to check Viewpager item ids with Espresso?
Why is BitmapFactory.decodeStream returning null?
Draw Rainbow Paint on canvas android
Running Weinre bound to something other than localhost
XXHDPI and XXXHDPI dimensions in dp for images and icons in android
Adding Parse-1.8.0 to Android Studio 1.0.1 (Or any .zip file)

Categories

HOME
url-redirection
beautifulsoup
cheerio
codenvy
github-for-windows
redux-form
ns-3
mjml
jelastic
spring-data-redis
can
grafana
entity-framework-core
alsa
telegram-bot
gembox-spreadsheet
bookmarks
computer-science
teechart
mql5
opengl-es-3.0
jxl
openbugs
frequency-distribution
symmetricds
flash-player
heat
gruntfile
esoteric-languages
vuejs
html5-appcache
spring-async
zxing
highstock
comparator
draft-js-plugins
expressionengine3
delimiter
tizen-tv
sqlpackage
panoramas
jbutton
glib
xajax
parse-tree
git-rewrite-history
tex
filesystemwatcher
sim-card
odroid
google-data-api
doc
signal-strength
monkey-testing
opencmis
clarifai
dotnet-httpclient
yii2-api
user-defined-fields
compiler-design
flyout
vibrate
builtins
winusb
envi
mta
observablecollection
fuzzywuzzy
user-management
grgit
binomial-theorem
ocra
phpldapadmin
variadic-templates
uncaught-typeerror
linkedin-jsapi
jama
template-deduction
ora-00904
artemis
pdfviewer
cuda-gdb
boost-signals
josql
failing-tests
google-maps-mobile
node-redis
winmain
w3c-geolocation
django-paypal
commerceserver2007
load-time
silent
vs-android
message-passing
burndowncharts
software-lifecycle
fault-tolerance
firefox-3
java1.4

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App