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

how to move particular item gridview in android
put imageview over the webview in android
Setting photo taken using camera as thumbnai in an imageview
Android notification swipe delete disabling
How to use SMS SmsManager
Android multipart/x-mixed-replace - decode bitmap from inputstream returns null
SpeechRecognizer insufficient permissions error with Glass
Access Context from another activty in Android
Actionbar using customview and menuitems
Using just xxhdpi-size icons for Android
How to create ProgressDialog with pause and resume
Unable to export bitmape onto csv
How to add CheckBoxes dynamically to an Android layout? [duplicate]
Adding cast button to ActionBar using the CastCompanionLibrary
OncreateView does not call when Activity get destroyed and re-run again
Error inflating class fragment on Google Maps V2

Categories

HOME
shell
porting
powerpoint
mstest
jelastic
gradient
limit
google-cloud-datalab
angularfire2
little-proxy
pcl-crypto
drop-down-menu
stellar.js
capistrano3
linear-algebra
package.json
searchview
inno-download-plugin
parcelable
flask-sqlalchemy
resourcebundle
comparator
expressionengine3
licensing
flooding
paperjs
cppreference
ntp
magento-1.8
panoramas
recurring-events
cognos-bi
autolisp
linkedhashmap
joomla2.5
getpixel
numpy-broadcasting
timing
recurrent-neural-network
gdata
diacritics
apache-stanbol
resolution
watchface
skylink
wmp
rfc3339
procfile
xbmc
payara-micro
scalding
edit
seq
type-theory
bootstrap-tags-input
polyline
rocks
stax
mapinfo
appscale
beanstalk
binomial-theorem
dock
batik
viola-jones
dulwich
graphics2d
apache-commons-daemon
umlgraph
webfinger
human-computer-interface
trdion2011
create.js
unix-socket
matrix-inverse
vbe
koala
openargs
notorm
scrypt
mongohq
scringo
cmmi
abstract-data-type
epiceditor
jquery-1.9
dopostback
sentestingkit
listitem
cuda-gdb
multiplexing
google-maps-mobile
user-tracking
google-ajax-api
inline-formset
object-database
drupal-fivestar
ajax-polling
scrollbars
request-headers
django-piston
complex-event-processing
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