How to pass a URI to an intent?
you can store the uri as string
intent.putExtra("imageUri", imageUri.toString());
and then just convert the string back to uri like this
Uri myUri = Uri.parse(extras.getString("imageUri"));
pass uri to another activity and convert it to image
Convert you URI
to String while adding to Intent
like given below
i.putExtra("imagePath", selectedImage.toString());
and in your NextActivity
get the String
and convert back to URI
like ->
Intent intent = getIntent();
String image_path= intent.getStringExtra("imagePath");
Uri fileUri = Uri.parse(image_path)
imageview.setImageURI(fileUri)
How to transfer a Uri image from one activity to another?
use with putExtra to send the Uri Path:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent .setClass(ThisActivity.this, NewActivity.class);
intent .putExtra("KEY", Uri);
startActivity(intent );
In the newActivity OnCreate method:
Bundle extras = getIntent().getExtras();
if (extras != null && extras.containsKey("KEY")) {
Uri= extras.getString("KEY");
}
Use those func:
Uri to String:
Uri uri;
String stringUri;
stringUri = uri.toString();
String to Uri:
Uri uri;
String stringUri;
uri = Uri.parse(stringUri);
How to open a file in another app via an Intent using an URI?
Get rid of:
val file = File(Uri.parse(uri).path!!)
...and replace your setDataAndType()
call with:
newIntent.setDataAndType(Uri.parse(uri), mimeType)
Pass image through intent using URI to another activity
In your FullImageActivity, do this to retrieve the bitmap
Intent intent = getIntent();
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("pic");
This is because the bitmap class in android implements parcelable.
http://developer.android.com/reference/android/graphics/Bitmap.html
How to pass Uri value to bundle value
You can pass the Uri as a string using the toString
function, then parse it back as a Uri.
So, to send it as part of the URI:
phonebookIntent.putExtra("uri", uriData.toString());
To read it back:
Uri uriData = Uri.parse(extras.getString"uri"));
How to properly put a Uri from a local file into a Intent
I want my local image file (located at res/drawable) to be converted to a Uri, so I can put it into a Intent to start an Activity.
Resources are files on your developer machine. They are not files on the device.
This is what I got until now
That will not work, as AFAIK there are zero Android devices with a /res
directory off of the filesystem root, and your drawable resources would not be there anyway.
Why is my image not being recognized?
Your third one (android.resource
scheme) is the closest. Get rid of the .jpg
extension.
However, many third-party apps will not recognize that scheme. And, if you are implementing the activity that is to handle this request, I have no idea why you are using ACTION_SEND
. If your objective is to only work within your own app, skip the Uri
, package the drawable resource ID (R.drawable.photo
) as an int
extra, and have your other activity use that resource ID more naturally (e.g., setImageResource()
on the ImageView
).
Related Topics
Java - Declaring from Interface Type Instead of Class
How to Close a Java Swing Application from the Code
How to Convert Image to Byte Array in Java
Collections Sort(List<T>,Comparator<? Super T>) Method Example
How to Initialize List<String> Object in Java
When Should We Use Observer and Observable
What's the Difference Between Session.Persist() and Session.Save() in Hibernate
How Big Is an Object Reference in Java and Precisely What Information Does It Contain
Is Default No-Args Constructor Mandatory for Gson
How to Make a Jtable Non-Editable
Jpanel & Components Change Position Automatically
How to Call Launch() More Than Once in Java
Java.Sql.Sqlexception: No Suitable Driver Found for Jdbc:Microsoft:Sqlserver
How to Set Seekbar Min and Max Value
Java.Lang.Nullpointerexception: Attempt to Invoke Virtual Method on a Null Object Reference