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.
Related
I am using the following code to open android gallery when an image is clicked in my app
Intent intent = new Intent (Intent.AUri.parse( "content://media/internal/images/media" ));
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
mActivity.startActivity(intent);
how can i modify my code to open a particular image directory or a particular image
According to me you should try this.
In your MainActivity introduce a method to create intend for that
and use syntax
intent.setComponent(new ComponentName("com.example.administrator.YOUR GALLERY APP NAME","com.example.administrator.YOUR APP.MainActivity"));
where com.example.administration is the initial name of your package
I want to open an image from the web inside in-built android gallery image viewer. So I searched. Found this link
StackOverflow
First answer didn't work for me. Following one did.
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com/example.jpg")));
BUT It opened the image into browser. I want it to open this with in-built image viewer of android.
Rest of the things that I found work with the local image, not from web.
Basically the idea is to use a method that will open the image in native app, and I'll call that method with Cordova/Phonegap.
Is there any simple way to do it? How can I open the image with url in the native in-built android gallery app??
Try this:
public void openImage(String image) {
Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI.buildUpon().appendPath(image).build();
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
Pass your image path to this method and see if it works.
Hope this has helped!
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);
Currently I have the following:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(mediaLoc)), "image/" + type);
context.startActivity(intent);
This was because the app used to download images from urls and saved them into the sdcard before viewing. But now I want to change the implementation to show the image from a url in the default image viewer when ACTION_VIEW is called and give them the option to save. Is this possible with ACTION_VIEW? I'm asking because I wish to use the default image viewer in the phone as it has already handled the zoom functions.
You would have to make a custom action_view for it.
I have retrieved the uri of the image
But when i use
startActivity(new Intent(Intent.ACTION_VIEW,mediaUri));
the image is viewed in image viewer but i can also see other gallery images.
How to avoid this.
I only want the single image to open in image viewer.
This may help you
Intent i = new Intent(android.content.Intent.ACTION_VIEW);
i.setDataAndType(Uri.parse("file:///sdcard/path/to/myfile.png"),"image/png");
startActivity(i);