How to change something file:///system/media/lockscreen/lockscreen_001.jpg to
something like /mnt/sdcard/myPicture.jpg
The reason why I want to change is that file:/// is wrong if I want to further process. It is hard to tell but if I get the URI from Uri uri= data.getData(); is file:///system/media/lockscreen/lockscreen_001.jpg, how to handle because normally is start with mnt
Try this :
Uri uri = Uri.parse("file:///system/media/lockscreen/lockscreen_001.jpg");
Toast.makeText(getApplicationContext(), ""+uri.getPath(), Toast.LENGTH_LONG).show();
uri.getPath() will give you the path by eliminating file: extension.
EDIT :
Uri urinew = Uri.parse(uri.getPath());
This will give you new uri with the path you got.
Hope it helps you.
Thanks.
Hope this code can help you :
Uri selectedImage = imageReturnedIntent.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
Related
I'm trying to develop email app and I want to attach a image to it, but I'm getting NullPointerException. Here's my code:
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
columnIndex = cursor.getColumnIndex(filePathColumn[0]);
attachmentfile = cursor.getString(columnIndex);
Log.e("Attachment Path: ", attachmentfile);
URI = Uri.parse("file://" + attachmentfile);
cursor.close();`
Please help me
I think your problem is that you are not putting right the file path.
The following works for me:
Uri.parse("file:///"+attachmentfile));
Note that file path has 3 "/", the first two are for the "file://" header, the other because sdcard dir is inside the root directory of the filesystem, which is "/" in linux.
I select an image from the image gallery in my app. In the onActivityResult it returns an Intent object and I execute the getData() method on it. I get the image URI back. I am now trying to convert that in to a File so I can send it to AWS S3.
This is what I have been trying but it just returns null:
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = context.getContentResolver().query(contentUri, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
I also try
File file = new File(imageURI.getPath())
also null. Is this impossible or can somebody help?
supposing your onActivityResult checks in with the Intent object being ReturnedIntent you can do
File f = new File(ReturnedIntent.getData());
or get an inputstream and use it
getContentResolver().openInputStream(ReturnedIntent.getData())
//returns inputstream
what is the essence of this String object String filePath ?
In my application, I open my gallery and pick a picture and then show my image in an image view then I'm supposed to send it through bluetooth.
That's what i've reached :
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
iv.setImageBitmap(yourSelectedImage);
How to send it through bluetooth?
N.B I've opened my bluetooth and made it also discover-able by other devices .
Please I'll be thankful if u helped me in my assignment =]
for example
real path is mnt/sdcard/image_1.jpg
Uri path is content://media/external/images/media/140 like this
Uri photoUri =Uri.parse("content://media/external/images/media/140");
Log.d("selectedphoto",""+photoUri);
selectedImagePath = getPath(photoUri);
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
In above code I convert Uri to real path but dnt know how to convert real path to Uri
Try this:
Uri.fromFile(new File("/sdcard/cats.jpg"));
This will get the file path from the MediaProvider, DownloadsProvider, and ExternalStorageProvider, while falling back to the unofficial ContentProvider method you mention.
https://stackoverflow.com/a/27271131/3758898
I am trying to pick a picture from the gallery and set it as a background for the view. Now, I am able to select pics as long as they are on my SD card. But as my gallery is in sync with my picasa album and when I try to select one of those pics, the cursor is returning NULL. Below is my code.
Uri selectedImage = imageReturnedIntent.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
The selected image has URI of "
https://lh5.googleusercontent.com/-thIdOA38IO0/SY8GG8PqW4I/AAAAAAAABKA/f3XpPvY9JHo/s1024/Picture%252520007.jpg"
Can someone help?
Thx!
Rahul.
Uri selectedImage = Uri.parse(imageReturnedIntent.getDataString());
Try the above line which return the Uri of selectedImage.