Hi in my page there are three option to make the picture to display in the another activity. option one memory card,camera,horizontal list view of images. From this what ever the user may choose but the image should be displayed in the next activity image view. Please guide me to do further !! am just open the camera and the memory card and after that i dont know how to send it to next activity.
Basically, you need to pass the information of the image to the next activity using Intent.
You should use:
Intent intent = new Intent(firstActivity.this, secondActivity.class);
intent.putExtra("fileName","SEE_BELOW");
startActivity(intent);
Option A:
if you are using an image from SDcard - replace SEE_BELOW with the actual String of the image Path.
Option B:
if you are getting the image from a ListView - use the arg2 in the onItemSelected method to get the position selected in the list and pull the image from there, save it to SD, and sending the String path like in Option A.
Option C:
if you are getting the image from the camera - I would save the image to SD, and then send the String path via Intent like in Option A.
Now, in your SecondActivity, in the onCreate method you call:
Intent intent = getIntent();
String image = intent.getStringExtra("fileName");
Now in your image variable you have the address of the image - just set it to your imageView and you are done!
Related
I'm now writing an app using android studio. In the main activity, I wrote a function to take a photo by using camera, then I want to pass this photo to the second activity. In the second activity, I want to upload this photo to a web API, and the type of the uploaded image has to be "JPEG".
I'm not sure I should use bundle or not. Or should I use "URI"? But when I call this:
URI photo_uri = photo.toURI();
There would be some problem. I couldn't run it. How can I fix this? This is what I wrote now, I use bundle:
// photo -> photo_uri, "photo.toURI()" doesn't work
Intent intent = new Intent(this, Main4Activity.class);
intent.putExtra("URI", photo_uri);
startActivity(intent);
And how can I receive the data(in JPEG type) in another activity?
You can send the file or uri path to second activity. After getting file or uri path you can convert that path into the file and upload it on the server.
You should check the Android docs about using the camera, there you have how to get the Uri, you must NEVER try to share the Bitmap itself.
About passing data between activities, you should use the Bundle so check this doc about Parcelables and Bundles which is the way to share data.
Regards!
I am developing an android app. When I capture an image using the code
Intent intent = new Intent(MediaStore.ActionImageCapture)
it will be stored in my sdcard as well as it will be displayed in the ImageView. Next, on button ‘Crop Picture’ click event, it should open the captured image as a new intent with the crop feature.
I've code to open the Gallery and select the captured image with the crop feature, but I don’t want the Gallery to get opened, instead I want the captured image in new intent with crop features.
Could anyone please assist?
In this case What you should do is, when it goes to next activity, save the image in local device, and put the image location as a intent value. Then when the new activity start, onCreate method, get the image location from intent values and load the image from the saved location. then delete the saved image.
If you can wait for few hours, I can put the code here.Feel free to ask anything until you get what you want.
Cheers!!
I have an android app that lists items with url links and on clicking opens the pages using uri,
as below
String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
I would like to open only for example a video or image in that page but not the whole of it.
Is that possible in android?
I got what you want to ask.
NO, it is not possible with Intent to open a part of a webpage, it will open entire page,
I suggest you to
1. download and save the image to your drawable folder.
2. create a new actvity , and in the xml associated with that activity add a imageview
3. place your image in that imageview
4. and on the click of the link start the activity with the intent
I would suggest to either use an ImageView (load the image into it - Download image for imageview on Android) or a VideoView (as stream - http://code.tutsplus.com/tutorials/streaming-video-in-android-apps--cms-19888).
It's not possible with an intent.
I have following requirement.
When the App receives a image file from server, it should open the image automatically in default image viewer.
Normal case:
Activity is visible.
Received image file from Server.
App send Intent.ACTION_VIEW
Gallery View shows the downloaded image.
Fail case:
Activity is not visible. (E.g. Press Home and return to launcher.)
Received image file from Server.
App send Intent.ACTION_VIEW
Nothing happens. (<-- Fail)
** If I go back to my App then I can see the Gallery View.
Is there anything I can do to get the Gallery View to show even my activity is not visible?
How i start the Gallery view:
final Intent openfileintent = new Intent();
openfileintent.setAction(android.content.Intent.ACTION_VIEW);
final File file = sharedfile.getFileInstance();
openfileintent.setDataAndType(Uri.fromFile(file), sharedfile.getMimeType());
startActivity(openfileintent);
Have found answer after trial and error.
There is 2 flags to add.
And most importantly, should use application context instead of activity context.
final Intent openfileintent = new Intent();
openfileintent.setAction(android.content.Intent.ACTION_VIEW);
(*1) openfileintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
(*2) openfileintent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
final File file = sharedfile.getFileInstance();
openfileintent.setDataAndType(Uri.fromFile(file), sharedfile.getMimeType());
(*3) getApplicationContext().startActivity(openfileintent);
Can we pass image and an image URI to other activity in same application using bundle?suggest me some way to do that?
USAGE :actually i have made an activity that crop an image taken from camera or from image stored in SD card depends upon the user.
and another app that uses a background image and a border image both are overlay so as to see PHOTOFRAME.
So now I want to combine both app so that the cropped image come from first app should become the background image for the second app.ie comes in photoframe.How can i do that?
Once you save your image in SD card
use this to cal the other activity.
final Intent intent = new Intent(MyClass.this, TargetClass.class);
final String root = Environment.getExternalStorageDirectory().getAbsolutePath();
intent.setData(Uri.parse(root + "/my/image/path/image.png"));
startActivity(intent);
if you are the reciever then you can get the path by calling
Uri path = getIntent().getData();
in the onCreate of the recieving activity. this is the standard way of checking for path by other activities.
Yes you can pass URI object,see putParcelable method in http://developer.android.com/reference/android/os/Bundle.html, URI already implements Parcelable interface,you can use corresponding get methods to get it.If any object that implements Parcelable interface then we can pass it using Bundle.